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.ldap.model.name.Dn;
24  import org.apache.directory.api.ldap.model.name.Rdn;
25  
26  
27  /**
28   * ModifyDNRequest implementation.
29   * 
30   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
31   */
32  public class ModifyDnRequestImpl extends AbstractAbandonableRequest implements ModifyDnRequest
33  {
34      static final long serialVersionUID = 1233507339633051696L;
35  
36      /** PDU's modify Dn candidate <b>entry</b> distinguished name property */
37      private Dn name;
38  
39      /** PDU's <b>newrdn</b> relative distinguished name property */
40      private Rdn newRdn;
41  
42      /** PDU's <b>newSuperior</b> distinguished name property */
43      private Dn newSuperior;
44  
45      /** PDU's <b>deleteOldRdn</b> flag */
46      private boolean deleteOldRdn = false;
47  
48      /** The associated response */
49      private ModifyDnResponse response;
50  
51  
52      // -----------------------------------------------------------------------
53      // Constructors
54      // -----------------------------------------------------------------------
55      /**
56       * Creates a ModifyDnRequest implementing object used to perform a
57       * dn change on an entry potentially resulting in an entry move.
58       */
59      public ModifyDnRequestImpl()
60      {
61          super( -1, MessageTypeEnum.MODIFYDN_REQUEST );
62      }
63  
64  
65      // -----------------------------------------------------------------------
66      // ModifyDnRequest Interface Method Implementations
67      // -----------------------------------------------------------------------
68  
69      /**
70       * {@inheritDoc}
71       */
72      public boolean getDeleteOldRdn()
73      {
74          return deleteOldRdn;
75      }
76  
77  
78      /**
79       * {@inheritDoc}
80       */
81      public ModifyDnRequest setDeleteOldRdn( boolean deleteOldRdn )
82      {
83          this.deleteOldRdn = deleteOldRdn;
84  
85          return this;
86      }
87  
88  
89      /**
90       * {@inheritDoc}
91       */
92      public boolean isMove()
93      {
94          return newSuperior != null;
95      }
96  
97  
98      /**
99       * {@inheritDoc}
100      */
101     public Dn getName()
102     {
103         return name;
104     }
105 
106 
107     /**
108      * {@inheritDoc}
109      */
110     public ModifyDnRequest setName( Dn name )
111     {
112         this.name = name;
113 
114         return this;
115     }
116 
117 
118     /**
119      * {@inheritDoc}
120      */
121     public Rdn getNewRdn()
122     {
123         return newRdn;
124     }
125 
126 
127     /**
128      * {@inheritDoc}
129      */
130     public ModifyDnRequest setNewRdn( Rdn newRdn )
131     {
132         this.newRdn = newRdn;
133 
134         return this;
135     }
136 
137 
138     /**
139      * {@inheritDoc}
140      */
141     public Dn getNewSuperior()
142     {
143         return newSuperior;
144     }
145 
146 
147     /**
148      * {@inheritDoc}
149      */
150     public ModifyDnRequest setNewSuperior( Dn newSuperior )
151     {
152         this.newSuperior = newSuperior;
153 
154         return this;
155     }
156 
157 
158     /**
159      * {@inheritDoc}
160      */
161     public ModifyDnRequest setMessageId( int messageId )
162     {
163         super.setMessageId( messageId );
164 
165         return this;
166     }
167 
168 
169     /**
170      * {@inheritDoc}
171      */
172     public ModifyDnRequest addControl( Control control )
173     {
174         return ( ModifyDnRequest ) super.addControl( control );
175     }
176 
177 
178     /**
179      * {@inheritDoc}
180      */
181     public ModifyDnRequest addAllControls( Control[] controls )
182     {
183         return ( ModifyDnRequest ) super.addAllControls( controls );
184     }
185 
186 
187     /**
188      * {@inheritDoc}
189      */
190     public ModifyDnRequest removeControl( Control control )
191     {
192         return ( ModifyDnRequest ) super.removeControl( control );
193     }
194 
195 
196     // ------------------------------------------------------------------------
197     // SingleReplyRequest Interface Method Implementations
198     // ------------------------------------------------------------------------
199 
200     /**
201      * Gets the protocol response message type for this request which produces
202      * at least one response.
203      * 
204      * @return the message type of the response.
205      */
206     public MessageTypeEnum getResponseType()
207     {
208         return MessageTypeEnum.MODIFYDN_RESPONSE;
209     }
210 
211 
212     /**
213      * The result containing response for this request.
214      * 
215      * @return the result containing response for this request
216      */
217     public ModifyDnResponse getResultResponse()
218     {
219         if ( response == null )
220         {
221             response = new ModifyDnResponseImpl( getMessageId() );
222         }
223 
224         return response;
225     }
226 
227 
228     /**
229      * {@inheritDoc}
230      */
231     @Override
232     public int hashCode()
233     {
234         int hash = 37;
235         if ( name != null )
236         {
237             hash = hash * 17 + name.hashCode();
238         }
239         hash = hash * 17 + ( deleteOldRdn ? 0 : 1 );
240 
241         if ( newRdn != null )
242         {
243             hash = hash * 17 + newRdn.hashCode();
244         }
245         if ( newSuperior != null )
246         {
247             hash = hash * 17 + newSuperior.hashCode();
248         }
249         hash = hash * 17 + super.hashCode();
250 
251         return hash;
252     }
253 
254 
255     /**
256      * Checks to see of an object equals this ModifyDnRequest stub. The equality
257      * presumes all ModifyDnRequest specific properties are the same.
258      * 
259      * @param obj the object to compare with this stub
260      * @return true if the obj is equal to this stub, false otherwise
261      */
262     public boolean equals( Object obj )
263     {
264         if ( obj == this )
265         {
266             return true;
267         }
268 
269         if ( !super.equals( obj ) )
270         {
271             return false;
272         }
273 
274         ModifyDnRequest req = ( ModifyDnRequest ) obj;
275 
276         if ( name != null && req.getName() == null )
277         {
278             return false;
279         }
280 
281         if ( name == null && req.getName() != null )
282         {
283             return false;
284         }
285 
286         if ( name != null && req.getName() != null && !name.equals( req.getName() ) )
287         {
288             return false;
289         }
290 
291         if ( deleteOldRdn != req.getDeleteOldRdn() )
292         {
293             return false;
294         }
295 
296         if ( newRdn != null && req.getNewRdn() == null )
297         {
298             return false;
299         }
300 
301         if ( newRdn == null && req.getNewRdn() != null )
302         {
303             return false;
304         }
305 
306         if ( newRdn != null && req.getNewRdn() != null && !newRdn.equals( req.getNewRdn() ) )
307         {
308             return false;
309         }
310 
311         if ( newSuperior != null && req.getNewSuperior() == null )
312         {
313             return false;
314         }
315 
316         if ( newSuperior == null && req.getNewSuperior() != null )
317         {
318             return false;
319         }
320 
321         return ( ( newSuperior == null ) || ( req.getNewSuperior() == null ) || newSuperior.equals( req
322             .getNewSuperior() ) );
323     }
324 
325 
326     /**
327      * Get a String representation of a ModifyDNRequest
328      * 
329      * @return A ModifyDNRequest String
330      */
331     public String toString()
332     {
333 
334         StringBuffer sb = new StringBuffer();
335 
336         sb.append( "    ModifyDN Response\n" );
337         sb.append( "        Entry : '" ).append( name ).append( "'\n" );
338         if ( newRdn != null )
339         {
340             sb.append( "        New Rdn : '" ).append( newRdn.toString() ).append( "'\n" );
341         }
342         sb.append( "        Delete old Rdn : " ).append( deleteOldRdn ).append( "\n" );
343 
344         if ( newSuperior != null )
345         {
346             sb.append( "        New superior : '" ).append( newSuperior.toString() ).append( "'\n" );
347         }
348 
349         // The controls
350         sb.append( super.toString() );
351 
352         return super.toString( sb.toString() );
353     }
354 }