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.ldap.message.ExtendedResponseImpl;
023 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
024 import org.apache.directory.shared.ldap.util.StringTools;
025 /**
026 *
027 * The response sent back from the server after the Cancel extended operation is performed.
028 *
029 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
030 * @version $Rev$, $Date$
031 */
032 public class CancelResponse extends ExtendedResponseImpl
033 {
034 /** The serial version UUID */
035 private static final long serialVersionUID = 1L;
036
037 /**
038 * Create a new CancelResponse object
039 * @param messageId The messageId
040 * @param rcode the result code
041 */
042 public CancelResponse( int messageId, ResultCodeEnum rcode )
043 {
044 super( messageId, null );
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( "The result code can only be one of: " + 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 public CancelResponse( int messageId )
066 {
067 super( messageId, null );
068 super.getLdapResult().setMatchedDn( null );
069 super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
070 }
071
072
073 // ------------------------------------------------------------------------
074 // ExtendedResponse Interface Method Implementations
075 // ------------------------------------------------------------------------
076 /**
077 * Gets the response OID specific encoded response values. It's a null
078 * value for a CancelResponse
079 *
080 * @return the response specific encoded response values.
081 */
082 public byte[] getResponse()
083 {
084 return StringTools.EMPTY_BYTES;
085 }
086
087
088 /**
089 * Gets the OID uniquely identifying this extended response (a.k.a. its
090 * name). It's a null value for the Cancel response
091 *
092 * @return the OID of the extended response type.
093 */
094 public String getResponseName()
095 {
096 return "";
097 }
098
099
100 /**
101 * @see Object#equals(Object)
102 */
103 public boolean equals( Object obj )
104 {
105 if ( obj == this )
106 {
107 return true;
108 }
109
110 if ( obj instanceof CancelResponse )
111 {
112 return true;
113 }
114
115 return false;
116 }
117 }