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.filter;
21
22
23 import org.apache.directory.api.ldap.model.entry.Value;
24 import org.apache.directory.api.ldap.model.schema.AttributeType;
25
26
27
28
29
30
31
32 public class ExtensibleNode extends LeafNode
33 {
34
35 private Value value;
36
37
38 protected byte[] bytes;
39
40
41 private String matchingRuleId;
42
43
44 private boolean dnAttributes = false;
45
46
47
48
49
50
51
52 public ExtensibleNode( AttributeType attributeType )
53 {
54 super( attributeType, AssertionType.EXTENSIBLE );
55
56 dnAttributes = false;
57 }
58
59
60
61
62
63
64
65 public ExtensibleNode( String attribute )
66 {
67 super( attribute, AssertionType.EXTENSIBLE );
68
69 dnAttributes = false;
70 }
71
72
73
74
75
76
77
78
79
80
81 public ExtensibleNode( AttributeType attributeType, Value value, String matchingRuleId, boolean dnAttributes )
82 {
83 super( attributeType, AssertionType.EXTENSIBLE );
84
85 this.value = value;
86 this.matchingRuleId = matchingRuleId;
87 this.dnAttributes = dnAttributes;
88 }
89
90
91
92
93
94
95
96
97
98
99 public ExtensibleNode( String attribute, Value value, String matchingRuleId, boolean dnAttributes )
100 {
101 super( attribute, AssertionType.EXTENSIBLE );
102
103 this.value = value;
104 this.matchingRuleId = matchingRuleId;
105 this.dnAttributes = dnAttributes;
106 }
107
108
109
110
111
112
113
114 @Override
115 public ExprNode clone()
116 {
117 ExprNode clone = super.clone();
118
119
120 if ( value != null )
121 {
122 ( ( ExtensibleNode ) clone ).value = value.clone();
123 }
124
125 return clone;
126 }
127
128
129
130
131
132
133
134 public boolean hasDnAttributes()
135 {
136 return dnAttributes;
137 }
138
139
140
141
142
143
144
145 public void setDnAttributes( boolean dnAttributes )
146 {
147 this.dnAttributes = dnAttributes;
148 }
149
150
151
152
153
154
155
156 public String getMatchingRuleId()
157 {
158 return matchingRuleId;
159 }
160
161
162
163
164
165
166
167 public void setMatchingRuleId( String matchingRuleId )
168 {
169 this.matchingRuleId = matchingRuleId;
170 }
171
172
173
174
175
176
177
178 public final Value getValue()
179 {
180 return value;
181 }
182
183
184
185
186
187 public String getEscapedValue()
188 {
189 if ( value.isHumanReadable() )
190 {
191 return escapeFilterValue( value.getString() );
192 }
193 else
194 {
195 return escapeFilterValue( value.getAttributeType(), value.getBytes() );
196 }
197 }
198
199
200
201
202
203
204
205 public final void setValue( Value value )
206 {
207 this.value = value;
208 }
209
210
211
212
213
214 @Override
215 public boolean equals( Object obj )
216 {
217 if ( obj == this )
218 {
219 return true;
220 }
221
222 if ( !( obj instanceof ExtensibleNode ) )
223 {
224 return false;
225 }
226 ExtensibleNode that = ( ExtensibleNode ) obj;
227
228 if ( dnAttributes != that.dnAttributes )
229 {
230 return false;
231 }
232 if ( !matchingRuleId.equals( that.matchingRuleId ) )
233 {
234 return false;
235 }
236 if ( !value.equals( that.value ) )
237 {
238 return false;
239 }
240
241 return super.equals( obj );
242 }
243
244
245
246
247
248
249 @Override
250 public int hashCode()
251 {
252 int h = 37;
253
254 h = h * 17 + super.hashCode();
255 h = h * 17 + ( dnAttributes ? 1 : 0 );
256 h = h * 17 + matchingRuleId.hashCode();
257 h = h * 17 + value.hashCode();
258
259 return h;
260 }
261
262
263
264
265
266
267 @Override
268 public String toString()
269 {
270 StringBuilder buf = new StringBuilder();
271
272 buf.append( '(' );
273
274 if ( attributeType != null )
275 {
276 buf.append( attributeType.getName() );
277 }
278 else
279 {
280 buf.append( attribute );
281 }
282
283 buf.append( "-" );
284 buf.append( dnAttributes );
285 buf.append( "-EXTENSIBLE-" );
286 buf.append( matchingRuleId );
287 buf.append( "-" );
288 buf.append( value );
289
290 buf.append( super.toString() );
291
292 buf.append( ')' );
293
294 return buf.toString();
295 }
296 }