1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.ldap.server.schema;
18
19
20 import java.util.ArrayList;
21 import java.util.Iterator;
22 import java.util.List;
23
24 import javax.naming.NamingException;
25
26 import org.apache.ldap.common.schema.AttributeType;
27 import org.apache.ldap.common.schema.MatchingRule;
28 import org.apache.ldap.common.schema.ObjectClass;
29 import org.apache.ldap.common.schema.Syntax;
30 import org.apache.ldap.server.schema.bootstrap.BootstrapAttributeTypeRegistry;
31 import org.apache.ldap.server.schema.bootstrap.BootstrapComparatorRegistry;
32 import org.apache.ldap.server.schema.bootstrap.BootstrapDitContentRuleRegistry;
33 import org.apache.ldap.server.schema.bootstrap.BootstrapDitStructureRuleRegistry;
34 import org.apache.ldap.server.schema.bootstrap.BootstrapMatchingRuleRegistry;
35 import org.apache.ldap.server.schema.bootstrap.BootstrapMatchingRuleUseRegistry;
36 import org.apache.ldap.server.schema.bootstrap.BootstrapNameFormRegistry;
37 import org.apache.ldap.server.schema.bootstrap.BootstrapNormalizerRegistry;
38 import org.apache.ldap.server.schema.bootstrap.BootstrapObjectClassRegistry;
39 import org.apache.ldap.server.schema.bootstrap.BootstrapOidRegistry;
40 import org.apache.ldap.server.schema.bootstrap.BootstrapRegistries;
41 import org.apache.ldap.server.schema.bootstrap.BootstrapSyntaxCheckerRegistry;
42 import org.apache.ldap.server.schema.bootstrap.BootstrapSyntaxRegistry;
43
44
45 /***
46 * Document me.
47 *
48 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
49 * @version $Rev: 264732 $
50 */
51 public class GlobalRegistries implements Registries
52 {
53 private GlobalAttributeTypeRegistry attributeTypeRegistry;
54 private GlobalComparatorRegistry comparatorRegistry;
55 private GlobalDitContentRuleRegistry ditContentRuleRegistry;
56 private GlobalDitStructureRuleRegistry ditStructureRuleRegistry;
57 private GlobalMatchingRuleRegistry matchingRuleRegistry;
58 private GlobalMatchingRuleUseRegistry matchingRuleUseRegistry;
59 private GlobalNameFormRegistry nameFormRegistry;
60 private GlobalNormalizerRegistry normalizerRegistry;
61 private GlobalObjectClassRegistry objectClassRegistry;
62 private GlobalOidRegistry oidRegistry;
63 private GlobalSyntaxCheckerRegistry syntaxCheckerRegistry;
64 private GlobalSyntaxRegistry syntaxRegistry;
65
66
67 public GlobalRegistries( BootstrapRegistries bootstrapRegistries )
68 {
69 oidRegistry = new GlobalOidRegistry(
70 ( BootstrapOidRegistry ) bootstrapRegistries.getOidRegistry() );
71 normalizerRegistry = new GlobalNormalizerRegistry(
72 ( BootstrapNormalizerRegistry ) bootstrapRegistries.getNormalizerRegistry());
73 comparatorRegistry = new GlobalComparatorRegistry(
74 ( BootstrapComparatorRegistry ) bootstrapRegistries.getComparatorRegistry());
75 syntaxCheckerRegistry = new GlobalSyntaxCheckerRegistry(
76 ( BootstrapSyntaxCheckerRegistry ) bootstrapRegistries.getSyntaxCheckerRegistry());
77 syntaxRegistry = new GlobalSyntaxRegistry(
78 ( BootstrapSyntaxRegistry ) bootstrapRegistries.getSyntaxRegistry(),
79 oidRegistry );
80 matchingRuleRegistry = new GlobalMatchingRuleRegistry(
81 ( BootstrapMatchingRuleRegistry ) bootstrapRegistries.getMatchingRuleRegistry(),
82 oidRegistry );
83 attributeTypeRegistry = new GlobalAttributeTypeRegistry(
84 ( BootstrapAttributeTypeRegistry ) bootstrapRegistries.getAttributeTypeRegistry(),
85 oidRegistry );
86 objectClassRegistry = new GlobalObjectClassRegistry(
87 ( BootstrapObjectClassRegistry ) bootstrapRegistries.getObjectClassRegistry(),
88 oidRegistry );
89 ditContentRuleRegistry = new GlobalDitContentRuleRegistry(
90 ( BootstrapDitContentRuleRegistry ) bootstrapRegistries.getDitContentRuleRegistry(),
91 oidRegistry );
92 ditStructureRuleRegistry = new GlobalDitStructureRuleRegistry(
93 ( BootstrapDitStructureRuleRegistry ) bootstrapRegistries.getDitStructureRuleRegistry(),
94 oidRegistry );
95 matchingRuleUseRegistry = new GlobalMatchingRuleUseRegistry(
96 ( BootstrapMatchingRuleUseRegistry ) bootstrapRegistries.getMatchingRuleUseRegistry(),
97 oidRegistry );
98 nameFormRegistry = new GlobalNameFormRegistry(
99 ( BootstrapNameFormRegistry ) bootstrapRegistries.getNameFormRegistry(),
100 oidRegistry );
101 }
102
103
104 public AttributeTypeRegistry getAttributeTypeRegistry()
105 {
106 return attributeTypeRegistry;
107 }
108
109 public ComparatorRegistry getComparatorRegistry()
110 {
111 return comparatorRegistry;
112 }
113
114 public DITContentRuleRegistry getDitContentRuleRegistry()
115 {
116 return ditContentRuleRegistry;
117 }
118
119 public DITStructureRuleRegistry getDitStructureRuleRegistry()
120 {
121 return ditStructureRuleRegistry;
122 }
123
124 public MatchingRuleRegistry getMatchingRuleRegistry()
125 {
126 return matchingRuleRegistry;
127 }
128
129 public MatchingRuleUseRegistry getMatchingRuleUseRegistry()
130 {
131 return matchingRuleUseRegistry;
132 }
133
134 public NameFormRegistry getNameFormRegistry()
135 {
136 return nameFormRegistry;
137 }
138
139 public NormalizerRegistry getNormalizerRegistry()
140 {
141 return normalizerRegistry;
142 }
143
144 public ObjectClassRegistry getObjectClassRegistry()
145 {
146 return objectClassRegistry;
147 }
148
149 public OidRegistry getOidRegistry()
150 {
151 return oidRegistry;
152 }
153
154 public SyntaxCheckerRegistry getSyntaxCheckerRegistry()
155 {
156 return syntaxCheckerRegistry;
157 }
158
159 public SyntaxRegistry getSyntaxRegistry()
160 {
161 return syntaxRegistry;
162 }
163
164
165
166
167
168
169
170 /***
171 * Attempts to resolve the dependent schema objects of all entities that
172 * refer to other objects within the registries. Null references will be
173 * handed appropriately.
174 *
175 * @return a list of exceptions encountered while resolving entities
176 */
177 public List checkRefInteg()
178 {
179 ArrayList errors = new ArrayList();
180
181 Iterator list = objectClassRegistry.list();
182 while ( list.hasNext() )
183 {
184 ObjectClass oc = ( ObjectClass ) list.next();
185 resolve( oc, errors );
186 }
187
188 list = attributeTypeRegistry.list();
189 while ( list.hasNext() )
190 {
191 AttributeType at = ( AttributeType ) list.next();
192 resolve( at, errors );
193 }
194
195 list = matchingRuleRegistry.list();
196 while ( list.hasNext() )
197 {
198 MatchingRule mr = ( MatchingRule ) list.next();
199 resolve( mr, errors );
200 }
201
202 list = syntaxRegistry.list();
203 while ( list.hasNext() )
204 {
205 Syntax syntax = ( Syntax ) list.next();
206 resolve( syntax, errors );
207 }
208
209 return errors;
210 }
211
212
213 /***
214 * Attempts to resolve the SyntaxChecker associated with a Syntax.
215 *
216 * @param syntax the Syntax to resolve the SyntaxChecker of
217 * @param errors the list of errors to add exceptions to
218 * @return true if it succeeds, false otherwise
219 */
220 private boolean resolve( Syntax syntax, List errors )
221 {
222 if ( syntax == null )
223 {
224 return true;
225 }
226
227 try
228 {
229 syntax.getSyntaxChecker();
230 return true;
231 }
232 catch ( NamingException e )
233 {
234 errors.add( e );
235 return false;
236 }
237 }
238
239
240 private boolean resolve( MatchingRule mr, List errors )
241 {
242 boolean isSuccess = true;
243
244 if ( mr == null )
245 {
246 return true;
247 }
248
249 try
250 {
251 if ( mr.getComparator() == null )
252 {
253 String schema = matchingRuleRegistry.getSchemaName( mr.getOid() );
254 errors.add( new NullPointerException( "matchingRule "
255 + mr.getName() + " in schema " + schema + " with OID "
256 + mr.getOid() + " has a null comparator" ) );
257 isSuccess = false;
258 }
259 }
260 catch ( NamingException e )
261 {
262 errors.add( e );
263 isSuccess = false;
264 }
265
266 try
267 {
268 if ( mr.getNormalizer() == null )
269 {
270 String schema = matchingRuleRegistry.getSchemaName( mr.getOid() );
271 errors.add( new NullPointerException( "matchingRule "
272 + mr.getName() + " in schema " + schema + " with OID "
273 + mr.getOid() + " has a null normalizer" ) );
274 isSuccess = false;
275 }
276 }
277 catch ( NamingException e )
278 {
279 errors.add( e );
280 isSuccess = false;
281 }
282
283 try
284 {
285 isSuccess &= resolve( mr.getSyntax(), errors );
286
287 if ( mr.getSyntax() == null )
288 {
289 String schema = matchingRuleRegistry.getSchemaName( mr.getOid() );
290 errors.add( new NullPointerException( "matchingRule "
291 + mr.getName() + " in schema " + schema + " with OID " + mr.getOid()
292 + " has a null Syntax" ) );
293 isSuccess = false;
294 }
295 }
296 catch ( NamingException e )
297 {
298 errors.add( e );
299 isSuccess = false;
300 }
301
302 return isSuccess;
303 }
304
305
306 private boolean resolve( AttributeType at, List errors )
307 {
308 boolean isSuccess = true;
309 boolean hasMatchingRule = false;
310
311 if ( at == null )
312 {
313 return true;
314 }
315
316 try
317 {
318 isSuccess &= resolve( at.getSuperior(), errors );
319 }
320 catch ( NamingException e )
321 {
322 errors.add( e );
323 isSuccess = false;
324 }
325
326 try
327 {
328 isSuccess &= resolve( at.getEquality(), errors );
329
330 if ( at.getEquality() != null )
331 {
332 hasMatchingRule |= true;
333 }
334 }
335 catch ( NamingException e )
336 {
337 errors.add( e );
338 isSuccess = false;
339 }
340
341 try
342 {
343 isSuccess &= resolve( at.getOrdering(), errors );
344
345 if ( at.getOrdering() != null )
346 {
347 hasMatchingRule |= true;
348 }
349 }
350 catch ( NamingException e )
351 {
352 errors.add( e );
353 isSuccess = false;
354 }
355
356 try
357 {
358 isSuccess &= resolve( at.getSubstr(), errors );
359
360 if ( at.getSubstr() != null )
361 {
362 hasMatchingRule |= true;
363 }
364 }
365 catch ( NamingException e )
366 {
367 errors.add( e );
368 isSuccess = false;
369 }
370
371 try
372 {
373 isSuccess &= resolve( at.getSyntax(), errors );
374
375 if ( at.getSyntax() == null )
376 {
377 String schema = attributeTypeRegistry.getSchemaName( at.getOid() );
378 errors.add( new NullPointerException( "attributeType "
379 + at.getName() + " in schema " + schema + " with OID "
380 + at.getOid() + " has a null Syntax" ) );
381 isSuccess = false;
382 }
383 }
384 catch ( NamingException e )
385 {
386 errors.add( e );
387 isSuccess = false;
388 }
389
390 if ( hasMatchingRule )
391 {
392
393 }
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411 return isSuccess;
412 }
413
414
415 private boolean resolve( ObjectClass oc, List errors )
416 {
417 boolean isSuccess = true;
418
419 if ( oc == null )
420 {
421 return true;
422 }
423
424 ObjectClass[] superiors = new ObjectClass[0];
425 try
426 {
427 superiors = oc.getSuperClasses();
428 }
429 catch ( NamingException e )
430 {
431 superiors = new ObjectClass[0];
432 isSuccess = false;
433 errors.add( e );
434 }
435
436 for ( int ii = 0; ii < superiors.length; ii++ )
437 {
438 isSuccess &= resolve( superiors[ii], errors ) ;
439 }
440
441 AttributeType[] mayList = new AttributeType[0];
442 try
443 {
444 mayList = oc.getMayList();
445 }
446 catch ( NamingException e )
447 {
448 mayList = new AttributeType[0];
449 isSuccess = false;
450 errors.add( e );
451 }
452
453 for ( int ii = 0; ii < mayList.length; ii++ )
454 {
455 isSuccess &= resolve( mayList[ii], errors ) ;
456 }
457
458
459 AttributeType[] mustList = new AttributeType[0];
460 try
461 {
462 mustList = oc.getMustList();
463 }
464 catch ( NamingException e )
465 {
466 mustList = new AttributeType[0];
467 isSuccess = false;
468 errors.add( e );
469 }
470
471 for ( int ii = 0; ii < mustList.length; ii++ )
472 {
473 isSuccess &= resolve( mustList[ii], errors ) ;
474 }
475
476 return isSuccess;
477 }
478 }