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.schema.registries;
21
22
23 import java.util.ArrayList;
24 import java.util.Collections;
25 import java.util.HashMap;
26 import java.util.HashSet;
27 import java.util.List;
28 import java.util.Map;
29 import java.util.Set;
30
31 import org.apache.directory.api.i18n.I18n;
32 import org.apache.directory.api.ldap.model.constants.MetaSchemaConstants;
33 import org.apache.directory.api.ldap.model.exception.LdapException;
34 import org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException;
35 import org.apache.directory.api.ldap.model.exception.LdapSchemaException;
36 import org.apache.directory.api.ldap.model.exception.LdapSchemaExceptionCodes;
37 import org.apache.directory.api.ldap.model.exception.LdapSchemaViolationException;
38 import org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException;
39 import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
40 import org.apache.directory.api.ldap.model.schema.AttributeType;
41 import org.apache.directory.api.ldap.model.schema.DitContentRule;
42 import org.apache.directory.api.ldap.model.schema.DitStructureRule;
43 import org.apache.directory.api.ldap.model.schema.LdapComparator;
44 import org.apache.directory.api.ldap.model.schema.LdapSyntax;
45 import org.apache.directory.api.ldap.model.schema.LoadableSchemaObject;
46 import org.apache.directory.api.ldap.model.schema.MatchingRule;
47 import org.apache.directory.api.ldap.model.schema.MatchingRuleUse;
48 import org.apache.directory.api.ldap.model.schema.NameForm;
49 import org.apache.directory.api.ldap.model.schema.Normalizer;
50 import org.apache.directory.api.ldap.model.schema.ObjectClass;
51 import org.apache.directory.api.ldap.model.schema.SchemaErrorHandler;
52 import org.apache.directory.api.ldap.model.schema.SchemaObject;
53 import org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper;
54 import org.apache.directory.api.ldap.model.schema.SyntaxChecker;
55 import org.apache.directory.api.ldap.model.schema.registries.helper.AttributeTypeHelper;
56 import org.apache.directory.api.ldap.model.schema.registries.helper.DitContentRuleHelper;
57 import org.apache.directory.api.ldap.model.schema.registries.helper.DitStructureRuleHelper;
58 import org.apache.directory.api.ldap.model.schema.registries.helper.LdapSyntaxHelper;
59 import org.apache.directory.api.ldap.model.schema.registries.helper.MatchingRuleHelper;
60 import org.apache.directory.api.ldap.model.schema.registries.helper.MatchingRuleUseHelper;
61 import org.apache.directory.api.ldap.model.schema.registries.helper.NameFormHelper;
62 import org.apache.directory.api.ldap.model.schema.registries.helper.ObjectClassHelper;
63 import org.apache.directory.api.util.Strings;
64 import org.slf4j.Logger;
65 import org.slf4j.LoggerFactory;
66
67
68
69
70
71
72
73 public class Registries implements SchemaLoaderListener, Cloneable
74 {
75
76 private static final Logger LOG = LoggerFactory.getLogger( Registries.class );
77
78
79
80
81
82 protected Map<String, Schema> loadedSchemas = new HashMap<>();
83
84
85 protected DefaultAttributeTypeRegistry attributeTypeRegistry;
86
87
88 protected DefaultObjectClassRegistry objectClassRegistry;
89
90
91 protected DefaultComparatorRegistry comparatorRegistry;
92
93
94 protected DefaultDitContentRuleRegistry ditContentRuleRegistry;
95
96
97 protected DefaultDitStructureRuleRegistry ditStructureRuleRegistry;
98
99
100 protected DefaultMatchingRuleRegistry matchingRuleRegistry;
101
102
103 protected DefaultMatchingRuleUseRegistry matchingRuleUseRegistry;
104
105
106 protected DefaultNameFormRegistry nameFormRegistry;
107
108
109 protected DefaultNormalizerRegistry normalizerRegistry;
110
111
112 protected OidRegistry<SchemaObject> globalOidRegistry;
113
114
115 protected DefaultSyntaxCheckerRegistry syntaxCheckerRegistry;
116
117
118 protected DefaultLdapSyntaxRegistry ldapSyntaxRegistry;
119
120
121 private Map<String, Set<SchemaObjectWrapper>> schemaObjects;
122
123
124 private boolean isRelaxed;
125
126
127 private boolean disabledAccepted;
128
129 private SchemaErrorHandler errorHandler;
130
131
132
133 public static final boolean STRICT = false;
134
135
136 public static final boolean RELAXED = true;
137
138
139
140
141
142 protected Map<SchemaObjectWrapper, Set<SchemaObjectWrapper>> usedBy;
143
144
145
146
147
148 protected Map<SchemaObjectWrapper, Set<SchemaObjectWrapper>> using;
149
150
151
152
153
154 public Registries()
155 {
156 globalOidRegistry = new OidRegistry<>();
157 attributeTypeRegistry = new DefaultAttributeTypeRegistry();
158 comparatorRegistry = new DefaultComparatorRegistry();
159 ditContentRuleRegistry = new DefaultDitContentRuleRegistry();
160 ditStructureRuleRegistry = new DefaultDitStructureRuleRegistry();
161 ldapSyntaxRegistry = new DefaultLdapSyntaxRegistry();
162 matchingRuleRegistry = new DefaultMatchingRuleRegistry();
163 matchingRuleUseRegistry = new DefaultMatchingRuleUseRegistry();
164 nameFormRegistry = new DefaultNameFormRegistry();
165 normalizerRegistry = new DefaultNormalizerRegistry();
166 objectClassRegistry = new DefaultObjectClassRegistry();
167 syntaxCheckerRegistry = new DefaultSyntaxCheckerRegistry();
168 schemaObjects = new HashMap<>();
169 usedBy = new HashMap<>();
170 using = new HashMap<>();
171
172 isRelaxed = STRICT;
173 disabledAccepted = false;
174 }
175
176
177
178
179
180 public AttributeTypeRegistry getAttributeTypeRegistry()
181 {
182 return attributeTypeRegistry;
183 }
184
185
186
187
188
189 public ComparatorRegistry getComparatorRegistry()
190 {
191 return comparatorRegistry;
192 }
193
194
195
196
197
198 public DitContentRuleRegistry getDitContentRuleRegistry()
199 {
200 return ditContentRuleRegistry;
201 }
202
203
204
205
206
207 public DitStructureRuleRegistry getDitStructureRuleRegistry()
208 {
209 return ditStructureRuleRegistry;
210 }
211
212
213
214
215
216 public MatchingRuleRegistry getMatchingRuleRegistry()
217 {
218 return matchingRuleRegistry;
219 }
220
221
222
223
224
225 public MatchingRuleUseRegistry getMatchingRuleUseRegistry()
226 {
227 return matchingRuleUseRegistry;
228 }
229
230
231
232
233
234 public NameFormRegistry getNameFormRegistry()
235 {
236 return nameFormRegistry;
237 }
238
239
240
241
242
243 public NormalizerRegistry getNormalizerRegistry()
244 {
245 return normalizerRegistry;
246 }
247
248
249
250
251
252 public ObjectClassRegistry getObjectClassRegistry()
253 {
254 return objectClassRegistry;
255 }
256
257
258
259
260
261 public OidRegistry<SchemaObject> getGlobalOidRegistry()
262 {
263 return globalOidRegistry;
264 }
265
266
267
268
269
270 public SyntaxCheckerRegistry getSyntaxCheckerRegistry()
271 {
272 return syntaxCheckerRegistry;
273 }
274
275
276
277
278
279 public LdapSyntaxRegistry getLdapSyntaxRegistry()
280 {
281 return ldapSyntaxRegistry;
282 }
283
284
285
286
287
288
289
290
291
292 public String getOid( String name )
293 {
294
295
296 try
297 {
298 AttributeType attributeType = attributeTypeRegistry.lookup( name );
299
300 if ( attributeType != null )
301 {
302 return attributeType.getOid();
303 }
304 }
305 catch ( LdapException ne )
306 {
307
308 }
309
310
311 try
312 {
313 ObjectClass objectClass = objectClassRegistry.lookup( name );
314
315 if ( objectClass != null )
316 {
317 return objectClass.getOid();
318 }
319 }
320 catch ( LdapException ne )
321 {
322
323 }
324
325
326 try
327 {
328 LdapSyntax ldapSyntax = ldapSyntaxRegistry.lookup( name );
329
330 if ( ldapSyntax != null )
331 {
332 return ldapSyntax.getOid();
333 }
334 }
335 catch ( LdapException ne )
336 {
337
338 }
339
340
341 try
342 {
343 MatchingRule matchingRule = matchingRuleRegistry.lookup( name );
344
345 if ( matchingRule != null )
346 {
347 return matchingRule.getOid();
348 }
349 }
350 catch ( LdapException ne )
351 {
352
353 }
354
355
356 try
357 {
358 MatchingRuleUse matchingRuleUse = matchingRuleUseRegistry.lookup( name );
359
360 if ( matchingRuleUse != null )
361 {
362 return matchingRuleUse.getOid();
363 }
364 }
365 catch ( LdapException ne )
366 {
367
368 }
369
370
371 try
372 {
373 NameForm nameForm = nameFormRegistry.lookup( name );
374
375 if ( nameForm != null )
376 {
377 return nameForm.getOid();
378 }
379 }
380 catch ( LdapException ne )
381 {
382
383 }
384
385
386 try
387 {
388 DitContentRule ditContentRule = ditContentRuleRegistry.lookup( name );
389
390 if ( ditContentRule != null )
391 {
392 return ditContentRule.getOid();
393 }
394 }
395 catch ( LdapException ne )
396 {
397
398 }
399
400
401 try
402 {
403 DitStructureRule ditStructureRule = ditStructureRuleRegistry.lookup( name );
404
405 if ( ditStructureRule != null )
406 {
407 return ditStructureRule.getOid();
408 }
409 }
410 catch ( LdapException ne )
411 {
412
413 }
414
415 return null;
416 }
417
418
419
420
421
422
423
424
425 public Schema getLoadedSchema( String schemaName )
426 {
427 return loadedSchemas.get( Strings.toLowerCaseAscii( schemaName ) );
428 }
429
430
431
432
433
434
435
436
437 public boolean isSchemaLoaded( String schemaName )
438 {
439 return loadedSchemas.containsKey( Strings.toLowerCaseAscii( schemaName ) );
440 }
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467 public void checkRefInteg()
468 {
469
470
471
472
473 for ( Normalizer normalizer : normalizerRegistry )
474 {
475 resolve( normalizer );
476 }
477
478
479 for ( LdapComparator<?> comparator : comparatorRegistry )
480 {
481 resolve( comparator );
482 }
483
484
485 for ( SyntaxChecker syntaxChecker : syntaxCheckerRegistry )
486 {
487 resolve( syntaxChecker );
488 }
489
490
491
492 for ( LdapSyntax ldapSyntax : ldapSyntaxRegistry )
493 {
494 resolve( ldapSyntax );
495 }
496
497
498
499 for ( MatchingRule matchingRule : matchingRuleRegistry )
500 {
501 resolve( matchingRule );
502 }
503
504
505
506 for ( AttributeType attributeType : attributeTypeRegistry )
507 {
508 resolve( attributeType );
509 }
510
511
512
513 for ( ObjectClass objectClass : objectClassRegistry )
514 {
515 resolve( objectClass );
516 }
517
518
519 }
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541 public void delCrossReferences( AttributeType attributeType )
542 {
543 if ( attributeType.getEquality() != null )
544 {
545 delReference( attributeType, attributeType.getEquality() );
546 }
547
548 if ( attributeType.getOrdering() != null )
549 {
550 delReference( attributeType, attributeType.getOrdering() );
551 }
552
553 if ( attributeType.getSubstring() != null )
554 {
555 delReference( attributeType, attributeType.getSubstring() );
556 }
557
558 if ( attributeType.getSyntax() != null )
559 {
560 delReference( attributeType, attributeType.getSyntax() );
561 }
562
563 if ( attributeType.getSuperior() != null )
564 {
565 delReference( attributeType, attributeType.getSuperior() );
566 }
567 }
568
569
570
571
572
573
574
575
576
577
578
579
580 private void buildAttributeTypeReferences()
581 {
582 for ( AttributeType attributeType : attributeTypeRegistry )
583 {
584 if ( ( getUsing( attributeType ) == null ) || getUsing( attributeType ).isEmpty() )
585 {
586 buildReference( attributeType );
587 }
588 }
589 }
590
591
592
593
594
595 private void buildComparatorReferences()
596 {
597 for ( LdapComparator<?> comparator : comparatorRegistry )
598 {
599 buildReference( comparator );
600 }
601 }
602
603
604
605
606
607 private void buildDitContentRuleReferences()
608 {
609
610 }
611
612
613
614
615
616 private void buildDitStructureRuleReferences()
617 {
618
619 }
620
621
622
623
624
625
626
627
628
629
630 public void delCrossReferences( MatchingRule matchingRule )
631 {
632 if ( matchingRule.getLdapComparator() != null )
633 {
634 delReference( matchingRule, matchingRule.getLdapComparator() );
635 }
636
637 if ( matchingRule.getNormalizer() != null )
638 {
639 delReference( matchingRule, matchingRule.getNormalizer() );
640 }
641
642 if ( matchingRule.getSyntax() != null )
643 {
644 delReference( matchingRule, matchingRule.getSyntax() );
645 }
646 }
647
648
649
650
651
652
653
654 public void buildReference( SchemaObject schemaObject )
655 {
656 try
657 {
658 switch ( schemaObject.getObjectType() )
659 {
660 case ATTRIBUTE_TYPE:
661 AttributeTypeHelper.addToRegistries( ( AttributeType ) schemaObject, errorHandler, this );
662 break;
663
664 case DIT_CONTENT_RULE:
665 DitContentRuleHelper.addToRegistries( ( DitContentRule ) schemaObject, errorHandler, this );
666 break;
667
668 case DIT_STRUCTURE_RULE:
669 DitStructureRuleHelper.addToRegistries( ( DitStructureRule ) schemaObject, errorHandler, this );
670 break;
671
672 case LDAP_SYNTAX:
673 LdapSyntaxHelper.addToRegistries( ( LdapSyntax ) schemaObject, errorHandler, this );
674 break;
675
676 case MATCHING_RULE:
677 MatchingRuleHelper.addToRegistries( ( MatchingRule ) schemaObject, errorHandler, this );
678 break;
679
680 case MATCHING_RULE_USE:
681 MatchingRuleUseHelper.addToRegistries( ( MatchingRuleUse ) schemaObject, errorHandler, this );
682 break;
683
684 case NAME_FORM:
685 NameFormHelper.addToRegistries( ( NameForm ) schemaObject, errorHandler, this );
686 break;
687
688 case OBJECT_CLASS:
689 ObjectClassHelper.addToRegistries( ( ObjectClass ) schemaObject, errorHandler, this );
690 break;
691
692 case SYNTAX_CHECKER:
693 case NORMALIZER:
694 case COMPARATOR:
695
696 break;
697
698 default:
699 throw new IllegalArgumentException(
700 I18n.err( I18n.ERR_13718_UNEXPECTED_SCHEMA_OBJECT_TYPE, schemaObject.getObjectType() ) );
701 }
702 }
703 catch ( LdapException ne )
704 {
705
706 String msg = I18n.err( I18n.ERR_13746_CANNOT_BUILD_REFERENCES, schemaObject.getName(), ne.getLocalizedMessage() );
707
708 LdapProtocolErrorException error = new LdapProtocolErrorException( msg, ne );
709 errorHandler.handle( LOG, msg, error );
710 }
711 }
712
713
714
715
716
717
718
719 public void removeReference( SchemaObject schemaObject )
720 {
721 try
722 {
723 switch ( schemaObject.getObjectType() )
724 {
725 case ATTRIBUTE_TYPE:
726 AttributeTypeHelper.removeFromRegistries( ( AttributeType ) schemaObject, errorHandler, this );
727 break;
728
729 case LDAP_SYNTAX:
730 LdapSyntaxHelper.removeFromRegistries( ( LdapSyntax ) schemaObject, errorHandler, this );
731 break;
732
733 case MATCHING_RULE:
734 MatchingRuleHelper.removeFromRegistries( ( MatchingRule ) schemaObject, errorHandler, this );
735 break;
736
737 case OBJECT_CLASS:
738 ObjectClassHelper.removeFromRegistries( ( ObjectClass ) schemaObject, errorHandler, this );
739 break;
740
741 case DIT_CONTENT_RULE :
742
743 break;
744
745 case DIT_STRUCTURE_RULE :
746
747 break;
748
749 case NAME_FORM :
750
751 break;
752
753 case MATCHING_RULE_USE :
754
755 break;
756
757 case SYNTAX_CHECKER:
758 case NORMALIZER:
759 case COMPARATOR:
760
761 break;
762
763 default:
764 throw new IllegalArgumentException(
765 I18n.err( I18n.ERR_13718_UNEXPECTED_SCHEMA_OBJECT_TYPE, schemaObject.getObjectType() ) );
766 }
767 }
768 catch ( LdapException ne )
769 {
770
771 String msg = I18n.err( I18n.ERR_13747_CANNOT_REMOVE_REFERENCES, schemaObject.getName(), ne.getLocalizedMessage() );
772
773 LdapSchemaViolationException error = new LdapSchemaViolationException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, msg, ne );
774 errorHandler.handle( LOG, msg, error );
775 }
776 }
777
778
779
780
781
782 private void buildMatchingRuleReferences()
783 {
784 for ( MatchingRule matchingRule : matchingRuleRegistry )
785 {
786 buildReference( matchingRule );
787 }
788 }
789
790
791
792
793
794 private void buildMatchingRuleUseReferences()
795 {
796 for ( MatchingRuleUse matchingRuleUse : matchingRuleUseRegistry )
797 {
798 buildReference( matchingRuleUse );
799 }
800 }
801
802
803
804
805
806 private void buildNameFormReferences()
807 {
808
809 }
810
811
812
813
814
815 private void buildNormalizerReferences()
816 {
817 for ( Normalizer normalizer : normalizerRegistry )
818 {
819 buildReference( normalizer );
820 }
821 }
822
823
824
825
826
827 private void buildObjectClassReferences()
828 {
829
830 Set<String> done = new HashSet<>();
831
832
833 for ( ObjectClass objectClass : objectClassRegistry )
834 {
835 if ( done.contains( objectClass.getOid() ) )
836 {
837 continue;
838 }
839 else
840 {
841 done.add( objectClass.getOid() );
842 }
843
844 buildReference( objectClass );
845 }
846 }
847
848
849
850
851
852 private void buildLdapSyntaxReferences()
853 {
854 for ( LdapSyntax syntax : ldapSyntaxRegistry )
855 {
856 buildReference( syntax );
857 }
858 }
859
860
861
862
863
864 private void buildSyntaxCheckerReferences()
865 {
866 for ( SyntaxChecker syntaxChecker : syntaxCheckerRegistry )
867 {
868 buildReference( syntaxChecker );
869 }
870 }
871
872
873
874
875
876 public void buildReferences()
877 {
878
879 buildComparatorReferences();
880
881
882 buildNormalizerReferences();
883
884
885 buildSyntaxCheckerReferences();
886
887
888 buildLdapSyntaxReferences();
889
890
891 buildMatchingRuleReferences();
892
893
894 buildAttributeTypeReferences();
895
896
897 buildMatchingRuleUseReferences();
898
899
900 buildObjectClassReferences();
901
902
903 buildDitContentRuleReferences();
904
905
906 buildNameFormReferences();
907
908
909 buildDitStructureRuleReferences();
910 }
911
912
913
914
915
916
917
918 private void resolve( LdapSyntax syntax )
919 {
920
921
922 try
923 {
924 LdapSyntaxHelper.addToRegistries( syntax, errorHandler, this );
925 }
926 catch ( LdapException e )
927 {
928 errorHandler.handle( LOG, e.getMessage(), e );
929 }
930 }
931
932
933
934
935
936
937
938 private void resolve( Normalizer normalizer )
939 {
940
941 }
942
943
944
945
946
947
948
949 private void resolve( LdapComparator<?> comparator )
950 {
951
952 }
953
954
955
956
957
958
959
960 private void resolve( SyntaxChecker syntaxChecker )
961 {
962
963 }
964
965
966
967
968
969
970
971
972 private void resolve( MatchingRule matchingRule )
973 {
974
975 String syntaxOid = matchingRule.getSyntaxOid();
976
977 if ( syntaxOid != null )
978 {
979
980 try
981 {
982 ldapSyntaxRegistry.lookup( syntaxOid );
983 }
984 catch ( LdapException ne )
985 {
986
987 LdapSchemaException ldapSchemaException = new LdapSchemaException(
988 LdapSchemaExceptionCodes.OID_ALREADY_REGISTERED, I18n.err( I18n.ERR_13748_MATCHING_RULE_NO_SYNTAX, matchingRule.getOid() ),
989 ne );
990 ldapSchemaException.setSourceObject( matchingRule );
991 errorHandler.handle( LOG, ldapSchemaException.getMessage(), ldapSchemaException );
992 }
993 }
994 else
995 {
996
997 LdapSchemaException ldapSchemaException = new LdapSchemaException(
998 LdapSchemaExceptionCodes.OID_ALREADY_REGISTERED, I18n.err( I18n.ERR_13748_MATCHING_RULE_NO_SYNTAX, matchingRule.getOid() ) );
999 ldapSchemaException.setSourceObject( matchingRule );
1000 errorHandler.handle( LOG, ldapSchemaException.getMessage(), ldapSchemaException );
1001 }
1002
1003
1004 Normalizer normalizer = matchingRule.getNormalizer();
1005
1006 if ( normalizer == null )
1007 {
1008
1009 LdapSchemaViolationException error = new LdapSchemaViolationException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err(
1010 I18n.ERR_13220_NO_NORMALIZER, matchingRule.getOid() ) );
1011 errorHandler.handle( LOG, error.getMessage(), error );
1012 }
1013
1014
1015 LdapComparator<?> comparator = matchingRule.getLdapComparator();
1016
1017 if ( comparator == null )
1018 {
1019
1020 LdapSchemaViolationException error = new LdapSchemaViolationException(
1021 ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX,
1022 I18n.err( I18n.ERR_13863_MR_DOES_NOT_HAVE_A_COMP, matchingRule.getOid() ) );
1023 errorHandler.handle( LOG, error.getMessage(), error );
1024 }
1025 }
1026
1027
1028
1029
1030
1031
1032
1033
1034 private void resolveRecursive( AttributeType attributeType, Set<String> processed )
1035 {
1036
1037 String superiorOid = attributeType.getSuperiorOid();
1038
1039 AttributeType superior = null;
1040
1041 if ( superiorOid != null )
1042 {
1043
1044 try
1045 {
1046 superior = attributeTypeRegistry.lookup( superiorOid );
1047 }
1048 catch ( LdapException ne )
1049 {
1050
1051 if ( !processed.contains( superiorOid ) )
1052 {
1053 errorHandler.handle( LOG, ne.getMessage(), ne );
1054 }
1055 }
1056
1057
1058
1059 if ( superior != null )
1060 {
1061 if ( !processed.contains( superiorOid ) )
1062 {
1063 resolveRecursive( superior, processed );
1064 processed.add( attributeType.getOid() );
1065 }
1066 else
1067 {
1068
1069 LdapSchemaViolationException error = new LdapSchemaViolationException( ResultCodeEnum.OTHER,
1070 I18n.err( I18n.ERR_13749_AT_WITH_CYCLE, attributeType.getOid() ) );
1071 errorHandler.handle( LOG, error.getMessage(), error );
1072 return;
1073 }
1074 }
1075 }
1076
1077
1078
1079 String syntaxOid = attributeType.getSyntaxOid();
1080
1081 if ( syntaxOid != null )
1082 {
1083
1084 try
1085 {
1086 ldapSyntaxRegistry.lookup( syntaxOid );
1087 }
1088 catch ( LdapException ne )
1089 {
1090
1091 errorHandler.handle( LOG, ne.getMessage(), ne );
1092 }
1093 }
1094 else
1095 {
1096
1097 if ( superior == null )
1098 {
1099
1100
1101 LdapSchemaViolationException error = new LdapSchemaViolationException(
1102 ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX,
1103 I18n.err( I18n.ERR_13864_AT_DOES_NOT_HAVE_A_SUPERIOR_NOR_SYNTAX, attributeType.getOid() ) );
1104 errorHandler.handle( LOG, error.getMessage(), error );
1105 }
1106 }
1107
1108
1109
1110 String equalityOid = attributeType.getEqualityOid();
1111
1112 if ( equalityOid != null )
1113 {
1114
1115 try
1116 {
1117 matchingRuleRegistry.lookup( equalityOid );
1118 }
1119 catch ( LdapException ne )
1120 {
1121
1122 errorHandler.handle( LOG, ne.getMessage(), ne );
1123 }
1124 }
1125
1126
1127
1128 String orderingOid = attributeType.getOrderingOid();
1129
1130 if ( orderingOid != null )
1131 {
1132
1133 try
1134 {
1135 matchingRuleRegistry.lookup( orderingOid );
1136 }
1137 catch ( LdapException ne )
1138 {
1139
1140 errorHandler.handle( LOG, ne.getMessage(), ne );
1141 }
1142 }
1143
1144
1145
1146 String substringOid = attributeType.getSubstringOid();
1147
1148 if ( substringOid != null )
1149 {
1150
1151 try
1152 {
1153 matchingRuleRegistry.lookup( substringOid );
1154 }
1155 catch ( LdapException ne )
1156 {
1157
1158 errorHandler.handle( LOG, ne.getMessage(), ne );
1159 }
1160 }
1161 }
1162
1163
1164
1165
1166
1167
1168
1169
1170 private void resolve( AttributeType attributeType )
1171 {
1172
1173
1174
1175 Set<String> processed = new HashSet<>();
1176
1177
1178 processed.add( attributeType.getOid() );
1179
1180
1181 resolveRecursive( attributeType, processed );
1182 }
1183
1184
1185 private List<AttributeType> getMustRecursive( List<AttributeType> musts, Set<ObjectClass> processed,
1186 ObjectClass objectClass )
1187 {
1188 if ( objectClass != null )
1189 {
1190 if ( processed.contains( objectClass ) )
1191 {
1192
1193
1194 return null;
1195 }
1196
1197 processed.add( objectClass );
1198
1199 for ( AttributeType must : objectClass.getMustAttributeTypes() )
1200 {
1201 musts.add( must );
1202 }
1203
1204 for ( ObjectClass superior : objectClass.getSuperiors() )
1205 {
1206 getMustRecursive( musts, processed, superior );
1207 }
1208 }
1209
1210 return musts;
1211 }
1212
1213
1214 private void resolve( ObjectClass objectClass )
1215 {
1216
1217
1218
1219 Set<String> processed = new HashSet<>();
1220
1221
1222 processed.add( objectClass.getOid() );
1223
1224
1225 resolveRecursive( objectClass, processed );
1226
1227
1228
1229 List<AttributeType> musts = getMustRecursive( new ArrayList<AttributeType>(), new HashSet<ObjectClass>(),
1230 objectClass );
1231
1232 if ( musts != null )
1233 {
1234 for ( AttributeType may : objectClass.getMayAttributeTypes() )
1235 {
1236 if ( musts.contains( may ) )
1237 {
1238
1239 LdapSchemaException ldapSchemaException = new LdapSchemaException(
1240 LdapSchemaExceptionCodes.OC_DUPLICATE_AT_IN_MAY_AND_MUST );
1241 ldapSchemaException.setSourceObject( objectClass );
1242 ldapSchemaException.setOtherObject( may );
1243 errorHandler.handle( LOG, ldapSchemaException.getMessage(), ldapSchemaException );
1244 }
1245 }
1246 }
1247 }
1248
1249
1250 private void resolveRecursive( ObjectClass objectClass, Set<String> processed )
1251 {
1252
1253 List<String> superiorOids = objectClass.getSuperiorOids();
1254 ObjectClass superior = null;
1255
1256 for ( String superiorOid : superiorOids )
1257 {
1258
1259 try
1260 {
1261 superior = objectClassRegistry.lookup( superiorOid );
1262 }
1263 catch ( LdapException ne )
1264 {
1265
1266 if ( !processed.contains( superiorOid ) )
1267 {
1268 LdapSchemaException ldapSchemaException = new LdapSchemaException(
1269 LdapSchemaExceptionCodes.OC_NONEXISTENT_SUPERIOR, ne );
1270 ldapSchemaException.setSourceObject( objectClass );
1271 ldapSchemaException.setRelatedId( superiorOid );
1272 errorHandler.handle( LOG, ldapSchemaException.getMessage(), ldapSchemaException );
1273 }
1274 }
1275
1276
1277
1278 if ( superior != null )
1279 {
1280 if ( !processed.contains( superior.getOid() ) )
1281 {
1282 resolveRecursive( superior, processed );
1283 processed.add( objectClass.getOid() );
1284 }
1285 else
1286 {
1287
1288 LdapSchemaException ldapSchemaException = new LdapSchemaException(
1289 LdapSchemaExceptionCodes.OC_CYCLE_CLASS_HIERARCHY );
1290 ldapSchemaException.setSourceObject( objectClass );
1291 ldapSchemaException.setOtherObject( superior );
1292 errorHandler.handle( LOG, ldapSchemaException.getMessage(), ldapSchemaException );
1293 return;
1294 }
1295 }
1296 }
1297
1298
1299 for ( String mayOid : objectClass.getMayAttributeTypeOids() )
1300 {
1301
1302 try
1303 {
1304 attributeTypeRegistry.lookup( mayOid );
1305 }
1306 catch ( LdapException ne )
1307 {
1308
1309 errorHandler.handle( LOG, ne.getMessage(), ne );
1310 }
1311 }
1312
1313
1314 for ( String mustOid : objectClass.getMustAttributeTypeOids() )
1315 {
1316
1317 try
1318 {
1319 attributeTypeRegistry.lookup( mustOid );
1320 }
1321 catch ( LdapException ne )
1322 {
1323
1324 errorHandler.handle( LOG, ne.getMessage(), ne );
1325 }
1326 }
1327
1328
1329 ObjectClassHelper.addToRegistries( objectClass, errorHandler, this );
1330 }
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340 public void add( SchemaObject schemaObject, boolean check ) throws LdapException
1341 {
1342
1343 boolean wasRelaxed = isRelaxed;
1344 setRelaxed();
1345
1346
1347 register( schemaObject );
1348
1349
1350 associateWithSchema( schemaObject );
1351
1352
1353 if ( check )
1354 {
1355 buildReference( schemaObject );
1356 }
1357
1358
1359 schemaObject.lock();
1360
1361 if ( check && ( !errorHandler.wasError() ) )
1362 {
1363
1364 checkRefInteg();
1365 }
1366
1367
1368 if ( !wasRelaxed )
1369 {
1370 setStrict();
1371 }
1372 }
1373
1374
1375
1376
1377
1378
1379
1380
1381 public void delete( SchemaObject schemaObject ) throws LdapException
1382 {
1383
1384 boolean wasRelaxed = isRelaxed;
1385 setRelaxed();
1386
1387
1388 SchemaObject removed = unregister( schemaObject );
1389
1390
1391 dissociateFromSchema( removed );
1392
1393
1394 removeReference( removed );
1395
1396 if ( !errorHandler.wasError() )
1397 {
1398
1399 checkRefInteg();
1400 }
1401
1402
1403 if ( !wasRelaxed )
1404 {
1405 setStrict();
1406 }
1407 }
1408
1409
1410
1411
1412
1413
1414
1415
1416 @Override
1417 public void schemaLoaded( Schema schema )
1418 {
1419 this.loadedSchemas.put( Strings.toLowerCaseAscii( schema.getSchemaName() ), schema );
1420 }
1421
1422
1423
1424
1425
1426
1427
1428
1429 @Override
1430 public void schemaUnloaded( Schema schema )
1431 {
1432 this.loadedSchemas.remove( Strings.toLowerCaseAscii( schema.getSchemaName() ) );
1433 }
1434
1435
1436
1437
1438
1439
1440
1441 public Map<String, Schema> getLoadedSchemas()
1442 {
1443 return Collections.unmodifiableMap( loadedSchemas );
1444 }
1445
1446
1447
1448
1449
1450
1451 public Map<String, Set<SchemaObjectWrapper>> getObjectBySchemaName()
1452 {
1453 return schemaObjects;
1454 }
1455
1456
1457
1458
1459
1460
1461
1462
1463 private String getSchemaName( SchemaObject schemaObject )
1464 {
1465 String schemaName = Strings.toLowerCaseAscii( schemaObject.getSchemaName() );
1466
1467 if ( loadedSchemas.containsKey( schemaName ) )
1468 {
1469 return schemaName;
1470 }
1471 else
1472 {
1473 return MetaSchemaConstants.SCHEMA_OTHER;
1474 }
1475 }
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485 public boolean contains( SchemaObject schemaObject )
1486 {
1487 String schemaName = schemaObject.getSchemaName();
1488
1489 Set<SchemaObjectWrapper> setSchemaObjects = schemaObjects.get( schemaName );
1490
1491 if ( ( setSchemaObjects == null ) || setSchemaObjects.isEmpty() )
1492 {
1493 return false;
1494 }
1495
1496 SchemaObjectWrapper wrapper = new SchemaObjectWrapper( schemaObject );
1497
1498 return setSchemaObjects.contains( wrapper );
1499 }
1500
1501
1502
1503
1504
1505
1506
1507
1508 public Set<SchemaObjectWrapper> addSchema( String schemaName )
1509 {
1510 Set<SchemaObjectWrapper> content = new HashSet<>();
1511 schemaObjects.put( schemaName, content );
1512
1513 return content;
1514 }
1515
1516
1517
1518
1519
1520
1521
1522
1523 private void register( SchemaObject schemaObject ) throws LdapException
1524 {
1525 if ( LOG.isDebugEnabled() )
1526 {
1527 LOG.debug( I18n.msg( I18n.MSG_13720_REGISTRING, schemaObject.getObjectType(), schemaObject.getOid() ) );
1528 }
1529
1530
1531 if ( !( schemaObject instanceof LoadableSchemaObject ) && globalOidRegistry.contains( schemaObject.getOid() ) )
1532 {
1533 String msg = I18n.err( I18n.ERR_13750_REGISTERING_FAILED_ALREADY_PRESENT, schemaObject.getObjectType(), schemaObject.getOid() );
1534 LOG.error( msg );
1535 LdapUnwillingToPerformException error = new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, msg );
1536 errorHandler.handle( LOG, msg, error );
1537 return;
1538 }
1539
1540 try
1541 {
1542
1543 switch ( schemaObject.getObjectType() )
1544 {
1545 case ATTRIBUTE_TYPE:
1546 attributeTypeRegistry.register( ( AttributeType ) schemaObject );
1547 break;
1548
1549 case COMPARATOR:
1550 comparatorRegistry.register( ( LdapComparator<?> ) schemaObject );
1551 break;
1552
1553 case DIT_CONTENT_RULE:
1554 ditContentRuleRegistry.register( ( DitContentRule ) schemaObject );
1555 break;
1556
1557 case DIT_STRUCTURE_RULE:
1558 ditStructureRuleRegistry.register( ( DitStructureRule ) schemaObject );
1559 break;
1560
1561 case LDAP_SYNTAX:
1562 ldapSyntaxRegistry.register( ( LdapSyntax ) schemaObject );
1563 break;
1564
1565 case MATCHING_RULE:
1566 matchingRuleRegistry.register( ( MatchingRule ) schemaObject );
1567 break;
1568
1569 case MATCHING_RULE_USE:
1570 matchingRuleUseRegistry.register( ( MatchingRuleUse ) schemaObject );
1571 break;
1572
1573 case NAME_FORM:
1574 nameFormRegistry.register( ( NameForm ) schemaObject );
1575 break;
1576
1577 case NORMALIZER:
1578 normalizerRegistry.register( ( Normalizer ) schemaObject );
1579 break;
1580
1581 case OBJECT_CLASS:
1582 objectClassRegistry.register( ( ObjectClass ) schemaObject );
1583 break;
1584
1585 case SYNTAX_CHECKER:
1586 syntaxCheckerRegistry.register( ( SyntaxChecker ) schemaObject );
1587 break;
1588
1589 default:
1590 throw new IllegalArgumentException(
1591 I18n.err( I18n.ERR_13718_UNEXPECTED_SCHEMA_OBJECT_TYPE, schemaObject.getObjectType() ) );
1592 }
1593 }
1594 catch ( Exception e )
1595 {
1596 errorHandler.handle( LOG, e.getMessage(), e );
1597 }
1598 }
1599
1600
1601
1602
1603
1604
1605
1606
1607 public void associateWithSchema( SchemaObject schemaObject )
1608 {
1609 if ( LOG.isDebugEnabled() )
1610 {
1611 LOG.debug( I18n.msg( I18n.MSG_13720_REGISTRING, schemaObject.getObjectType(), schemaObject.getOid() ) );
1612 }
1613
1614
1615 if ( !( schemaObject instanceof LoadableSchemaObject ) && globalOidRegistry.contains( schemaObject.getOid() ) )
1616 {
1617 String msg = I18n.err( I18n.ERR_13750_REGISTERING_FAILED_ALREADY_PRESENT, schemaObject.getObjectType(), schemaObject.getOid() );
1618 LOG.error( msg );
1619 LdapUnwillingToPerformException error = new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, msg );
1620 errorHandler.handle( LOG, msg, error );
1621 return;
1622 }
1623
1624
1625 String schemaName = getSchemaName( schemaObject );
1626
1627
1628 Set<SchemaObjectWrapper> content = schemaObjects.get( schemaName );
1629
1630 if ( content == null )
1631 {
1632 content = new HashSet<>();
1633 schemaObjects.put( Strings.toLowerCaseAscii( schemaName ), content );
1634 }
1635
1636 SchemaObjectWrapper schemaObjectWrapper = new SchemaObjectWrapper( schemaObject );
1637
1638 if ( content.contains( schemaObjectWrapper ) )
1639 {
1640
1641
1642 errorHandler.handle( LOG, I18n.msg( I18n.MSG_13719_REGISTRING_FAILED_ALREADY_PRESENT,
1643 schemaObject.getObjectType(), schemaObject.getOid() ), null );
1644 }
1645 else
1646 {
1647
1648 content.add( schemaObjectWrapper );
1649
1650
1651
1652 if ( !( schemaObject instanceof LoadableSchemaObject ) )
1653 {
1654 try
1655 {
1656 globalOidRegistry.register( schemaObject );
1657 }
1658 catch ( LdapException ne )
1659 {
1660 errorHandler.handle( LOG, ne.getMessage(), ne );
1661 return;
1662 }
1663 }
1664
1665 if ( LOG.isDebugEnabled() )
1666 {
1667 LOG.debug( I18n.msg( I18n.MSG_13731_REGISTRED_FOR_OID, schemaObject.getName(), schemaObject.getOid() ) );
1668 }
1669 }
1670 }
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681 public void dissociateFromSchema( SchemaObject schemaObject ) throws LdapException
1682 {
1683 if ( LOG.isDebugEnabled() )
1684 {
1685 LOG.debug( I18n.msg( I18n.MSG_13741_UNREGISTRING, schemaObject.getObjectType(), schemaObject.getOid() ) );
1686 }
1687
1688
1689 if ( !( schemaObject instanceof LoadableSchemaObject ) && !globalOidRegistry.contains( schemaObject.getOid() ) )
1690 {
1691 String msg = I18n.err( I18n.ERR_13751_UNREGISTERING_FAILED_NOT_PRESENT, schemaObject.getObjectType(), schemaObject.getOid() );
1692 LOG.error( msg );
1693 Throwable error = new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, msg );
1694 errorHandler.handle( LOG, msg, error );
1695 return;
1696 }
1697
1698
1699 String schemaName = getSchemaName( schemaObject );
1700 String oid = schemaObject.getOid();
1701
1702
1703 Set<SchemaObjectWrapper> content = schemaObjects.get( schemaName );
1704
1705 SchemaObjectWrapper schemaObjectWrapper = new SchemaObjectWrapper( schemaObject );
1706
1707 if ( !content.contains( schemaObjectWrapper ) )
1708 {
1709
1710
1711 if ( LOG.isInfoEnabled() )
1712 {
1713 LOG.info( I18n.msg( I18n.MSG_13739_UNREGISTERED_FAILED_NOT_PRESENT, schemaObject.getObjectType(),
1714 schemaObject.getOid() ) );
1715 }
1716 }
1717 else
1718 {
1719
1720 content.remove( schemaObjectWrapper );
1721
1722
1723
1724 if ( !( schemaObject instanceof LoadableSchemaObject ) )
1725 {
1726 try
1727 {
1728 globalOidRegistry.unregister( oid );
1729 }
1730 catch ( LdapException ne )
1731 {
1732 errorHandler.handle( LOG, ne.getMessage(), ne );
1733 return;
1734 }
1735 }
1736
1737 if ( LOG.isDebugEnabled() )
1738 {
1739 LOG.debug( I18n.msg( I18n.MSG_13737_UNREGISTERED_FOR_OID, schemaObject.getName(), schemaObject.getOid() ) );
1740 }
1741 }
1742 }
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752 private SchemaObject unregister( SchemaObject schemaObject ) throws LdapException
1753 {
1754 if ( LOG.isDebugEnabled() )
1755 {
1756 LOG.debug( I18n.msg( I18n.MSG_13741_UNREGISTRING, schemaObject.getObjectType(), schemaObject.getOid() ) );
1757 }
1758
1759
1760 if ( !( schemaObject instanceof LoadableSchemaObject ) && !globalOidRegistry.contains( schemaObject.getOid() ) )
1761 {
1762 String msg = I18n.err( I18n.ERR_13751_UNREGISTERING_FAILED_NOT_PRESENT, schemaObject.getObjectType(), schemaObject.getOid() );
1763 LOG.error( msg );
1764 throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, msg );
1765 }
1766
1767 SchemaObject unregistered;
1768
1769
1770 switch ( schemaObject.getObjectType() )
1771 {
1772 case ATTRIBUTE_TYPE:
1773 unregistered = attributeTypeRegistry.unregister( ( AttributeType ) schemaObject );
1774 break;
1775
1776 case COMPARATOR:
1777 unregistered = comparatorRegistry.unregister( ( LdapComparator<?> ) schemaObject );
1778 break;
1779
1780 case DIT_CONTENT_RULE:
1781 unregistered = ditContentRuleRegistry.unregister( ( DitContentRule ) schemaObject );
1782 break;
1783
1784 case DIT_STRUCTURE_RULE:
1785 unregistered = ditStructureRuleRegistry.unregister( ( DitStructureRule ) schemaObject );
1786 break;
1787
1788 case LDAP_SYNTAX:
1789 unregistered = ldapSyntaxRegistry.unregister( ( LdapSyntax ) schemaObject );
1790 break;
1791
1792 case MATCHING_RULE:
1793 unregistered = matchingRuleRegistry.unregister( ( MatchingRule ) schemaObject );
1794 break;
1795
1796 case MATCHING_RULE_USE:
1797 unregistered = matchingRuleUseRegistry.unregister( ( MatchingRuleUse ) schemaObject );
1798 break;
1799
1800 case NAME_FORM:
1801 unregistered = nameFormRegistry.unregister( ( NameForm ) schemaObject );
1802 break;
1803
1804 case NORMALIZER:
1805 unregistered = normalizerRegistry.unregister( ( Normalizer ) schemaObject );
1806 break;
1807
1808 case OBJECT_CLASS:
1809 unregistered = objectClassRegistry.unregister( ( ObjectClass ) schemaObject );
1810 break;
1811
1812 case SYNTAX_CHECKER:
1813 unregistered = syntaxCheckerRegistry.unregister( ( SyntaxChecker ) schemaObject );
1814 break;
1815
1816 default:
1817 throw new IllegalArgumentException(
1818 I18n.err( I18n.ERR_13718_UNEXPECTED_SCHEMA_OBJECT_TYPE, schemaObject.getObjectType() ) );
1819 }
1820
1821 return unregistered;
1822 }
1823
1824
1825
1826
1827
1828
1829
1830
1831 public boolean isReferenced( SchemaObject schemaObject )
1832 {
1833 SchemaObjectWrapper wrapper = new SchemaObjectWrapper( schemaObject );
1834
1835 Set<SchemaObjectWrapper> set = usedBy.get( wrapper );
1836
1837 boolean referenced = ( set != null ) && !set.isEmpty();
1838
1839 if ( LOG.isDebugEnabled() )
1840 {
1841 if ( referenced )
1842 {
1843 LOG.debug( I18n.msg( I18n.MSG_13735_REFERENCED, schemaObject.getObjectType(), schemaObject.getOid() ) );
1844 }
1845 else
1846 {
1847 LOG.debug( I18n.msg( I18n.MSG_13734_NOT_REFERENCED, schemaObject.getObjectType(), schemaObject.getOid() ) );
1848 }
1849 }
1850
1851 return referenced;
1852 }
1853
1854
1855
1856
1857
1858
1859
1860
1861 public Set<SchemaObjectWrapper> getUsedBy( SchemaObject schemaObject )
1862 {
1863 SchemaObjectWrapper wrapper = new SchemaObjectWrapper( schemaObject );
1864
1865 return usedBy.get( wrapper );
1866 }
1867
1868
1869
1870
1871
1872
1873
1874 public String dumpUsedBy()
1875 {
1876 StringBuilder sb = new StringBuilder();
1877
1878 sb.append( "USED BY :\n" );
1879
1880 try
1881 {
1882 for ( Map.Entry<SchemaObjectWrapper, Set<SchemaObjectWrapper>> entry : usedBy.entrySet() )
1883 {
1884 SchemaObjectWrapper wrapper = entry.getKey();
1885
1886 sb.append( wrapper.get().getObjectType() ).append( '[' ).append( wrapper.get().getOid() )
1887 .append( "] : {" );
1888
1889 boolean isFirst = true;
1890
1891 for ( SchemaObjectWrapper uses : entry.getValue() )
1892 {
1893 if ( isFirst )
1894 {
1895 isFirst = false;
1896 }
1897 else
1898 {
1899 sb.append( ", " );
1900 }
1901
1902 sb.append( uses.get().getObjectType() ).append( '[' ).append( wrapper.get().getOid() ).append( "]" );
1903 }
1904
1905 sb.append( "}\n" );
1906 }
1907 }
1908 catch ( Exception e )
1909 {
1910 e.printStackTrace();
1911 }
1912
1913 return sb.toString();
1914 }
1915
1916
1917
1918
1919
1920
1921
1922 public String dumpUsing()
1923 {
1924 StringBuilder sb = new StringBuilder();
1925
1926 sb.append( "USING :\n" );
1927
1928 try
1929 {
1930 for ( Map.Entry<SchemaObjectWrapper, Set<SchemaObjectWrapper>> entry : using.entrySet() )
1931 {
1932 SchemaObjectWrapper wrapper = entry.getKey();
1933
1934 sb.append( wrapper.get().getObjectType() ).append( '[' ).append( wrapper.get().getOid() )
1935 .append( "] : {" );
1936
1937 boolean isFirst = true;
1938
1939 for ( SchemaObjectWrapper uses : entry.getValue() )
1940 {
1941 if ( isFirst )
1942 {
1943 isFirst = false;
1944 }
1945 else
1946 {
1947 sb.append( ", " );
1948 }
1949
1950 sb.append( uses.get().getObjectType() ).append( '[' ).append( wrapper.get().getOid() ).append( "]" );
1951 }
1952
1953 sb.append( "}\n" );
1954 }
1955 }
1956 catch ( Exception e )
1957 {
1958 e.printStackTrace();
1959 }
1960
1961 return sb.toString();
1962 }
1963
1964
1965
1966
1967
1968
1969
1970
1971 public Set<SchemaObjectWrapper> getUsing( SchemaObject schemaObject )
1972 {
1973 SchemaObjectWrapper wrapper = new SchemaObjectWrapper( schemaObject );
1974
1975 return using.get( wrapper );
1976 }
1977
1978
1979
1980
1981
1982
1983
1984
1985 private void addUsing( SchemaObject reference, SchemaObject referee )
1986 {
1987 if ( ( reference == null ) || ( referee == null ) )
1988 {
1989 return;
1990 }
1991
1992 SchemaObjectWrapper wrapper = new SchemaObjectWrapper( reference );
1993
1994 Set<SchemaObjectWrapper> uses = getUsing( reference );
1995
1996 if ( uses == null )
1997 {
1998 uses = new HashSet<>();
1999 }
2000
2001 uses.add( new SchemaObjectWrapper( referee ) );
2002
2003
2004 using.put( wrapper, uses );
2005 }
2006
2007
2008
2009
2010
2011
2012
2013
2014 public void addReference( SchemaObject base, SchemaObject referenced )
2015 {
2016 if ( LOG.isDebugEnabled() )
2017 {
2018 LOG.debug( dump( "add", base, referenced ) );
2019 }
2020
2021 addUsing( base, referenced );
2022 addUsedBy( referenced, base );
2023
2024
2025
2026 if ( LOG.isTraceEnabled() )
2027 {
2028 LOG.trace( dumpUsedBy() );
2029 LOG.trace( dumpUsing() );
2030 }
2031 }
2032
2033
2034
2035
2036
2037
2038
2039
2040 private void addUsedBy( SchemaObject referee, SchemaObject reference )
2041 {
2042 if ( ( reference == null ) || ( referee == null ) )
2043 {
2044 return;
2045 }
2046
2047 SchemaObjectWrapper wrapper = new SchemaObjectWrapper( referee );
2048
2049 Set<SchemaObjectWrapper> uses = getUsedBy( referee );
2050
2051 if ( uses == null )
2052 {
2053 uses = new HashSet<>();
2054 }
2055
2056 uses.add( new SchemaObjectWrapper( reference ) );
2057
2058
2059 usedBy.put( wrapper, uses );
2060 }
2061
2062
2063
2064
2065
2066
2067
2068
2069 private void delUsing( SchemaObject reference, SchemaObject referee )
2070 {
2071 if ( ( reference == null ) || ( referee == null ) )
2072 {
2073 return;
2074 }
2075
2076 Set<SchemaObjectWrapper> uses = getUsing( reference );
2077
2078 if ( uses == null )
2079 {
2080 return;
2081 }
2082
2083 uses.remove( new SchemaObjectWrapper( referee ) );
2084
2085 SchemaObjectWrapper wrapper = new SchemaObjectWrapper( reference );
2086
2087 if ( uses.isEmpty() )
2088 {
2089 using.remove( wrapper );
2090 }
2091 else
2092 {
2093 using.put( wrapper, uses );
2094 }
2095 }
2096
2097
2098
2099
2100
2101
2102
2103
2104 private void delUsedBy( SchemaObject referee, SchemaObject reference )
2105 {
2106 if ( ( reference == null ) || ( referee == null ) )
2107 {
2108 return;
2109 }
2110
2111 Set<SchemaObjectWrapper> uses = getUsedBy( referee );
2112
2113 if ( uses == null )
2114 {
2115 return;
2116 }
2117
2118 uses.remove( new SchemaObjectWrapper( reference ) );
2119
2120 SchemaObjectWrapper wrapper = new SchemaObjectWrapper( referee );
2121
2122 if ( uses.isEmpty() )
2123 {
2124 usedBy.remove( wrapper );
2125 }
2126 else
2127 {
2128 usedBy.put( wrapper, uses );
2129 }
2130 }
2131
2132
2133
2134
2135
2136
2137
2138
2139 public void delReference( SchemaObject base, SchemaObject referenced )
2140 {
2141 if ( LOG.isDebugEnabled() )
2142 {
2143 LOG.debug( dump( "del", base, referenced ) );
2144 }
2145
2146 delUsing( base, referenced );
2147 delUsedBy( referenced, base );
2148
2149 if ( LOG.isDebugEnabled() )
2150 {
2151 LOG.debug( dumpUsedBy() );
2152 LOG.debug( dumpUsing() );
2153 }
2154 }
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165 private String dump( String op, SchemaObject reference, SchemaObject referee )
2166 {
2167 return op + " : " + reference.getObjectType() + "[" + reference.getOid() + "]/[" + referee.getObjectType()
2168 + "[" + referee.getOid() + "]";
2169 }
2170
2171
2172 private boolean checkReferences( SchemaObject reference, SchemaObject referee, String message )
2173 {
2174 SchemaObjectWrapper referenceWrapper = new SchemaObjectWrapper( reference );
2175 SchemaObjectWrapper refereeWrapper = new SchemaObjectWrapper( referee );
2176
2177
2178 if ( !using.containsKey( referenceWrapper ) )
2179 {
2180 if ( LOG.isDebugEnabled() )
2181 {
2182 LOG.debug(
2183 I18n.msg( I18n.MSG_13730_SYN_DOES_NOT_REFERENCE, reference.getObjectType(), reference.getOid(), message ) );
2184 }
2185
2186 return false;
2187 }
2188
2189 Set<SchemaObjectWrapper> usings = using.get( referenceWrapper );
2190
2191 if ( !usings.contains( refereeWrapper ) )
2192 {
2193 if ( LOG.isDebugEnabled() )
2194 {
2195 LOG.debug( I18n.msg( I18n.MSG_13732_NOT_REFERENCE_ANY, reference.getObjectType(), reference.getOid(), message ) );
2196 }
2197
2198 return false;
2199 }
2200
2201
2202 if ( !usedBy.containsKey( refereeWrapper ) )
2203 {
2204 if ( LOG.isDebugEnabled() )
2205 {
2206 LOG.debug( I18n.msg( I18n.MSG_13733_NOT_REFERENCED_BY_ANY, referee.getObjectType(), referee.getOid(), message ) );
2207 }
2208
2209 return false;
2210 }
2211
2212 Set<SchemaObjectWrapper> used = usedBy.get( refereeWrapper );
2213
2214 if ( !used.contains( referenceWrapper ) )
2215 {
2216 if ( LOG.isDebugEnabled() )
2217 {
2218 LOG.debug( I18n.msg( I18n.MSG_13733_NOT_REFERENCED_BY_ANY, referee.getObjectType(), referee.getOid(), message ) );
2219 }
2220
2221 return false;
2222 }
2223
2224 return true;
2225 }
2226
2227
2228
2229
2230
2231
2232
2233 public boolean check()
2234 {
2235
2236 if ( LOG.isDebugEnabled() )
2237 {
2238 LOG.debug( I18n.msg( I18n.MSG_13717_CHECKING_SYNTAXES ) );
2239 }
2240
2241 for ( LdapSyntax syntax : ldapSyntaxRegistry )
2242 {
2243
2244 if ( syntax.getSyntaxChecker() == null )
2245 {
2246 if ( LOG.isDebugEnabled() )
2247 {
2248 LOG.debug( I18n.msg( I18n.MSG_13729_SYN_WITH_NO_SYNTAX_CHECKER, syntax ) );
2249 }
2250
2251 return false;
2252 }
2253
2254 if ( !syntaxCheckerRegistry.contains( syntax.getSyntaxChecker().getOid() ) )
2255 {
2256 if ( LOG.isDebugEnabled() )
2257 {
2258 LOG.debug( I18n.msg( I18n.MSG_13713_CANT_FIND_SC_FOR_SYN, syntax.getSyntaxChecker().getOid(),
2259 syntax ) );
2260 }
2261
2262 return false;
2263 }
2264
2265
2266 if ( !checkReferences( syntax, syntax.getSyntaxChecker(), "SyntaxChecker" ) )
2267 {
2268 return false;
2269 }
2270 }
2271
2272
2273 if ( LOG.isDebugEnabled() )
2274 {
2275 LOG.debug( I18n.msg( I18n.MSG_13715_CHECKING_MATCHING_RULES ) );
2276 }
2277
2278 for ( MatchingRule matchingRule : matchingRuleRegistry )
2279 {
2280
2281 if ( matchingRule.getNormalizer() == null )
2282 {
2283 if ( LOG.isDebugEnabled() )
2284 {
2285 LOG.debug( I18n.msg( I18n.MSG_13727_MR_WITH_NO_NORMALIZER, matchingRule ) );
2286 }
2287
2288 return false;
2289 }
2290
2291
2292 if ( !normalizerRegistry.contains( matchingRule.getNormalizer().getOid() ) )
2293 {
2294 if ( LOG.isDebugEnabled() )
2295 {
2296 LOG.debug( I18n.msg( I18n.MSG_13709_CANT_FIND_NORM_FOR_MR, matchingRule.getNormalizer()
2297 .getOid(), matchingRule ) );
2298 }
2299
2300 return false;
2301 }
2302
2303
2304 if ( matchingRule.getLdapComparator() == null )
2305 {
2306 if ( LOG.isDebugEnabled() )
2307 {
2308 LOG.debug( I18n.msg( I18n.MSG_13726_MR_WITH_NO_COMPARATOR, matchingRule ) );
2309 }
2310
2311 return false;
2312 }
2313
2314 if ( !comparatorRegistry.contains( matchingRule.getLdapComparator().getOid() ) )
2315 {
2316 if ( LOG.isDebugEnabled() )
2317 {
2318 LOG.debug( I18n.msg( I18n.MSG_13707_CANT_FIND_AT_FOR_MR, matchingRule.getLdapComparator().getOid(),
2319 matchingRule ) );
2320 }
2321
2322 return false;
2323 }
2324
2325
2326 if ( matchingRule.getSyntax() == null )
2327 {
2328 if ( LOG.isDebugEnabled() )
2329 {
2330 LOG.debug( I18n.msg( I18n.MSG_13728_MR_WITH_NO_SYNTAX, matchingRule ) );
2331 }
2332
2333 return false;
2334 }
2335
2336 if ( !ldapSyntaxRegistry.contains( matchingRule.getSyntax().getOid() ) )
2337 {
2338 if ( LOG.isDebugEnabled() )
2339 {
2340 LOG.debug( I18n.msg( I18n.MSG_13712_CANT_FIND_SYN_FOR_MR, matchingRule.getSyntax().getOid(),
2341 matchingRule ) );
2342 }
2343
2344 return false;
2345 }
2346
2347
2348 if ( !checkReferences( matchingRule, matchingRule.getSyntax(), "Syntax" ) )
2349 {
2350 return false;
2351 }
2352
2353
2354 if ( !checkReferences( matchingRule, matchingRule.getNormalizer(), "Normalizer" ) )
2355 {
2356 return false;
2357 }
2358
2359
2360 if ( !checkReferences( matchingRule, matchingRule.getLdapComparator(), "Comparator" ) )
2361 {
2362 return false;
2363 }
2364 }
2365
2366
2367 if ( LOG.isDebugEnabled() )
2368 {
2369 LOG.debug( I18n.msg( I18n.MSG_13716_CHECKING_OBJECT_CLASSES ) );
2370 }
2371
2372 for ( ObjectClass objectClass : objectClassRegistry )
2373 {
2374
2375 if ( objectClass.getMayAttributeTypes() != null )
2376 {
2377 for ( AttributeType may : objectClass.getMayAttributeTypes() )
2378 {
2379 if ( !attributeTypeRegistry.contains( may.getOid() ) )
2380 {
2381 if ( LOG.isDebugEnabled() )
2382 {
2383 LOG.debug( I18n.msg( I18n.MSG_13705_CANT_FIND_AT_IN_MAY, may, objectClass ) );
2384 }
2385
2386 return false;
2387 }
2388
2389
2390 if ( !checkReferences( objectClass, may, "AttributeType" ) )
2391 {
2392 return false;
2393 }
2394 }
2395 }
2396
2397
2398 if ( objectClass.getMustAttributeTypes() != null )
2399 {
2400 for ( AttributeType must : objectClass.getMustAttributeTypes() )
2401 {
2402 if ( !attributeTypeRegistry.contains( must.getOid() ) )
2403 {
2404 if ( LOG.isDebugEnabled() )
2405 {
2406 LOG.debug( I18n.msg( I18n.MSG_13706_CANT_FIND_AT_IN_MUST, must, objectClass ) );
2407 }
2408
2409 return false;
2410 }
2411
2412
2413 if ( !checkReferences( objectClass, must, "AttributeType" ) )
2414 {
2415 return false;
2416 }
2417 }
2418 }
2419
2420
2421 if ( objectClass.getSuperiors() != null )
2422 {
2423 for ( ObjectClass superior : objectClass.getSuperiors() )
2424 {
2425 if ( !objectClassRegistry.contains( objectClass.getOid() ) )
2426 {
2427 if ( LOG.isDebugEnabled() )
2428 {
2429 LOG.debug( I18n.msg( I18n.MSG_13710_CANT_FIND_OC_WITH_SUPERIOR, superior, objectClass ) );
2430 }
2431
2432 return false;
2433 }
2434
2435
2436 if ( !checkReferences( objectClass, superior, "ObjectClass" ) )
2437 {
2438 return false;
2439 }
2440 }
2441 }
2442 }
2443
2444
2445 if ( LOG.isDebugEnabled() )
2446 {
2447 LOG.debug( I18n.msg( I18n.MSG_13714_CHECKING_ATTRIBUTE_TYPES ) );
2448 }
2449
2450 for ( AttributeType attributeType : attributeTypeRegistry )
2451 {
2452
2453 if ( attributeType.getSyntax() == null )
2454 {
2455 if ( LOG.isDebugEnabled() )
2456 {
2457 LOG.debug( I18n.msg( I18n.MSG_13725_AT_WITH_NO_SYNTAX, attributeType ) );
2458 }
2459
2460 return false;
2461 }
2462
2463 if ( !ldapSyntaxRegistry.contains( attributeType.getSyntax().getOid() ) )
2464 {
2465 if ( LOG.isDebugEnabled() )
2466 {
2467 LOG.debug( I18n.msg( I18n.MSG_13711_CANT_FIND_SYN_FOR_AT, attributeType.getSyntax().getOid(),
2468 attributeType ) );
2469 }
2470
2471 return false;
2472 }
2473
2474
2475 if ( !checkReferences( attributeType, attributeType.getSyntax(), "AttributeType" ) )
2476 {
2477 return false;
2478 }
2479
2480
2481 if ( attributeType.getEquality() != null )
2482 {
2483 if ( !matchingRuleRegistry.contains( attributeType.getEquality().getOid() ) )
2484 {
2485 if ( LOG.isDebugEnabled() )
2486 {
2487 LOG.debug( I18n.msg( I18n.MSG_13708_CANT_FIND_MR_FOR_AT, attributeType.getEquality()
2488 .getOid(), attributeType ) );
2489 }
2490
2491 return false;
2492 }
2493
2494
2495 if ( !checkReferences( attributeType, attributeType.getEquality(), "AttributeType" ) )
2496 {
2497 return false;
2498 }
2499 }
2500
2501
2502 if ( attributeType.getOrdering() != null )
2503 {
2504 if ( !matchingRuleRegistry.contains( attributeType.getOrdering().getOid() ) )
2505 {
2506 if ( LOG.isDebugEnabled() )
2507 {
2508 LOG.debug( I18n.msg( I18n.MSG_13708_CANT_FIND_MR_FOR_AT, attributeType.getOrdering()
2509 .getOid(), attributeType ) );
2510 }
2511
2512 return false;
2513 }
2514
2515
2516 if ( !checkReferences( attributeType, attributeType.getOrdering(), "AttributeType" ) )
2517 {
2518 return false;
2519 }
2520 }
2521
2522
2523 if ( attributeType.getSubstring() != null )
2524 {
2525 if ( !matchingRuleRegistry.contains( attributeType.getSubstring().getOid() ) )
2526 {
2527 if ( LOG.isDebugEnabled() )
2528 {
2529 LOG.debug( I18n.msg( I18n.MSG_13708_CANT_FIND_MR_FOR_AT, attributeType.getSubstring()
2530 .getOid(), attributeType ) );
2531 }
2532
2533 return false;
2534 }
2535
2536
2537 if ( !checkReferences( attributeType, attributeType.getSubstring(), "AttributeType" ) )
2538 {
2539 return false;
2540 }
2541 }
2542
2543
2544 if ( attributeType.getSuperior() != null )
2545 {
2546 AttributeType superior = attributeType.getSuperior();
2547
2548 if ( !attributeTypeRegistry.contains( superior.getOid() ) )
2549 {
2550 if ( LOG.isDebugEnabled() )
2551 {
2552 LOG.debug( I18n.msg( I18n.MSG_13704_CANT_FIND_AT_WITH_SUPERIOR, superior, attributeType ) );
2553 }
2554
2555 return false;
2556 }
2557
2558
2559 if ( !checkReferences( attributeType, superior, "AttributeType" ) )
2560 {
2561 return false;
2562 }
2563 }
2564 }
2565
2566 return true;
2567 }
2568
2569
2570
2571
2572
2573
2574
2575
2576 @Override
2577 public Registries clone() throws CloneNotSupportedException
2578 {
2579
2580 Registries clone = ( Registries ) super.clone();
2581
2582
2583 clone.globalOidRegistry = globalOidRegistry.copy();
2584
2585
2586 clone.attributeTypeRegistry = attributeTypeRegistry.copy();
2587 clone.comparatorRegistry = comparatorRegistry.copy();
2588 clone.ditContentRuleRegistry = ditContentRuleRegistry.copy();
2589 clone.ditStructureRuleRegistry = ditStructureRuleRegistry.copy();
2590 clone.ldapSyntaxRegistry = ldapSyntaxRegistry.copy();
2591 clone.matchingRuleRegistry = matchingRuleRegistry.copy();
2592 clone.matchingRuleUseRegistry = matchingRuleUseRegistry.copy();
2593 clone.nameFormRegistry = nameFormRegistry.copy();
2594 clone.normalizerRegistry = normalizerRegistry.copy();
2595 clone.objectClassRegistry = objectClassRegistry.copy();
2596 clone.syntaxCheckerRegistry = syntaxCheckerRegistry.copy();
2597 clone.errorHandler = errorHandler;
2598
2599
2600 for ( AttributeType attributeType : clone.attributeTypeRegistry )
2601 {
2602 clone.globalOidRegistry.put( attributeType );
2603 }
2604
2605 for ( DitContentRule ditContentRule : clone.ditContentRuleRegistry )
2606 {
2607 clone.globalOidRegistry.put( ditContentRule );
2608 }
2609
2610 for ( DitStructureRule ditStructureRule : clone.ditStructureRuleRegistry )
2611 {
2612 clone.globalOidRegistry.put( ditStructureRule );
2613 }
2614
2615 for ( MatchingRule matchingRule : clone.matchingRuleRegistry )
2616 {
2617 clone.globalOidRegistry.put( matchingRule );
2618 }
2619
2620 for ( MatchingRuleUse matchingRuleUse : clone.matchingRuleUseRegistry )
2621 {
2622 clone.globalOidRegistry.put( matchingRuleUse );
2623 }
2624
2625 for ( NameForm nameForm : clone.nameFormRegistry )
2626 {
2627 clone.globalOidRegistry.put( nameForm );
2628 }
2629
2630 for ( ObjectClass objectClass : clone.objectClassRegistry )
2631 {
2632 clone.globalOidRegistry.put( objectClass );
2633 }
2634
2635 for ( LdapSyntax syntax : clone.ldapSyntaxRegistry )
2636 {
2637 clone.globalOidRegistry.put( syntax );
2638 }
2639
2640
2641 clone.loadedSchemas = new HashMap<>();
2642
2643 for ( Map.Entry<String, Set<SchemaObjectWrapper>> entry : schemaObjects.entrySet() )
2644 {
2645
2646 clone.loadedSchemas.put( entry.getKey(), loadedSchemas.get( entry.getKey() ) );
2647 }
2648
2649
2650
2651 clone.using = new HashMap<>();
2652 clone.usedBy = new HashMap<>();
2653
2654
2655 clone.buildReferences();
2656
2657
2658 clone.checkRefInteg();
2659
2660 clone.schemaObjects = new HashMap<>();
2661
2662
2663
2664 for ( Map.Entry<String, Set<SchemaObjectWrapper>> entry : schemaObjects.entrySet() )
2665 {
2666 Set<SchemaObjectWrapper> objects = new HashSet<>();
2667
2668 for ( SchemaObjectWrapper schemaObjectWrapper : entry.getValue() )
2669 {
2670 SchemaObject original = schemaObjectWrapper.get();
2671
2672 try
2673 {
2674 if ( !( original instanceof LoadableSchemaObject ) )
2675 {
2676 SchemaObject copy = clone.globalOidRegistry.getSchemaObject( original.getOid() );
2677 SchemaObjectWrapper newWrapper = new SchemaObjectWrapper( copy );
2678 objects.add( newWrapper );
2679 }
2680 else
2681 {
2682 SchemaObjectWrapper newWrapper = new SchemaObjectWrapper( original );
2683 objects.add( newWrapper );
2684 }
2685 }
2686 catch ( LdapException ne )
2687 {
2688
2689 }
2690 }
2691
2692 clone.schemaObjects.put( entry.getKey(), objects );
2693 }
2694
2695 return clone;
2696 }
2697
2698
2699
2700
2701
2702
2703
2704
2705 public boolean isRelaxed()
2706 {
2707 return isRelaxed;
2708 }
2709
2710
2711
2712
2713
2714
2715
2716 public boolean isStrict()
2717 {
2718 return !isRelaxed;
2719 }
2720
2721
2722
2723
2724
2725
2726 public void setRelaxed()
2727 {
2728 isRelaxed = RELAXED;
2729 globalOidRegistry.setRelaxed();
2730 attributeTypeRegistry.setRelaxed();
2731 comparatorRegistry.setRelaxed();
2732 ditContentRuleRegistry.setRelaxed();
2733 ditStructureRuleRegistry.setRelaxed();
2734 ldapSyntaxRegistry.setRelaxed();
2735 matchingRuleRegistry.setRelaxed();
2736 matchingRuleUseRegistry.setRelaxed();
2737 nameFormRegistry.setRelaxed();
2738 normalizerRegistry.setRelaxed();
2739 objectClassRegistry.setRelaxed();
2740 syntaxCheckerRegistry.setRelaxed();
2741 }
2742
2743
2744
2745
2746
2747
2748 public void setStrict()
2749 {
2750 isRelaxed = STRICT;
2751 globalOidRegistry.setStrict();
2752 attributeTypeRegistry.setStrict();
2753 comparatorRegistry.setStrict();
2754 ditContentRuleRegistry.setStrict();
2755 ditStructureRuleRegistry.setStrict();
2756 ldapSyntaxRegistry.setStrict();
2757 matchingRuleRegistry.setStrict();
2758 matchingRuleUseRegistry.setStrict();
2759 nameFormRegistry.setStrict();
2760 normalizerRegistry.setStrict();
2761 objectClassRegistry.setStrict();
2762 syntaxCheckerRegistry.setStrict();
2763 }
2764
2765
2766 public SchemaErrorHandler getErrorHandler()
2767 {
2768 return errorHandler;
2769 }
2770
2771
2772 public void setErrorHandler( SchemaErrorHandler errorHandler )
2773 {
2774 this.errorHandler = errorHandler;
2775 globalOidRegistry.setErrorHandler( errorHandler );
2776 attributeTypeRegistry.setErrorHandler( errorHandler );
2777 comparatorRegistry.setErrorHandler( errorHandler );
2778 ditContentRuleRegistry.setErrorHandler( errorHandler );
2779 ditStructureRuleRegistry.setErrorHandler( errorHandler );
2780 ldapSyntaxRegistry.setErrorHandler( errorHandler );
2781 matchingRuleRegistry.setErrorHandler( errorHandler );
2782 matchingRuleUseRegistry.setErrorHandler( errorHandler );
2783 nameFormRegistry.setErrorHandler( errorHandler );
2784 normalizerRegistry.setErrorHandler( errorHandler );
2785 objectClassRegistry.setErrorHandler( errorHandler );
2786 syntaxCheckerRegistry.setErrorHandler( errorHandler );
2787 }
2788
2789
2790
2791
2792
2793
2794
2795 public boolean isDisabledAccepted()
2796 {
2797 return disabledAccepted;
2798 }
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808 public Set<SchemaObjectWrapper> getReferencing( SchemaObject schemaObject )
2809 {
2810 SchemaObjectWrapper schemaObjectWrapper = new SchemaObjectWrapper( schemaObject );
2811
2812 return usedBy.get( schemaObjectWrapper );
2813 }
2814
2815
2816
2817
2818
2819
2820
2821
2822 public void setDisabledAccepted( boolean disabledAccepted )
2823 {
2824 this.disabledAccepted = disabledAccepted;
2825 }
2826
2827
2828
2829
2830
2831
2832
2833 public void clear() throws LdapException
2834 {
2835
2836 if ( attributeTypeRegistry != null )
2837 {
2838 attributeTypeRegistry.clear();
2839 }
2840
2841
2842 if ( comparatorRegistry != null )
2843 {
2844 comparatorRegistry.clear();
2845 }
2846
2847
2848 if ( ditContentRuleRegistry != null )
2849 {
2850 ditContentRuleRegistry.clear();
2851 }
2852
2853
2854 if ( ditStructureRuleRegistry != null )
2855 {
2856 ditStructureRuleRegistry.clear();
2857 }
2858
2859
2860 if ( matchingRuleRegistry != null )
2861 {
2862 matchingRuleRegistry.clear();
2863 }
2864
2865
2866 if ( matchingRuleUseRegistry != null )
2867 {
2868 matchingRuleUseRegistry.clear();
2869 }
2870
2871
2872 if ( nameFormRegistry != null )
2873 {
2874 nameFormRegistry.clear();
2875 }
2876
2877
2878 if ( normalizerRegistry != null )
2879 {
2880 normalizerRegistry.clear();
2881 }
2882
2883
2884 if ( objectClassRegistry != null )
2885 {
2886 objectClassRegistry.clear();
2887 }
2888
2889
2890 if ( ldapSyntaxRegistry != null )
2891 {
2892 ldapSyntaxRegistry.clear();
2893 }
2894
2895
2896 if ( syntaxCheckerRegistry != null )
2897 {
2898 syntaxCheckerRegistry.clear();
2899 }
2900
2901
2902 for ( Map.Entry<String, Set<SchemaObjectWrapper>> entry : schemaObjects.entrySet() )
2903 {
2904 entry.getValue().clear();
2905 }
2906
2907 schemaObjects.clear();
2908
2909
2910 for ( Map.Entry<SchemaObjectWrapper, Set<SchemaObjectWrapper>> entry : usedBy.entrySet() )
2911 {
2912 entry.getValue().clear();
2913 }
2914
2915 usedBy.clear();
2916
2917
2918 for ( Map.Entry<SchemaObjectWrapper, Set<SchemaObjectWrapper>> entry : using.entrySet() )
2919 {
2920 entry.getValue().clear();
2921 }
2922
2923 using.clear();
2924
2925
2926 globalOidRegistry.clear();
2927
2928
2929 loadedSchemas.clear();
2930 }
2931
2932
2933
2934
2935
2936 @Override
2937 public String toString()
2938 {
2939 StringBuilder sb = new StringBuilder();
2940
2941 sb.append( "Registries [" );
2942
2943 if ( isRelaxed )
2944 {
2945 sb.append( "RELAXED," );
2946 }
2947 else
2948 {
2949 sb.append( "STRICT," );
2950 }
2951
2952 if ( disabledAccepted )
2953 {
2954 sb.append( " Disabled accepted] :\n" );
2955 }
2956 else
2957 {
2958 sb.append( " Disabled forbidden] :\n" );
2959 }
2960
2961 sb.append( "loaded schemas [" );
2962 boolean isFirst = true;
2963
2964 for ( String schema : loadedSchemas.keySet() )
2965 {
2966 if ( isFirst )
2967 {
2968 isFirst = false;
2969 }
2970 else
2971 {
2972 sb.append( ", " );
2973 }
2974
2975 sb.append( schema );
2976 }
2977
2978 sb.append( "]\n" );
2979
2980 sb.append( "AttributeTypes : " ).append( attributeTypeRegistry.size() ).append( "\n" );
2981 sb.append( "Comparators : " ).append( comparatorRegistry.size() ).append( "\n" );
2982 sb.append( "DitContentRules : " ).append( ditContentRuleRegistry.size() ).append( "\n" );
2983 sb.append( "DitStructureRules : " ).append( ditStructureRuleRegistry.size() ).append( "\n" );
2984 sb.append( "MatchingRules : " ).append( matchingRuleRegistry.size() ).append( "\n" );
2985 sb.append( "MatchingRuleUses : " ).append( matchingRuleUseRegistry.size() ).append( "\n" );
2986 sb.append( "NameForms : " ).append( nameFormRegistry.size() ).append( "\n" );
2987 sb.append( "Normalizers : " ).append( normalizerRegistry.size() ).append( "\n" );
2988 sb.append( "ObjectClasses : " ).append( objectClassRegistry.size() ).append( "\n" );
2989 sb.append( "Syntaxes : " ).append( ldapSyntaxRegistry.size() ).append( "\n" );
2990 sb.append( "SyntaxCheckers : " ).append( syntaxCheckerRegistry.size() ).append( "\n" );
2991
2992 sb.append( "GlobalOidRegistry : " ).append( globalOidRegistry.size() ).append( '\n' );
2993
2994 return sb.toString();
2995 }
2996 }