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.BinaryValue;
24 import org.apache.directory.api.ldap.model.entry.StringValue;
25 import org.apache.directory.api.ldap.model.entry.Value;
26 import org.apache.directory.api.ldap.model.name.Dn;
27 import org.apache.directory.api.util.Strings;
28
29
30
31
32
33
34
35 public class CompareRequestImpl extends AbstractAbandonableRequest implements CompareRequest
36 {
37 static final long serialVersionUID = 1699731530016468977L;
38
39
40 private Dn name;
41
42
43 private String attrId;
44
45
46 private Value<?> attrVal;
47
48
49 private CompareResponse response;
50
51
52
53
54
55
56
57
58
59 public CompareRequestImpl()
60 {
61 super( -1, MessageTypeEnum.COMPARE_REQUEST );
62 }
63
64
65
66
67
68
69
70
71
72
73
74
75 public Dn getName()
76 {
77 return name;
78 }
79
80
81
82
83
84 public CompareRequest setName( Dn name )
85 {
86 this.name = name;
87
88 return this;
89 }
90
91
92
93
94
95
96
97 public Value<?> getAssertionValue()
98 {
99 return attrVal;
100 }
101
102
103
104
105
106 public CompareRequest setAssertionValue( String value )
107 {
108 this.attrVal = new StringValue( value );
109
110 return this;
111 }
112
113
114
115
116
117 public CompareRequest setAssertionValue( byte[] value )
118 {
119 if ( value != null )
120 {
121 this.attrVal = new BinaryValue( value );
122 }
123 else
124 {
125 this.attrVal = null;
126 }
127
128 return this;
129 }
130
131
132
133
134
135
136
137 public String getAttributeId()
138 {
139 return attrId;
140 }
141
142
143
144
145
146 public CompareRequest setAttributeId( String attributeId )
147 {
148 this.attrId = attributeId;
149
150 return this;
151 }
152
153
154
155
156
157 public CompareRequest setMessageId( int messageId )
158 {
159 super.setMessageId( messageId );
160
161 return this;
162 }
163
164
165
166
167
168 public CompareRequest addControl( Control control )
169 {
170 return ( CompareRequest ) super.addControl( control );
171 }
172
173
174
175
176
177 public CompareRequest addAllControls( Control[] controls )
178 {
179 return ( CompareRequest ) super.addAllControls( controls );
180 }
181
182
183
184
185
186 public CompareRequest removeControl( Control control )
187 {
188 return ( CompareRequest ) super.removeControl( control );
189 }
190
191
192
193
194
195
196
197
198
199
200
201
202 public MessageTypeEnum getResponseType()
203 {
204 return MessageTypeEnum.COMPARE_RESPONSE;
205 }
206
207
208
209
210
211
212
213 public CompareResponse getResultResponse()
214 {
215 if ( response == null )
216 {
217 response = new CompareResponseImpl( getMessageId() );
218 }
219
220 return response;
221 }
222
223
224
225
226
227 @Override
228 public int hashCode()
229 {
230 int hash = 37;
231 if ( name != null )
232 {
233 hash = hash * 17 + name.hashCode();
234 }
235 if ( attrId != null )
236 {
237 hash = hash * 17 + attrId.hashCode();
238 }
239 if ( attrVal != null )
240 {
241 hash = hash * 17 + attrVal.hashCode();
242 }
243 Value<?> reqVal = getAssertionValue();
244 if ( reqVal != null )
245 {
246 hash = hash * 17 + reqVal.hashCode();
247 }
248 hash = hash * 17 + super.hashCode();
249
250 return hash;
251 }
252
253
254
255
256
257
258
259
260 public boolean equals( Object obj )
261 {
262 if ( obj == this )
263 {
264 return true;
265 }
266
267 if ( !super.equals( obj ) )
268 {
269 return false;
270 }
271
272 CompareRequest req = ( CompareRequest ) obj;
273 Dn reqName = req.getName();
274
275 if ( ( name != null ) && ( reqName == null ) )
276 {
277 return false;
278 }
279
280 if ( ( name == null ) && ( reqName != null ) )
281 {
282 return false;
283 }
284
285 if ( ( name != null ) && ( reqName != null ) && !name.equals( req.getName() ) )
286 {
287 return false;
288 }
289
290 String reqId = req.getAttributeId();
291
292 if ( ( attrId != null ) && ( reqId == null ) )
293 {
294 return false;
295 }
296
297 if ( ( attrId == null ) && ( reqId != null ) )
298 {
299 return false;
300 }
301
302 if ( ( attrId != null ) && ( reqId != null ) && !attrId.equals( reqId ) )
303 {
304 return false;
305 }
306
307 Value<?> reqVal = req.getAssertionValue();
308
309 if ( attrVal != null )
310 {
311 if ( reqVal != null )
312 {
313 return attrVal.equals( reqVal );
314 }
315 else
316 {
317 return false;
318 }
319 }
320 else
321 {
322 return reqVal == null;
323 }
324 }
325
326
327
328
329
330
331
332 public String toString()
333 {
334 StringBuilder sb = new StringBuilder();
335
336 sb.append( " Compare request\n" );
337 sb.append( " Entry : '" ).append( name.toString() ).append( "'\n" );
338 sb.append( " Attribute description : '" ).append( attrId ).append( "'\n" );
339 sb.append( " Attribute value : '" );
340
341 if ( attrVal.isHumanReadable() )
342 {
343 sb.append( attrVal.getValue() );
344 }
345 else
346 {
347 byte[] binVal = attrVal.getBytes();
348 sb.append( Strings.utf8ToString( binVal ) ).append( '/' ).append( Strings.dumpBytes( binVal ) )
349 .append( "'\n" );
350 }
351
352
353 sb.append( super.toString() );
354
355 return super.toString( sb.toString() );
356 }
357 }