View Javadoc
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   *    https://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.AbstractExtendedResponse;
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 AbstractExtendedResponse implements CancelResponse
35  {
36      /**
37       * Create a new CancelResponse object
38       * @param messageId The messageId
39       * @param rcode the result code
40       */
41      public CancelResponseImpl( int messageId, ResultCodeEnum rcode )
42      {
43          super( messageId );
44  
45          switch ( rcode )
46          {
47              case SUCCESS:
48              case CANCELED:
49              case CANNOT_CANCEL:
50              case NO_SUCH_OPERATION:
51              case TOO_LATE:
52                  break;
53  
54              default:
55                  throw new IllegalArgumentException( I18n.err( I18n.ERR_13503_RESULT_CODE_SHOULD_BE_IN, ResultCodeEnum.SUCCESS,
56                      ResultCodeEnum.OPERATIONS_ERROR, ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS ) );
57          }
58  
59          super.getLdapResult().setMatchedDn( null );
60          super.getLdapResult().setResultCode( rcode );
61      }
62  
63  
64      /**
65       * Create a new CancelResponse instance
66       * 
67       * @param messageId The request's messageId
68       */
69      public CancelResponseImpl( int messageId )
70      {
71          super( messageId );
72          super.getLdapResult().setMatchedDn( null );
73          super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
74      }
75  
76  
77      /**
78       * Create a new CancelResponse instance
79       */
80      public CancelResponseImpl()
81      {
82          super( CancelRequest.EXTENSION_OID );
83          super.getLdapResult().setMatchedDn( null );
84          super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
85      }
86  
87  
88      /**
89       * Gets the OID uniquely identifying this extended response (a.k.a. its
90       * name). It's a null value for the Cancel response
91       * 
92       * @return the OID of the extended response type.
93       */
94      @Override
95      public String getResponseName()
96      {
97          return "";
98      }
99  
100 
101     /**
102      * {@inheritDoc}
103      */
104     @Override
105     public int hashCode()
106     {
107         int hash = 37;
108         // Seems simple but look at the equals() method ...
109         hash = hash * 17 + getClass().getName().hashCode();
110 
111         return hash;
112     }
113 
114 
115     /**
116      * @see Object#equals(Object)
117      */
118     @Override
119     public boolean equals( Object obj )
120     {
121         if ( obj == this )
122         {
123             return true;
124         }
125 
126         return obj instanceof CancelResponseImpl;
127     }
128 }