001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *  
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *  
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License. 
018 *  
019 */
020package org.apache.directory.api.ldap.extras.extended.cancel;
021
022
023import org.apache.directory.api.i18n.I18n;
024import org.apache.directory.api.ldap.model.message.ExtendedResponseImpl;
025import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
026
027
028/**
029 * 
030 * The response sent back from the server after the Cancel extended operation is performed.
031 *
032 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
033 */
034public class CancelResponseImpl extends ExtendedResponseImpl implements CancelResponse
035{
036    /**
037     * Create a new CancelResponse instance
038     * 
039     * @param messageId The request's messageId
040     * @param rcode the result code
041     */
042    public CancelResponseImpl( int messageId, ResultCodeEnum rcode )
043    {
044        super( messageId );
045
046        switch ( rcode )
047        {
048            case SUCCESS:
049            case CANCELED:
050            case CANNOT_CANCEL:
051            case NO_SUCH_OPERATION:
052            case TOO_LATE:
053                break;
054
055            default:
056                throw new IllegalArgumentException( I18n.err( I18n.ERR_04166, ResultCodeEnum.SUCCESS,
057                    ResultCodeEnum.OPERATIONS_ERROR, ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS ) );
058        }
059
060        super.getLdapResult().setMatchedDn( null );
061        super.getLdapResult().setResultCode( rcode );
062    }
063
064
065    /**
066     * Create a new CancelResponse instance
067     * 
068     * @param messageId The request's messageId
069     */
070    public CancelResponseImpl( int messageId )
071    {
072        super( messageId );
073        super.getLdapResult().setMatchedDn( null );
074        super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
075    }
076
077
078    /**
079     * Create a new CancelResponse instance
080     */
081    public CancelResponseImpl()
082    {
083        super( CancelRequest.EXTENSION_OID );
084        super.getLdapResult().setMatchedDn( null );
085        super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
086    }
087
088
089    /**
090     * Gets the OID uniquely identifying this extended response (a.k.a. its
091     * name). It's a null value for the Cancel response
092     * 
093     * @return the OID of the extended response type.
094     */
095    @Override
096    public String getResponseName()
097    {
098        return "";
099    }
100
101
102    /**
103     * {@inheritDoc}
104     */
105    @Override
106    public int hashCode()
107    {
108        int hash = 37;
109        // Seems simple but look at the equals() method ...
110        hash = hash * 17 + getClass().getName().hashCode();
111
112        return hash;
113    }
114
115
116    /**
117     * @see Object#equals(Object)
118     */
119    @Override
120    public boolean equals( Object obj )
121    {
122        if ( obj == this )
123        {
124            return true;
125        }
126
127        return obj instanceof CancelResponseImpl;
128    }
129}