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     */
020    package org.apache.directory.shared.ldap.message.extended;
021    
022    import org.apache.directory.shared.i18n.I18n;
023    import org.apache.directory.shared.ldap.message.ExtendedResponseImpl;
024    import org.apache.directory.shared.ldap.message.ResultCodeEnum;
025    import org.apache.directory.shared.ldap.util.StringTools;
026    /**
027     * 
028     * The response sent back from the server after the Cancel extended operation is performed.
029     *
030     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
031     * @version $Rev$, $Date$
032     */
033    public class CancelResponse extends ExtendedResponseImpl
034    {
035        /** The serial version UUID */
036        private static final long serialVersionUID = 1L;
037    
038        /**
039         * Create a new CancelResponse object
040         * @param messageId The messageId
041         * @param rcode the result code
042         */
043        public CancelResponse( int messageId, ResultCodeEnum rcode )
044        {
045            super( messageId, null );
046    
047            switch ( rcode )
048            {
049                case SUCCESS :
050                case CANCELED:
051                case CANNOT_CANCEL :
052                case NO_SUCH_OPERATION :
053                case TOO_LATE :
054                    break;
055                
056                default:
057                    throw new IllegalArgumentException( I18n.err( I18n.ERR_04166, ResultCodeEnum.SUCCESS,
058                                    ResultCodeEnum.OPERATIONS_ERROR, ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS ) );
059            }
060            
061            super.getLdapResult().setMatchedDn( null );
062            super.getLdapResult().setResultCode( rcode );
063        }
064    
065    
066        public CancelResponse( int messageId )
067        {
068            super( messageId, null );
069            super.getLdapResult().setMatchedDn( null );
070            super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
071        }
072    
073    
074        // ------------------------------------------------------------------------
075        // ExtendedResponse Interface Method Implementations
076        // ------------------------------------------------------------------------
077        /**
078         * Gets the response OID specific encoded response values. It's a null
079         * value for a CancelResponse
080         * 
081         * @return the response specific encoded response values.
082         */
083        public byte[] getResponse()
084        {
085            return StringTools.EMPTY_BYTES;
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        public String getResponseName()
096        {
097            return "";
098        }
099    
100    
101        /**
102         * @see Object#equals(Object)
103         */
104        public boolean equals( Object obj )
105        {
106            if ( obj == this )
107            {
108                return true;
109            }
110    
111            if ( obj instanceof CancelResponse )
112            {
113                return true;
114            }
115    
116            return false;
117        }
118    }