1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.ldap.server.schema.bootstrap;
18
19
20 import java.util.Comparator;
21
22 import javax.naming.NamingException;
23
24 import org.apache.ldap.common.schema.AbstractAttributeType;
25 import org.apache.ldap.common.schema.AbstractMatchingRule;
26 import org.apache.ldap.common.schema.AbstractSchemaObject;
27 import org.apache.ldap.common.schema.AbstractSyntax;
28 import org.apache.ldap.common.schema.AttributeType;
29 import org.apache.ldap.common.schema.MatchingRule;
30 import org.apache.ldap.common.schema.Normalizer;
31 import org.apache.ldap.common.schema.ObjectClass;
32 import org.apache.ldap.common.schema.ObjectClassTypeEnum;
33 import org.apache.ldap.common.schema.Syntax;
34 import org.apache.ldap.common.schema.SyntaxChecker;
35 import org.apache.ldap.common.schema.UsageEnum;
36 import org.apache.ldap.server.schema.AttributeTypeRegistry;
37 import org.apache.ldap.server.schema.ComparatorRegistry;
38 import org.apache.ldap.server.schema.MatchingRuleRegistry;
39 import org.apache.ldap.server.schema.NormalizerRegistry;
40 import org.apache.ldap.server.schema.ObjectClassRegistry;
41 import org.apache.ldap.server.schema.SyntaxCheckerRegistry;
42 import org.apache.ldap.server.schema.SyntaxRegistry;
43
44
45 /***
46 * An abstract producer implementation.
47 *
48 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
49 * @version $Rev: 264732 $
50 */
51 public abstract class AbstractBootstrapProducer implements BootstrapProducer
52 {
53 /*** a reused empty String array */
54 protected static final String[] EMPTY = new String[0];
55 /*** the producer type */
56 private final ProducerTypeEnum type;
57
58
59 /***
60 * Creates a producer of a specific type.
61 *
62 * @param type the producer type
63 */
64 protected AbstractBootstrapProducer( ProducerTypeEnum type )
65 {
66 this.type = type;
67 }
68
69
70 /***
71 * @see BootstrapProducer#getType()
72 */
73 public ProducerTypeEnum getType()
74 {
75 return type;
76 }
77
78
79 protected static BootstrapSyntax
80 newSyntax( String oid, BootstrapRegistries registries )
81 {
82 return new BootstrapSyntax( oid, registries.getSyntaxCheckerRegistry() );
83 }
84
85
86
87 protected static BootstrapAttributeType
88 newAttributeType( String oid, BootstrapRegistries registries )
89 {
90 return new BootstrapAttributeType( oid, registries );
91 }
92
93
94
95 protected static BootstrapObjectClass
96 newObjectClass( String oid, BootstrapRegistries registries )
97 {
98 return new BootstrapObjectClass( oid, registries );
99 }
100
101
102
103 /***
104 * A mutable Syntax for the bootstrap phase that uses the
105 * syntaxCheckerRegistry to dynamically resolve syntax checkers.
106 */
107 public static class BootstrapSyntax extends AbstractSyntax
108 {
109 final SyntaxCheckerRegistry registry;
110
111
112 protected BootstrapSyntax( String oid, SyntaxCheckerRegistry registry )
113 {
114 super( oid );
115 this.registry = registry;
116 }
117
118
119 public void setDescription( String description )
120 {
121 super.setDescription( description );
122 }
123
124
125 public void setHumanReadible( boolean isHumanReadible )
126 {
127 super.setHumanReadible( isHumanReadible );
128 }
129
130
131 public void setNames( String[] names )
132 {
133 super.setNames( names );
134 }
135
136
137 public SyntaxChecker getSyntaxChecker( ) throws NamingException
138 {
139 return registry.lookup( getOid() );
140 }
141
142
143 public boolean isObsolete()
144 {
145 return false;
146 }
147 }
148
149
150 public static class BootstrapMatchingRule extends AbstractMatchingRule
151 {
152 final SyntaxRegistry syntaxRegistry;
153 final NormalizerRegistry normalizerRegistry;
154 final ComparatorRegistry comparatorRegistry;
155 String syntaxOid;
156
157
158 protected BootstrapMatchingRule( String oid, BootstrapRegistries registries )
159 {
160 super( oid );
161 this.syntaxRegistry = registries.getSyntaxRegistry();
162 this.normalizerRegistry = registries.getNormalizerRegistry();
163 this.comparatorRegistry = registries.getComparatorRegistry();
164 }
165
166
167 public void setNames( String[] names )
168 {
169 super.setNames( names );
170 }
171
172 public void setSyntaxOid( String syntaxOid )
173 {
174 this.syntaxOid = syntaxOid;
175 }
176
177 public void setDescription( String description )
178 {
179 super.setDescription( description );
180 }
181
182 public void setObsolete( boolean isObsolete )
183 {
184 super.setObsolete( isObsolete );
185 }
186
187
188
189
190
191 public Syntax getSyntax() throws NamingException
192 {
193 return syntaxRegistry.lookup( syntaxOid );
194 }
195
196 public Comparator getComparator() throws NamingException
197 {
198 return comparatorRegistry.lookup( getOid() );
199 }
200
201 public Normalizer getNormalizer() throws NamingException
202 {
203 return normalizerRegistry.lookup( getOid() );
204 }
205 }
206
207
208 /***
209 * A concrete mutable attributeType implementation for bootstrapping which
210 * uses registries for dynamically resolving dependent objects.
211 */
212 public static class BootstrapAttributeType extends AbstractAttributeType
213 {
214 private static final long serialVersionUID = 4050205236738471984L;
215
216 private final SyntaxRegistry syntaxRegistry;
217 private final MatchingRuleRegistry matchingRuleRegistry;
218 private final AttributeTypeRegistry attributeTypeRegistry;
219 private String superiorId;
220 private String equalityId;
221 private String substrId;
222 private String orderingId;
223 private String syntaxId;
224
225
226 protected BootstrapAttributeType( String oid, BootstrapRegistries registries )
227 {
228 super( oid );
229
230 syntaxRegistry = registries.getSyntaxRegistry();
231 matchingRuleRegistry = registries.getMatchingRuleRegistry();
232 attributeTypeRegistry = registries.getAttributeTypeRegistry();
233 }
234
235 public void setSuperiorId( String superiorId )
236 {
237 this.superiorId = superiorId;
238 }
239
240 public AttributeType getSuperior() throws NamingException
241 {
242 if ( superiorId == null )
243 {
244 return null;
245 }
246
247 return this.attributeTypeRegistry.lookup( superiorId );
248 }
249
250 public void setNames( String[] names )
251 {
252 super.setNames( names );
253 }
254
255 public MatchingRule getEquality() throws NamingException
256 {
257 if ( equalityId != null )
258 {
259 return this.matchingRuleRegistry.lookup( equalityId );
260 }
261
262 if ( superiorId != null )
263 {
264 return getSuperior().getEquality();
265 }
266
267 return null;
268 }
269
270 public void setEqualityId( String equalityId )
271 {
272 this.equalityId = equalityId;
273 }
274
275 public MatchingRule getSubstr() throws NamingException
276 {
277 if ( substrId != null )
278 {
279 return this.matchingRuleRegistry.lookup( substrId );
280 }
281
282 if ( superiorId != null )
283 {
284 return getSuperior().getSubstr();
285 }
286
287 return null;
288 }
289
290 public void setSubstrId( String substrId )
291 {
292 this.substrId = substrId;
293 }
294
295 public MatchingRule getOrdering() throws NamingException
296 {
297 if ( orderingId != null )
298 {
299 return this.matchingRuleRegistry.lookup( orderingId );
300 }
301
302 if ( superiorId != null )
303 {
304 return getSuperior().getOrdering();
305 }
306
307 return null;
308 }
309
310 public void setOrderingId( String orderingId )
311 {
312 this.orderingId = orderingId;
313 }
314
315 public void setSyntaxId( String syntaxId )
316 {
317 this.syntaxId = syntaxId;
318 }
319
320 public Syntax getSyntax() throws NamingException
321 {
322 if ( syntaxId != null )
323 {
324 return this.syntaxRegistry.lookup( syntaxId );
325 }
326
327 if ( superiorId != null )
328 {
329 return getSuperior().getSyntax();
330 }
331
332 return null;
333 }
334
335 public void setSingleValue( boolean singleValue )
336 {
337 super.setSingleValue( singleValue );
338 }
339
340 public void setCollective( boolean collective )
341 {
342 super.setCollective( collective );
343 }
344
345 public void setCanUserModify( boolean canUserModify )
346 {
347 super.setCanUserModify( canUserModify );
348 }
349
350 public void setObsolete( boolean obsolete )
351 {
352 super.setObsolete( obsolete );
353 }
354
355 public void setDescription( String description )
356 {
357 super.setDescription( description );
358 }
359
360 public void setUsage( UsageEnum usage )
361 {
362 super.setUsage( usage );
363 }
364
365 public void setLength( int length )
366 {
367 super.setLength( length );
368 }
369 }
370
371
372 /***
373 * A concrete mutable objectClass implementation for bootstrapping which
374 * uses registries for dynamically resolving dependent objects.
375 */
376 public static class BootstrapObjectClass extends AbstractSchemaObject
377 implements ObjectClass
378 {
379 private final ObjectClassRegistry objectClassRegistry;
380 private final AttributeTypeRegistry attributeTypeRegistry;
381
382 private String[] superClassIds = EMPTY;
383 private ObjectClass[] superClasses;
384 private ObjectClassTypeEnum type = ObjectClassTypeEnum.STRUCTURAL;
385
386 private String[] mayListIds = EMPTY;
387 private AttributeType[] mayList;
388
389 private String[] mustListIds = EMPTY;
390 private AttributeType[] mustList;
391
392
393 /***
394 * Creates a mutable ObjectClass for the bootstrap process.
395 *
396 * @param oid the OID of the new objectClass
397 * @param registries the bootstrap registries to use for resolving dependent objects
398 */
399 protected BootstrapObjectClass( String oid, BootstrapRegistries registries )
400 {
401 super( oid );
402
403 objectClassRegistry = registries.getObjectClassRegistry();
404 attributeTypeRegistry = registries.getAttributeTypeRegistry();
405 }
406
407
408
409
410
411
412
413 public ObjectClass[] getSuperClasses() throws NamingException
414 {
415 if ( superClasses == null )
416 {
417 superClasses = new ObjectClass[superClassIds.length];
418 }
419
420 for( int ii = 0; ii < superClassIds.length; ii++ )
421 {
422 superClasses[ii] = objectClassRegistry.lookup( superClassIds[ii] );
423 }
424
425 return superClasses;
426 }
427
428
429 public void setSuperClassIds( String[] superClassIds )
430 {
431 this.superClassIds = superClassIds;
432 }
433
434
435 public ObjectClassTypeEnum getType()
436 {
437 return type;
438 }
439
440
441 public void setType( ObjectClassTypeEnum type )
442 {
443 this.type = type;
444 }
445
446
447 public AttributeType[] getMustList() throws NamingException
448 {
449 if ( mustList == null )
450 {
451 mustList = new AttributeType[mustListIds.length];
452 }
453
454 for( int ii = 0; ii < mustListIds.length; ii++ )
455 {
456 mustList[ii] = attributeTypeRegistry.lookup( mustListIds[ii] );
457 }
458
459 return mustList;
460 }
461
462
463 public void setMustListIds( String[] mustListIds )
464 {
465 this.mustListIds = mustListIds;
466 }
467
468
469 public AttributeType[] getMayList() throws NamingException
470 {
471 if ( mayList == null )
472 {
473 mayList = new AttributeType[mayListIds.length];
474 }
475
476 for( int ii = 0; ii < mayListIds.length; ii++ )
477 {
478 mayList[ii] = attributeTypeRegistry.lookup( mayListIds[ii] );
479 }
480
481 return mayList;
482 }
483
484
485 public void setMayListIds( String[] mayListIds )
486 {
487 this.mayListIds = mayListIds;
488 }
489
490
491
492
493
494
495
496 public void setObsolete( boolean obsolete )
497 {
498 super.setObsolete( obsolete );
499 }
500
501 public void setNames( String[] names )
502 {
503 super.setNames( names );
504 }
505
506 public void setDescription( String description )
507 {
508 super.setDescription( description );
509 }
510
511
512 }
513 }