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.TLV;
28 import org.apache.directory.api.i18n.I18n;
29 import org.apache.directory.api.ldap.codec.api.LdapApiService;
30 import org.apache.directory.api.ldap.codec.api.LdapConstants;
31 import org.apache.directory.api.ldap.model.message.Control;
32 import org.apache.directory.api.ldap.model.message.DeleteRequest;
33 import org.apache.directory.api.ldap.model.name.Dn;
34 import org.apache.directory.api.util.Strings;
35
36
37
38
39
40
41
42 public class DeleteRequestDecorator extends SingleReplyRequestDecorator<DeleteRequest>
43 implements DeleteRequest
44 {
45
46
47 private byte[] dnBytes;
48
49
50
51
52
53
54
55 public DeleteRequestDecorator( LdapApiService codec, DeleteRequest decoratedMessage )
56 {
57 super( codec, decoratedMessage );
58 }
59
60
61
62
63
64
65
66
67
68 public Dn getName()
69 {
70 return getDecorated().getName();
71 }
72
73
74
75
76
77 public DeleteRequest setName( Dn name )
78 {
79 getDecorated().setName( name );
80
81 return this;
82 }
83
84
85
86
87
88 public DeleteRequest setMessageId( int messageId )
89 {
90 super.setMessageId( messageId );
91
92 return this;
93 }
94
95
96
97
98
99 public DeleteRequest addControl( Control control )
100 {
101 return ( DeleteRequest ) super.addControl( control );
102 }
103
104
105
106
107
108 public DeleteRequest addAllControls( Control[] controls )
109 {
110 return ( DeleteRequest ) super.addAllControls( controls );
111 }
112
113
114
115
116
117 public DeleteRequest removeControl( Control control )
118 {
119 return ( DeleteRequest ) super.removeControl( control );
120 }
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135 public int computeLength()
136 {
137 dnBytes = Strings.getBytesUtf8( getName().getName() );
138 int dnLength = dnBytes.length;
139
140
141 return 1 + TLV.getNbBytes( dnLength ) + dnLength;
142 }
143
144
145
146
147
148
149
150
151
152
153 public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
154 {
155 try
156 {
157
158 buffer.put( LdapConstants.DEL_REQUEST_TAG );
159
160
161 buffer.put( TLV.getBytes( dnBytes.length ) );
162 buffer.put( dnBytes );
163 }
164 catch ( BufferOverflowException boe )
165 {
166 throw new EncoderException( I18n.err( I18n.ERR_04005 ) );
167 }
168
169 return buffer;
170 }
171 }