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.LdapCodecConstants;
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
57 public ModifyDnRequestDecorator( LdapApiService codec, ModifyDnRequest decoratedMessage )
58 {
59 super( codec, decoratedMessage );
60 }
61
62
63
64
65
66
67
68
69
70 @Override
71 public Dn getName()
72 {
73 return getDecorated().getName();
74 }
75
76
77
78
79
80 @Override
81 public ModifyDnRequest setName( Dn name )
82 {
83 getDecorated().setName( name );
84
85 return this;
86 }
87
88
89
90
91
92 @Override
93 public Rdn getNewRdn()
94 {
95 return getDecorated().getNewRdn();
96 }
97
98
99
100
101
102 @Override
103 public ModifyDnRequest setNewRdn( Rdn newRdn )
104 {
105 getDecorated().setNewRdn( newRdn );
106
107 return this;
108 }
109
110
111
112
113
114 @Override
115 public boolean getDeleteOldRdn()
116 {
117 return getDecorated().getDeleteOldRdn();
118 }
119
120
121
122
123
124 @Override
125 public ModifyDnRequest setDeleteOldRdn( boolean deleteOldRdn )
126 {
127 getDecorated().setDeleteOldRdn( deleteOldRdn );
128
129 return this;
130 }
131
132
133
134
135
136 @Override
137 public Dn getNewSuperior()
138 {
139 return getDecorated().getNewSuperior();
140 }
141
142
143
144
145
146 @Override
147 public ModifyDnRequest setNewSuperior( Dn newSuperior )
148 {
149 getDecorated().setNewSuperior( newSuperior );
150
151 return this;
152 }
153
154
155
156
157
158 @Override
159 public boolean isMove()
160 {
161 return getDecorated().isMove();
162 }
163
164
165
166
167
168 @Override
169 public ModifyDnRequest setMessageId( int messageId )
170 {
171 super.setMessageId( messageId );
172
173 return this;
174 }
175
176
177
178
179
180 @Override
181 public ModifyDnRequest addControl( Control control )
182 {
183 return ( ModifyDnRequest ) super.addControl( control );
184 }
185
186
187
188
189
190 @Override
191 public ModifyDnRequest addAllControls( Control[] controls )
192 {
193 return ( ModifyDnRequest ) super.addAllControls( controls );
194 }
195
196
197
198
199
200 @Override
201 public ModifyDnRequest removeControl( Control control )
202 {
203 return ( ModifyDnRequest ) super.removeControl( control );
204 }
205
206
207
208
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 @Override
234 public int computeLength()
235 {
236 int newRdnlength = Strings.getBytesUtf8( getNewRdn().getName() ).length;
237
238
239 modifyDnRequestLength = 1 + TLV.getNbBytes( Dn.getNbBytes( getName() ) )
240 + Dn.getNbBytes( getName() ) + 1 + TLV.getNbBytes( newRdnlength ) + newRdnlength + 1 + 1
241 + 1;
242
243 if ( getNewSuperior() != null )
244 {
245 modifyDnRequestLength += 1 + TLV.getNbBytes( Dn.getNbBytes( getNewSuperior() ) )
246 + Dn.getNbBytes( getNewSuperior() );
247 }
248
249 return 1 + TLV.getNbBytes( modifyDnRequestLength ) + modifyDnRequestLength;
250 }
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268 @Override
269 public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
270 {
271 try
272 {
273
274 buffer.put( LdapCodecConstants.MODIFY_DN_REQUEST_TAG );
275 buffer.put( TLV.getBytes( modifyDnRequestLength ) );
276
277
278
279 BerValue.encode( buffer, Dn.getBytes( getName() ) );
280
281
282 BerValue.encode( buffer, getNewRdn().getName() );
283
284
285 BerValue.encode( buffer, getDeleteOldRdn() );
286
287
288 if ( getNewSuperior() != null )
289 {
290
291 buffer.put( ( byte ) LdapCodecConstants.MODIFY_DN_REQUEST_NEW_SUPERIOR_TAG );
292
293 int newSuperiorLength = Dn.getNbBytes( getNewSuperior() );
294
295 buffer.put( TLV.getBytes( newSuperiorLength ) );
296
297 if ( newSuperiorLength != 0 )
298 {
299 buffer.put( Dn.getBytes( getNewSuperior() ) );
300 }
301 }
302 }
303 catch ( BufferOverflowException boe )
304 {
305 throw new EncoderException( I18n.err( I18n.ERR_04005 ), boe );
306 }
307
308 return buffer;
309 }
310 }