1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 *
19 */
20 package org.apache.directory.api.ldap.extras.extended.cancel;
21
22
23 import org.apache.directory.api.i18n.I18n;
24 import org.apache.directory.api.ldap.model.message.ExtendedResponseImpl;
25 import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
26
27
28 /**
29 *
30 * The response sent back from the server after the Cancel extended operation is performed.
31 *
32 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
33 */
34 public class CancelResponseImpl extends ExtendedResponseImpl implements CancelResponse
35 {
36 /**
37 * Create a new CancelResponse instance
38 *
39 * @param messageId The request's messageId
40 * @param rcode the result code
41 */
42 public CancelResponseImpl( int messageId, ResultCodeEnum rcode )
43 {
44 super( messageId );
45
46 switch ( rcode )
47 {
48 case SUCCESS:
49 case CANCELED:
50 case CANNOT_CANCEL:
51 case NO_SUCH_OPERATION:
52 case TOO_LATE:
53 break;
54
55 default:
56 throw new IllegalArgumentException( I18n.err( I18n.ERR_04166, ResultCodeEnum.SUCCESS,
57 ResultCodeEnum.OPERATIONS_ERROR, ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS ) );
58 }
59
60 super.getLdapResult().setMatchedDn( null );
61 super.getLdapResult().setResultCode( rcode );
62 }
63
64
65 /**
66 * Create a new CancelResponse instance
67 *
68 * @param messageId The request's messageId
69 */
70 public CancelResponseImpl( int messageId )
71 {
72 super( messageId );
73 super.getLdapResult().setMatchedDn( null );
74 super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
75 }
76
77
78 /**
79 * Create a new CancelResponse instance
80 */
81 public CancelResponseImpl()
82 {
83 super( CancelRequest.EXTENSION_OID );
84 super.getLdapResult().setMatchedDn( null );
85 super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
86 }
87
88
89 /**
90 * Gets the OID uniquely identifying this extended response (a.k.a. its
91 * name). It's a null value for the Cancel response
92 *
93 * @return the OID of the extended response type.
94 */
95 @Override
96 public String getResponseName()
97 {
98 return "";
99 }
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 }