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