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.codec.decorators;
21
22
23 import java.nio.BufferOverflowException;
24 import java.nio.ByteBuffer;
25
26 import org.apache.directory.api.asn1.EncoderException;
27 import org.apache.directory.api.asn1.ber.tlv.BerValue;
28 import org.apache.directory.api.asn1.ber.tlv.TLV;
29 import org.apache.directory.api.i18n.I18n;
30 import org.apache.directory.api.ldap.codec.api.LdapApiService;
31 import org.apache.directory.api.ldap.codec.api.LdapConstants;
32 import org.apache.directory.api.ldap.model.message.Control;
33 import org.apache.directory.api.ldap.model.message.ModifyDnRequest;
34 import org.apache.directory.api.ldap.model.name.Dn;
35 import org.apache.directory.api.ldap.model.name.Rdn;
36 import org.apache.directory.api.util.Strings;
37
38
39
40
41
42
43
44 public class ModifyDnRequestDecorator extends SingleReplyRequestDecorator<ModifyDnRequest>
45 implements ModifyDnRequest
46 {
47
48 private int modifyDnRequestLength;
49
50
51
52
53
54
55
56 public ModifyDnRequestDecorator( LdapApiService codec, ModifyDnRequest decoratedMessage )
57 {
58 super( codec, decoratedMessage );
59 }
60
61
62
63
64
65 public void setModifyDnRequestLength( int modifyDnRequestLength )
66 {
67 this.modifyDnRequestLength = modifyDnRequestLength;
68 }
69
70
71
72
73
74
75 public int getModifyDnResponseLength()
76 {
77 return modifyDnRequestLength;
78 }
79
80
81
82
83
84
85
86
87
88 public Dn getName()
89 {
90 return getDecorated().getName();
91 }
92
93
94
95
96
97 public ModifyDnRequest setName( Dn name )
98 {
99 getDecorated().setName( name );
100
101 return this;
102 }
103
104
105
106
107
108 public Rdn getNewRdn()
109 {
110 return getDecorated().getNewRdn();
111 }
112
113
114
115
116
117 public ModifyDnRequest setNewRdn( Rdn newRdn )
118 {
119 getDecorated().setNewRdn( newRdn );
120
121 return this;
122 }
123
124
125
126
127
128 public boolean getDeleteOldRdn()
129 {
130 return getDecorated().getDeleteOldRdn();
131 }
132
133
134
135
136
137 public ModifyDnRequest setDeleteOldRdn( boolean deleteOldRdn )
138 {
139 getDecorated().setDeleteOldRdn( deleteOldRdn );
140
141 return this;
142 }
143
144
145
146
147
148 public Dn getNewSuperior()
149 {
150 return getDecorated().getNewSuperior();
151 }
152
153
154
155
156
157 public ModifyDnRequest setNewSuperior( Dn newSuperior )
158 {
159 getDecorated().setNewSuperior( newSuperior );
160
161 return this;
162 }
163
164
165
166
167
168 public boolean isMove()
169 {
170 return getDecorated().isMove();
171 }
172
173
174
175
176
177 public ModifyDnRequest setMessageId( int messageId )
178 {
179 super.setMessageId( messageId );
180
181 return this;
182 }
183
184
185
186
187
188 public ModifyDnRequest addControl( Control control )
189 {
190 return ( ModifyDnRequest ) super.addControl( control );
191 }
192
193
194
195
196
197 public ModifyDnRequest addAllControls( Control[] controls )
198 {
199 return ( ModifyDnRequest ) super.addAllControls( controls );
200 }
201
202
203
204
205
206 public ModifyDnRequest removeControl( Control control )
207 {
208 return ( ModifyDnRequest ) super.removeControl( control );
209 }
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238 public int computeLength()
239 {
240 int newRdnlength = Strings.getBytesUtf8( getNewRdn().getName() ).length;
241
242 int modifyDNRequestLength = 1 + TLV.getNbBytes( Dn.getNbBytes( getName() ) )
243 + Dn.getNbBytes( getName() ) + 1 + TLV.getNbBytes( newRdnlength ) + newRdnlength + 1 + 1
244 + 1;
245
246 if ( getNewSuperior() != null )
247 {
248 modifyDNRequestLength += 1 + TLV.getNbBytes( Dn.getNbBytes( getNewSuperior() ) )
249 + Dn.getNbBytes( getNewSuperior() );
250 }
251
252 setModifyDnRequestLength( modifyDNRequestLength );
253
254 return 1 + TLV.getNbBytes( modifyDNRequestLength ) + modifyDNRequestLength;
255 }
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272 public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
273 {
274 try
275 {
276
277 buffer.put( LdapConstants.MODIFY_DN_REQUEST_TAG );
278 buffer.put( TLV.getBytes( getModifyDnResponseLength() ) );
279
280
281
282 BerValue.encode( buffer, Dn.getBytes( getName() ) );
283
284
285 BerValue.encode( buffer, getNewRdn().getName() );
286
287
288 BerValue.encode( buffer, getDeleteOldRdn() );
289
290
291 if ( getNewSuperior() != null )
292 {
293
294 buffer.put( ( byte ) LdapConstants.MODIFY_DN_REQUEST_NEW_SUPERIOR_TAG );
295
296 int newSuperiorLength = Dn.getNbBytes( getNewSuperior() );
297
298 buffer.put( TLV.getBytes( newSuperiorLength ) );
299
300 if ( newSuperiorLength != 0 )
301 {
302 buffer.put( Dn.getBytes( getNewSuperior() ) );
303 }
304 }
305 }
306 catch ( BufferOverflowException boe )
307 {
308 throw new EncoderException( I18n.err( I18n.ERR_04005 ) );
309 }
310
311 return buffer;
312 }
313 }