1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
29
30
31
32 public class ModifyDnRequestImpl extends AbstractAbandonableRequest implements ModifyDnRequest
33 {
34 static final long serialVersionUID = 1233507339633051696L;
35
36
37 private Dn name;
38
39
40 private Rdn newRdn;
41
42
43 private Dn newSuperior;
44
45
46 private boolean deleteOldRdn = false;
47
48
49 private ModifyDnResponse response;
50
51
52
53
54
55
56
57
58
59 public ModifyDnRequestImpl()
60 {
61 super( -1, MessageTypeEnum.MODIFYDN_REQUEST );
62 }
63
64
65
66
67
68
69
70
71
72 @Override
73 public boolean getDeleteOldRdn()
74 {
75 return deleteOldRdn;
76 }
77
78
79
80
81
82 @Override
83 public ModifyDnRequest setDeleteOldRdn( boolean deleteOldRdn )
84 {
85 this.deleteOldRdn = deleteOldRdn;
86
87 return this;
88 }
89
90
91
92
93
94 @Override
95 public boolean isMove()
96 {
97 return newSuperior != null;
98 }
99
100
101
102
103
104 @Override
105 public Dn getName()
106 {
107 return name;
108 }
109
110
111
112
113
114 @Override
115 public ModifyDnRequest setName( Dn name )
116 {
117 this.name = name;
118
119 return this;
120 }
121
122
123
124
125
126 @Override
127 public Rdn getNewRdn()
128 {
129 return newRdn;
130 }
131
132
133
134
135
136 @Override
137 public ModifyDnRequest setNewRdn( Rdn newRdn )
138 {
139 this.newRdn = newRdn;
140
141 return this;
142 }
143
144
145
146
147
148 @Override
149 public Dn getNewSuperior()
150 {
151 return newSuperior;
152 }
153
154
155
156
157
158 @Override
159 public ModifyDnRequest setNewSuperior( Dn newSuperior )
160 {
161 this.newSuperior = newSuperior;
162
163 return this;
164 }
165
166
167
168
169
170 @Override
171 public ModifyDnRequest setMessageId( int messageId )
172 {
173 super.setMessageId( messageId );
174
175 return this;
176 }
177
178
179
180
181
182 @Override
183 public ModifyDnRequest addControl( Control control )
184 {
185 return ( ModifyDnRequest ) super.addControl( control );
186 }
187
188
189
190
191
192 @Override
193 public ModifyDnRequest addAllControls( Control[] controls )
194 {
195 return ( ModifyDnRequest ) super.addAllControls( controls );
196 }
197
198
199
200
201
202 @Override
203 public ModifyDnRequest removeControl( Control control )
204 {
205 return ( ModifyDnRequest ) super.removeControl( control );
206 }
207
208
209
210
211
212
213
214
215
216
217
218
219 @Override
220 public MessageTypeEnum getResponseType()
221 {
222 return MessageTypeEnum.MODIFYDN_RESPONSE;
223 }
224
225
226
227
228
229
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
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
272
273
274
275
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
344
345
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
367 sb.append( super.toString() );
368
369 return super.toString( sb.toString() );
370 }
371 }