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.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      @Override
73      public boolean getDeleteOldRdn()
74      {
75          return deleteOldRdn;
76      }
77  
78  
79      /**
80       * {@inheritDoc}
81       */
82      @Override
83      public ModifyDnRequest setDeleteOldRdn( boolean deleteOldRdn )
84      {
85          this.deleteOldRdn = deleteOldRdn;
86  
87          return this;
88      }
89  
90  
91      /**
92       * {@inheritDoc}
93       */
94      @Override
95      public boolean isMove()
96      {
97          return newSuperior != null;
98      }
99  
100 
101     /**
102      * {@inheritDoc}
103      */
104     @Override
105     public Dn getName()
106     {
107         return name;
108     }
109 
110 
111     /**
112      * {@inheritDoc}
113      */
114     @Override
115     public ModifyDnRequest setName( Dn name )
116     {
117         this.name = name;
118 
119         return this;
120     }
121 
122 
123     /**
124      * {@inheritDoc}
125      */
126     @Override
127     public Rdn getNewRdn()
128     {
129         return newRdn;
130     }
131 
132 
133     /**
134      * {@inheritDoc}
135      */
136     @Override
137     public ModifyDnRequest setNewRdn( Rdn newRdn )
138     {
139         this.newRdn = newRdn;
140 
141         return this;
142     }
143 
144 
145     /**
146      * {@inheritDoc}
147      */
148     @Override
149     public Dn getNewSuperior()
150     {
151         return newSuperior;
152     }
153 
154 
155     /**
156      * {@inheritDoc}
157      */
158     @Override
159     public ModifyDnRequest setNewSuperior( Dn newSuperior )
160     {
161         this.newSuperior = newSuperior;
162 
163         return this;
164     }
165 
166 
167     /**
168      * {@inheritDoc}
169      */
170     @Override
171     public ModifyDnRequest setMessageId( int messageId )
172     {
173         super.setMessageId( messageId );
174 
175         return this;
176     }
177 
178 
179     /**
180      * {@inheritDoc}
181      */
182     @Override
183     public ModifyDnRequest addControl( Control control )
184     {
185         return ( ModifyDnRequest ) super.addControl( control );
186     }
187 
188 
189     /**
190      * {@inheritDoc}
191      */
192     @Override
193     public ModifyDnRequest addAllControls( Control[] controls )
194     {
195         return ( ModifyDnRequest ) super.addAllControls( controls );
196     }
197 
198 
199     /**
200      * {@inheritDoc}
201      */
202     @Override
203     public ModifyDnRequest removeControl( Control control )
204     {
205         return ( ModifyDnRequest ) super.removeControl( control );
206     }
207 
208 
209     // ------------------------------------------------------------------------
210     // SingleReplyRequest Interface Method Implementations
211     // ------------------------------------------------------------------------
212 
213     /**
214      * Gets the protocol response message type for this request which produces
215      * at least one response.
216      * 
217      * @return the message type of the response.
218      */
219     @Override
220     public MessageTypeEnum getResponseType()
221     {
222         return MessageTypeEnum.MODIFYDN_RESPONSE;
223     }
224 
225 
226     /**
227      * The result containing response for this request.
228      * 
229      * @return the result containing response for this request
230      */
231     @Override
232     public ModifyDnResponse getResultResponse()
233     {
234         if ( response == null )
235         {
236             response = new ModifyDnResponseImpl( getMessageId() );
237         }
238 
239         return response;
240     }
241 
242 
243     /**
244      * {@inheritDoc}
245      */
246     @Override
247     public int hashCode()
248     {
249         int hash = 37;
250         if ( name != null )
251         {
252             hash = hash * 17 + name.hashCode();
253         }
254         hash = hash * 17 + ( deleteOldRdn ? 0 : 1 );
255 
256         if ( newRdn != null )
257         {
258             hash = hash * 17 + newRdn.hashCode();
259         }
260         if ( newSuperior != null )
261         {
262             hash = hash * 17 + newSuperior.hashCode();
263         }
264         hash = hash * 17 + super.hashCode();
265 
266         return hash;
267     }
268 
269 
270     /**
271      * Checks to see of an object equals this ModifyDnRequest stub. The equality
272      * presumes all ModifyDnRequest specific properties are the same.
273      * 
274      * @param obj the object to compare with this stub
275      * @return true if the obj is equal to this stub, false otherwise
276      */
277     @Override
278     public boolean equals( Object obj )
279     {
280         if ( obj == this )
281         {
282             return true;
283         }
284 
285         if ( !super.equals( obj ) )
286         {
287             return false;
288         }
289 
290         ModifyDnRequest req = ( ModifyDnRequest ) obj;
291 
292         if ( name != null && req.getName() == null )
293         {
294             return false;
295         }
296 
297         if ( name == null && req.getName() != null )
298         {
299             return false;
300         }
301 
302         if ( name != null && req.getName() != null && !name.equals( req.getName() ) )
303         {
304             return false;
305         }
306 
307         if ( deleteOldRdn != req.getDeleteOldRdn() )
308         {
309             return false;
310         }
311 
312         if ( newRdn != null && req.getNewRdn() == null )
313         {
314             return false;
315         }
316 
317         if ( newRdn == null && req.getNewRdn() != null )
318         {
319             return false;
320         }
321 
322         if ( newRdn != null && req.getNewRdn() != null && !newRdn.equals( req.getNewRdn() ) )
323         {
324             return false;
325         }
326 
327         if ( newSuperior != null && req.getNewSuperior() == null )
328         {
329             return false;
330         }
331 
332         if ( newSuperior == null && req.getNewSuperior() != null )
333         {
334             return false;
335         }
336 
337         return ( newSuperior == null ) || ( req.getNewSuperior() == null ) || newSuperior.equals( req
338             .getNewSuperior() );
339     }
340 
341 
342     /**
343      * Get a String representation of a ModifyDNRequest
344      * 
345      * @return A ModifyDNRequest String
346      */
347     @Override
348     public String toString()
349     {
350 
351         StringBuilder sb = new StringBuilder();
352 
353         sb.append( "    ModifyDN Response\n" );
354         sb.append( "        Entry : '" ).append( name ).append( "'\n" );
355         if ( newRdn != null )
356         {
357             sb.append( "        New Rdn : '" ).append( newRdn.toString() ).append( "'\n" );
358         }
359         sb.append( "        Delete old Rdn : " ).append( deleteOldRdn ).append( "\n" );
360 
361         if ( newSuperior != null )
362         {
363             sb.append( "        New superior : '" ).append( newSuperior.toString() ).append( "'\n" );
364         }
365 
366         // The controls
367         sb.append( super.toString() );
368 
369         return super.toString( sb.toString() );
370     }
371 }