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