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.entry.Attribute;
24 import org.apache.directory.api.ldap.model.entry.DefaultAttribute;
25 import org.apache.directory.api.ldap.model.entry.DefaultEntry;
26 import org.apache.directory.api.ldap.model.entry.Entry;
27 import org.apache.directory.api.ldap.model.entry.Value;
28 import org.apache.directory.api.ldap.model.exception.LdapException;
29 import org.apache.directory.api.ldap.model.name.Dn;
30
31
32
33
34
35
36
37 public class AddRequestImpl extends AbstractAbandonableRequest implements AddRequest
38 {
39 static final long serialVersionUID = 7534132448349520346L;
40
41
42 private Entry entry;
43
44 private AddResponse response;
45
46
47 private Attribute currentAttribute;
48
49
50
51
52
53
54
55
56
57 public AddRequestImpl()
58 {
59 super( -1, MessageTypeEnum.ADD_REQUEST );
60 entry = new DefaultEntry();
61 }
62
63
64
65
66
67
68
69 public void addAttributeType( String type ) throws LdapException
70 {
71
72 if ( entry.get( type ) != null )
73 {
74 currentAttribute = entry.get( type );
75 return;
76 }
77
78
79 currentAttribute = new DefaultAttribute( type );
80 entry.put( currentAttribute );
81 }
82
83
84
85
86
87 public String getCurrentAttributeType()
88 {
89 return currentAttribute.getId();
90 }
91
92
93
94
95
96
97
98 public void addAttributeValue( String value ) throws LdapException
99 {
100 currentAttribute.add( value );
101 }
102
103
104
105
106
107
108
109 public void addAttributeValue( Value<?> value ) throws LdapException
110 {
111 currentAttribute.add( value );
112 }
113
114
115
116
117
118
119
120 public void addAttributeValue( byte[] value ) throws LdapException
121 {
122 currentAttribute.add( value );
123 }
124
125
126
127
128
129
130
131
132
133
134
135 public Dn getEntryDn()
136 {
137 return entry.getDn();
138 }
139
140
141
142
143
144 public AddRequest setEntryDn( Dn dn )
145 {
146 entry.setDn( dn );
147
148 return this;
149 }
150
151
152
153
154
155 public Entry getEntry()
156 {
157 return entry;
158 }
159
160
161
162
163
164 public AddRequest setEntry( Entry entry )
165 {
166 this.entry = entry;
167
168 return this;
169 }
170
171
172
173
174
175 public AddRequest setMessageId( int messageId )
176 {
177 super.setMessageId( messageId );
178
179 return this;
180 }
181
182
183
184
185
186 public AddRequest addControl( Control control )
187 {
188 return ( AddRequest ) super.addControl( control );
189 }
190
191
192
193
194
195 public AddRequest addAllControls( Control[] controls )
196 {
197 return ( AddRequest ) super.addAllControls( controls );
198 }
199
200
201
202
203
204 public AddRequest removeControl( Control control )
205 {
206 return ( AddRequest ) super.removeControl( control );
207 }
208
209
210
211
212
213
214
215
216
217
218
219
220 public MessageTypeEnum getResponseType()
221 {
222 return MessageTypeEnum.ADD_RESPONSE;
223 }
224
225
226
227
228
229
230
231 public AddResponse getResultResponse()
232 {
233 if ( response == null )
234 {
235 response = new AddResponseImpl( getMessageId() );
236 }
237
238 return response;
239 }
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254 public boolean equals( Object obj )
255 {
256
257 if ( this == obj )
258 {
259 return true;
260 }
261
262
263 if ( !( obj instanceof AddRequest ) )
264 {
265 return false;
266 }
267
268 if ( !super.equals( obj ) )
269 {
270 return false;
271 }
272
273 AddRequest req = ( AddRequest ) obj;
274
275
276 if ( entry == null )
277 {
278 return ( req.getEntry() == null );
279 }
280 else
281 {
282 return ( entry.equals( req.getEntry() ) );
283 }
284 }
285
286
287
288
289
290
291 public int hashCode()
292 {
293 int hash = 37;
294 hash = hash * 17 + ( entry == null ? 0 : entry.hashCode() );
295 hash = hash * 17 + ( response == null ? 0 : response.hashCode() );
296 hash = hash * 17 + super.hashCode();
297
298 return hash;
299 }
300
301
302
303
304
305 public String toString()
306 {
307 StringBuilder sb = new StringBuilder();
308
309 sb.append( " Add Request :\n" );
310
311 if ( entry == null )
312 {
313 sb.append( " No entry\n" );
314 }
315 else
316 {
317 sb.append( entry.toString() );
318 }
319
320 return super.toString( sb.toString() );
321 }
322 }