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