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 object
038     * @param messageId The messageId
039     * @param rcode the result code
040     */
041    public CancelResponseImpl( int messageId, ResultCodeEnum rcode )
042    {
043        super( messageId );
044
045        switch ( rcode )
046        {
047            case SUCCESS:
048            case CANCELED:
049            case CANNOT_CANCEL:
050            case NO_SUCH_OPERATION:
051            case TOO_LATE:
052                break;
053
054            default:
055                throw new IllegalArgumentException( I18n.err( I18n.ERR_04166, ResultCodeEnum.SUCCESS,
056                    ResultCodeEnum.OPERATIONS_ERROR, ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS ) );
057        }
058
059        super.getLdapResult().setMatchedDn( null );
060        super.getLdapResult().setResultCode( rcode );
061    }
062
063
064    public CancelResponseImpl( int messageId )
065    {
066        super( messageId );
067        super.getLdapResult().setMatchedDn( null );
068        super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
069    }
070
071
072    public CancelResponseImpl()
073    {
074        super( CancelRequest.EXTENSION_OID );
075        super.getLdapResult().setMatchedDn( null );
076        super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
077    }
078
079
080    /**
081     * Gets the OID uniquely identifying this extended response (a.k.a. its
082     * name). It's a null value for the Cancel response
083     * 
084     * @return the OID of the extended response type.
085     */
086    public String getResponseName()
087    {
088        return "";
089    }
090
091
092    /**
093     * {@inheritDoc}
094     */
095    @Override
096    public int hashCode()
097    {
098        int hash = 37;
099        // Seems simple but look at the equals() method ...
100        hash = hash * 17 + getClass().getName().hashCode();
101
102        return hash;
103    }
104
105
106    /**
107     * @see Object#equals(Object)
108     */
109    @Override
110    public boolean equals( Object obj )
111    {
112        if ( obj == this )
113        {
114            return true;
115        }
116
117        return ( obj instanceof CancelResponseImpl );
118    }
119}