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