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.subtree;
21
22
23 import java.util.Collections;
24 import java.util.Set;
25
26 import org.apache.directory.api.ldap.model.filter.ExprNode;
27 import org.apache.directory.api.ldap.model.name.Dn;
28
29
30
31
32
33
34
35 public class BaseSubtreeSpecification implements SubtreeSpecification
36 {
37
38 private final Dn base;
39
40
41 private final Set<Dn> chopBefore;
42
43
44 private final Set<Dn> chopAfter;
45
46
47 private final int minBaseDistance;
48
49
50 private final int maxBaseDistance;
51
52
53
54
55
56 private final ExprNode refinement;
57
58
59
60
61
62
63
64
65
66
67
68 @SuppressWarnings("unchecked")
69 public BaseSubtreeSpecification()
70 {
71 this.base = new Dn();
72 this.minBaseDistance = 0;
73 this.maxBaseDistance = UNBOUNDED_MAX;
74 this.chopAfter = Collections.EMPTY_SET;
75 this.chopBefore = Collections.EMPTY_SET;
76 this.refinement = null;
77 }
78
79
80
81
82
83
84
85
86
87
88 @SuppressWarnings("unchecked")
89 public BaseSubtreeSpecification( ExprNode refinement )
90 {
91 this.base = new Dn();
92 this.minBaseDistance = 0;
93 this.maxBaseDistance = UNBOUNDED_MAX;
94 this.chopAfter = Collections.EMPTY_SET;
95 this.chopBefore = Collections.EMPTY_SET;
96 this.refinement = refinement;
97 }
98
99
100
101
102
103
104
105
106
107 @SuppressWarnings("unchecked")
108 public BaseSubtreeSpecification( Dn base )
109 {
110 this.base = base;
111 this.minBaseDistance = 0;
112 this.maxBaseDistance = UNBOUNDED_MAX;
113 this.chopAfter = Collections.EMPTY_SET;
114 this.chopBefore = Collections.EMPTY_SET;
115 this.refinement = null;
116 }
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131 public BaseSubtreeSpecification( Dn base, int minBaseDistance, int maxBaseDistance,
132 Set<Dn> chopAfter, Set<Dn> chopBefore )
133 {
134 this( base, minBaseDistance, maxBaseDistance, chopAfter, chopBefore, null );
135 }
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153 public BaseSubtreeSpecification( Dn base, int minBaseDistance, int maxBaseDistance,
154 Set<Dn> chopAfter, Set<Dn> chopBefore, ExprNode refinement )
155 {
156 this.base = base;
157 this.minBaseDistance = minBaseDistance;
158
159 if ( maxBaseDistance < 0 )
160 {
161 this.maxBaseDistance = UNBOUNDED_MAX;
162 }
163 else
164 {
165 this.maxBaseDistance = maxBaseDistance;
166 }
167
168 this.chopAfter = chopAfter;
169 this.chopBefore = chopBefore;
170 this.refinement = refinement;
171 }
172
173
174
175
176
177
178
179
180 public Dn getBase()
181 {
182 return this.base;
183 }
184
185
186
187
188
189 public Set<Dn> getChopBeforeExclusions()
190 {
191 return this.chopBefore;
192 }
193
194
195
196
197
198 public Set<Dn> getChopAfterExclusions()
199 {
200 return this.chopAfter;
201 }
202
203
204
205
206
207 public int getMinBaseDistance()
208 {
209 return this.minBaseDistance;
210 }
211
212
213
214
215
216 public int getMaxBaseDistance()
217 {
218 return this.maxBaseDistance;
219 }
220
221
222
223
224
225 public ExprNode getRefinement()
226 {
227 return this.refinement;
228 }
229
230
231
232
233
234
235
236
237 public void toString( StringBuilder buffer )
238 {
239 buffer.append( toString() );
240 }
241
242
243
244
245
246 public String toString()
247 {
248 StringBuilder buffer = new StringBuilder();
249 boolean isFirst = true;
250 buffer.append( '{' );
251
252
253 if ( !base.isEmpty() )
254 {
255 buffer.append( " base \"" );
256 buffer.append( base.getName() );
257 buffer.append( '"' );
258 isFirst = false;
259 }
260
261
262 if ( minBaseDistance > 0 )
263 {
264 if ( isFirst )
265 {
266 isFirst = false;
267 buffer.append( " " );
268 }
269 else
270 {
271 buffer.append( ", " );
272 }
273
274 buffer.append( "minimum " );
275 buffer.append( minBaseDistance );
276 }
277
278
279 if ( maxBaseDistance > UNBOUNDED_MAX )
280 {
281 if ( isFirst )
282 {
283 isFirst = false;
284 buffer.append( " " );
285 }
286 else
287 {
288 buffer.append( ", " );
289 }
290
291 buffer.append( "maximum " );
292 buffer.append( maxBaseDistance );
293 }
294
295
296 if ( !chopBefore.isEmpty() || !chopAfter.isEmpty() )
297 {
298 if ( isFirst )
299 {
300 isFirst = false;
301 buffer.append( " " );
302 }
303 else
304 {
305 buffer.append( ", " );
306 }
307
308 buffer.append( "specificExclusions { " );
309
310 boolean isFirstExclusion = true;
311
312 if ( chopBefore != null )
313 {
314 for ( Dn exclusion : chopBefore )
315 {
316 if ( isFirstExclusion )
317 {
318 isFirstExclusion = false;
319 }
320 else
321 {
322 buffer.append( ", " );
323 }
324
325 buffer.append( "chopBefore: \"" );
326 buffer.append( exclusion.getName() );
327 buffer.append( '"' );
328 }
329 }
330
331 if ( chopAfter != null )
332 {
333 for ( Dn exclusion : chopAfter )
334 {
335 if ( isFirstExclusion )
336 {
337 isFirstExclusion = false;
338 }
339 else
340 {
341 buffer.append( ", " );
342 }
343
344 buffer.append( "chopAfter: \"" );
345 buffer.append( exclusion.getName() );
346 buffer.append( '"' );
347 }
348 }
349
350 buffer.append( " }" );
351 }
352
353 if ( refinement != null )
354 {
355 if ( isFirst )
356 {
357 isFirst = false;
358 buffer.append( " " );
359 }
360 else
361 {
362 buffer.append( ", " );
363 }
364
365 buffer.append( "specificationFilter " );
366 buffer.append( refinement.toString() );
367 }
368
369 buffer.append( " }" );
370
371 return buffer.toString();
372 }
373 }