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   *    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 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_04166, 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      public CancelResponseImpl( int messageId )
65      {
66          super( messageId );
67          super.getLdapResult().setMatchedDn( null );
68          super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
69      }
70  
71  
72      public CancelResponseImpl()
73      {
74          super( CancelRequest.EXTENSION_OID );
75          super.getLdapResult().setMatchedDn( null );
76          super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
77      }
78  
79  
80      /**
81       * Gets the OID uniquely identifying this extended response (a.k.a. its
82       * name). It's a null value for the Cancel response
83       * 
84       * @return the OID of the extended response type.
85       */
86      public String getResponseName()
87      {
88          return "";
89      }
90  
91  
92      /**
93       * {@inheritDoc}
94       */
95      @Override
96      public int hashCode()
97      {
98          int hash = 37;
99          // Seems simple but look at the equals() method ...
100         hash = hash * 17 + getClass().getName().hashCode();
101 
102         return hash;
103     }
104 
105 
106     /**
107      * @see Object#equals(Object)
108      */
109     @Override
110     public boolean equals( Object obj )
111     {
112         if ( obj == this )
113         {
114             return true;
115         }
116 
117         return ( obj instanceof CancelResponseImpl );
118     }
119 }