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.model.message;
21  
22  
23  import org.apache.directory.api.i18n.I18n;
24  
25  
26  /**
27   * Implementation of an AbandonRequest message.
28   * 
29   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
30   */
31  public class AbandonRequestImpl extends AbstractRequest implements AbandonRequest
32  {
33      /** Sequence identifier of the outstanding request message to abandon */
34      private int abandonId;
35  
36      /** Ldap abandon request type code */
37      private static final MessageTypeEnum TYPE = MessageTypeEnum.ABANDON_REQUEST;
38  
39  
40      /**
41       * Creates an AbandonRequest implementation for an outstanding request.
42       */
43      public AbandonRequestImpl()
44      {
45          super( -1, TYPE, false );
46      }
47  
48  
49      /**
50       * Creates an AbandonRequest implementation for an outstanding request.
51       * 
52       * @param abdandonnedId the sequence identifier of the AbandonRequest message.
53       */
54      public AbandonRequestImpl( final int abdandonnedId )
55      {
56          super( -1, TYPE, false );
57          abandonId = abdandonnedId;
58      }
59  
60  
61      /**
62       * Gets the id of the request operation to terminate.
63       * 
64       * @return the id of the request message to abandon
65       */
66      @Override
67      public int getAbandoned()
68      {
69          return abandonId;
70      }
71  
72  
73      /**
74       * {@inheritDoc}
75       */
76      @Override
77      public AbandonRequest setAbandoned( int abandonId )
78      {
79          this.abandonId = abandonId;
80  
81          return this;
82      }
83  
84  
85      /**
86       * RFC 2251 [Section 4.11]: Abandon, Bind, Unbind, and StartTLS operations
87       * cannot be abandoned.
88       */
89      public void abandon()
90      {
91          throw new UnsupportedOperationException( I18n.err( I18n.ERR_13506_CANNOT_ABANDON_OPERATION ) );
92      }
93  
94  
95      /**
96       * {@inheritDoc}
97       */
98      @Override
99      public AbandonRequest setMessageId( int messageId )
100     {
101         super.setMessageId( messageId );
102 
103         return this;
104     }
105 
106 
107     /**
108      * {@inheritDoc}
109      */
110     @Override
111 public AbandonRequest addControl( Control control )
112     {
113         return ( AbandonRequest ) super.addControl( control );
114     }
115 
116 
117     /**
118      * {@inheritDoc}
119      */
120     @Override
121     public AbandonRequest addAllControls( Control[] controls )
122     {
123         return ( AbandonRequest ) super.addAllControls( controls );
124     }
125 
126 
127     /**
128      * {@inheritDoc}
129      */
130     @Override
131     public AbandonRequest removeControl( Control control )
132     {
133         return ( AbandonRequest ) super.removeControl( control );
134     }
135 
136 
137     /**
138      * Checks for equality first by asking the super method which should compare
139      * all but the Abandoned request's Id. It then compares this to determine
140      * equality.
141      * 
142      * @param obj the object to test for equality to this AbandonRequest
143      * @return true if the obj equals this request, false otherwise
144      */
145     @Override
146     public boolean equals( Object obj )
147     {
148         if ( this == obj )
149         {
150             return true;
151         }
152 
153         if ( !( obj instanceof AbandonRequest ) )
154         {
155             return false;
156         }
157 
158         if ( !super.equals( obj ) )
159         {
160             return false;
161         }
162 
163         AbandonRequest req = ( AbandonRequest ) obj;
164 
165         return req.getAbandoned() == abandonId;
166     }
167 
168 
169     /**
170      * @see Object#hashCode()
171      * @return the instance's hash code 
172      */
173     @Override
174     public int hashCode()
175     {
176         int hash = 37;
177         hash = hash * 17 + abandonId;
178         hash = hash * 17 + super.hashCode();
179 
180         return hash;
181     }
182 
183 
184     /**
185      * Return a String representing an AbandonRequest
186      * 
187      * @return A String representing the AbandonRequest
188      */
189     @Override
190     public String toString()
191     {
192         StringBuilder sb = new StringBuilder();
193 
194         sb.append( "    Abandon Request :\n" );
195         sb.append( "        Message Id : " ).append( abandonId );
196 
197         // The controls
198         sb.append( super.toString() );
199 
200         return sb.toString();
201     }
202 }