1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.directory.ldap.client.api;
22
23
24 import java.io.IOException;
25 import java.text.ParseException;
26 import java.util.ArrayList;
27 import java.util.List;
28 import java.util.Set;
29
30 import org.apache.directory.api.ldap.model.constants.MetaSchemaConstants;
31 import org.apache.directory.api.ldap.model.constants.SchemaConstants;
32 import org.apache.directory.api.ldap.model.entry.Attribute;
33 import org.apache.directory.api.ldap.model.entry.DefaultEntry;
34 import org.apache.directory.api.ldap.model.entry.Entry;
35 import org.apache.directory.api.ldap.model.entry.Value;
36 import org.apache.directory.api.ldap.model.exception.LdapException;
37 import org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException;
38 import org.apache.directory.api.ldap.model.name.Dn;
39 import org.apache.directory.api.ldap.model.schema.AttributeType;
40 import org.apache.directory.api.ldap.model.schema.AttributesFactory;
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.LdapSyntax;
44 import org.apache.directory.api.ldap.model.schema.MatchingRule;
45 import org.apache.directory.api.ldap.model.schema.MatchingRuleUse;
46 import org.apache.directory.api.ldap.model.schema.NameForm;
47 import org.apache.directory.api.ldap.model.schema.ObjectClass;
48 import org.apache.directory.api.ldap.model.schema.SchemaObject;
49 import org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper;
50 import org.apache.directory.api.ldap.model.schema.parsers.AttributeTypeDescriptionSchemaParser;
51 import org.apache.directory.api.ldap.model.schema.parsers.DitContentRuleDescriptionSchemaParser;
52 import org.apache.directory.api.ldap.model.schema.parsers.DitStructureRuleDescriptionSchemaParser;
53 import org.apache.directory.api.ldap.model.schema.parsers.LdapComparatorDescription;
54 import org.apache.directory.api.ldap.model.schema.parsers.LdapComparatorDescriptionSchemaParser;
55 import org.apache.directory.api.ldap.model.schema.parsers.LdapSyntaxDescriptionSchemaParser;
56 import org.apache.directory.api.ldap.model.schema.parsers.MatchingRuleDescriptionSchemaParser;
57 import org.apache.directory.api.ldap.model.schema.parsers.MatchingRuleUseDescriptionSchemaParser;
58 import org.apache.directory.api.ldap.model.schema.parsers.NameFormDescriptionSchemaParser;
59 import org.apache.directory.api.ldap.model.schema.parsers.NormalizerDescription;
60 import org.apache.directory.api.ldap.model.schema.parsers.NormalizerDescriptionSchemaParser;
61 import org.apache.directory.api.ldap.model.schema.parsers.ObjectClassDescriptionSchemaParser;
62 import org.apache.directory.api.ldap.model.schema.parsers.SyntaxCheckerDescription;
63 import org.apache.directory.api.ldap.model.schema.parsers.SyntaxCheckerDescriptionSchemaParser;
64 import org.apache.directory.api.ldap.model.schema.registries.AbstractSchemaLoader;
65 import org.apache.directory.api.ldap.model.schema.registries.DefaultSchema;
66 import org.apache.directory.api.ldap.model.schema.registries.Schema;
67 import org.apache.directory.api.util.Base64;
68 import org.apache.directory.api.util.Strings;
69 import org.apache.directory.ldap.client.api.exception.InvalidConnectionException;
70 import org.slf4j.Logger;
71 import org.slf4j.LoggerFactory;
72
73
74
75
76
77
78
79 public class DefaultSchemaLoader extends AbstractSchemaLoader
80 {
81 private static final String DEFAULT_APACHEDS_VENDOR_NAME = "Apache Software Foundation";
82
83
84 private static final Logger LOG = LoggerFactory.getLogger( DefaultSchemaLoader.class );
85
86
87 private LdapConnection connection;
88
89
90 private Dn subschemaSubentryDn;
91
92
93 private static AttributeTypeDescriptionSchemaParser AT_DESCR_SCHEMA_PARSER = new AttributeTypeDescriptionSchemaParser();
94 private static DitStructureRuleDescriptionSchemaParser DSR_DESCR_SCHEMA_PARSER = new DitStructureRuleDescriptionSchemaParser();
95 private static DitContentRuleDescriptionSchemaParser DCR_DESCR_SCHEMA_PARSER = new DitContentRuleDescriptionSchemaParser();
96 private static MatchingRuleDescriptionSchemaParser MR_DESCR_SCHEMA_PARSER = new MatchingRuleDescriptionSchemaParser();
97 private static MatchingRuleUseDescriptionSchemaParser MRU_DESCR_SCHEMA_PARSER = new MatchingRuleUseDescriptionSchemaParser();
98 private static NameFormDescriptionSchemaParser NF_DESCR_SCHEMA_PARSER = new NameFormDescriptionSchemaParser();
99 private static ObjectClassDescriptionSchemaParser OC_DESCR_SCHEMA_PARSER = new ObjectClassDescriptionSchemaParser();
100 private static LdapSyntaxDescriptionSchemaParser LS_DESCR_SCHEMA_PARSER = new LdapSyntaxDescriptionSchemaParser();
101
102 private static LdapComparatorDescriptionSchemaParser C_DESCR_SCHEMA_PARSER = new LdapComparatorDescriptionSchemaParser();
103 private static NormalizerDescriptionSchemaParser N_DESCR_SCHEMA_PARSER = new NormalizerDescriptionSchemaParser();
104 private static SyntaxCheckerDescriptionSchemaParser SC_DESCR_SCHEMA_PARSER = new SyntaxCheckerDescriptionSchemaParser();
105
106
107
108
109
110
111
112
113
114 public DefaultSchemaLoader( LdapConnection connection ) throws LdapException
115 {
116 if ( connection == null )
117 {
118 throw new InvalidConnectionException( "Cannot connect on the server, the connection is null" );
119 }
120
121 this.connection = connection;
122
123
124 boolean wasConnected = connection.isConnected();
125
126 try
127 {
128
129 if ( !wasConnected )
130 {
131 connection.connect();
132 }
133
134
135 Entry rootDse = connection.lookup( Dn.ROOT_DSE, SchemaConstants.SUBSCHEMA_SUBENTRY_AT,
136 SchemaConstants.VENDOR_NAME_AT );
137
138 if ( rootDse != null )
139 {
140
141 if ( isApacheDs( rootDse ) )
142 {
143
144 Attribute subschemaSubentryAttribute = rootDse.get( SchemaConstants.SUBSCHEMA_SUBENTRY_AT );
145
146 if ( ( subschemaSubentryAttribute != null ) && ( subschemaSubentryAttribute.size() > 0 ) )
147 {
148 subschemaSubentryDn = new Dn( connection.getSchemaManager(),
149 subschemaSubentryAttribute.getString() );
150
151 loadSchemas();
152 }
153 }
154 else
155 {
156
157 }
158 }
159 }
160 finally
161 {
162
163 if ( ( !wasConnected ) && ( connection.isConnected() ) )
164 {
165 try
166 {
167 connection.close();
168 }
169 catch ( IOException e )
170 {
171 throw new LdapException( e );
172 }
173 }
174 }
175 }
176
177
178
179
180
181
182
183
184
185
186 private boolean isApacheDs( Entry rootDse ) throws LdapInvalidAttributeValueException
187 {
188 if ( rootDse != null )
189 {
190 Attribute vendorNameAttribute = rootDse.get( SchemaConstants.VENDOR_NAME_AT );
191
192 if ( ( vendorNameAttribute != null ) && vendorNameAttribute.size() == 1 )
193 {
194 return DEFAULT_APACHEDS_VENDOR_NAME.equalsIgnoreCase( vendorNameAttribute.getString() );
195 }
196 }
197
198 return false;
199 }
200
201
202
203
204
205
206
207
208
209 public DefaultSchemaLoader( LdapConnection connection, Dn subschemaSubentryDn ) throws Exception
210 {
211 if ( !connection.isAuthenticated() )
212 {
213 throw new IllegalArgumentException( "connection is not authenticated" );
214 }
215
216 this.connection = connection;
217 this.subschemaSubentryDn = subschemaSubentryDn;
218
219 loadSchemas();
220 }
221
222
223
224
225
226
227
228
229 private void loadSchemas() throws LdapException
230 {
231 LOG.debug( "initializing schemas" );
232
233
234 Entry subschemaSubentry = connection.lookup( subschemaSubentryDn,
235 SchemaConstants.ATTRIBUTE_TYPES_AT,
236 SchemaConstants.COMPARATORS_AT,
237 SchemaConstants.DIT_CONTENT_RULES_AT,
238 SchemaConstants.DIT_STRUCTURE_RULES_AT,
239 SchemaConstants.LDAP_SYNTAXES_AT,
240 SchemaConstants.MATCHING_RULES_AT,
241 SchemaConstants.MATCHING_RULE_USE_AT,
242 SchemaConstants.NAME_FORMS_AT,
243 SchemaConstants.NORMALIZERS_AT,
244 SchemaConstants.OBJECT_CLASSES_AT,
245 SchemaConstants.SYNTAX_CHECKERS_AT
246 );
247
248
249 Attribute attributeTypes = subschemaSubentry.get( SchemaConstants.ATTRIBUTE_TYPES_AT );
250 loadAttributeTypes( attributeTypes );
251
252
253 Attribute comparators = subschemaSubentry.get( SchemaConstants.COMPARATORS_AT );
254 loadComparators( comparators );
255
256
257 Attribute ditContentRules = subschemaSubentry.get( SchemaConstants.DIT_CONTENT_RULES_AT );
258 loadDitContentRules( ditContentRules );
259
260
261 Attribute ditStructureRules = subschemaSubentry.get( SchemaConstants.DIT_STRUCTURE_RULES_AT );
262 loadDitStructureRules( ditStructureRules );
263
264
265 Attribute ldapSytaxes = subschemaSubentry.get( SchemaConstants.LDAP_SYNTAXES_AT );
266 loadLdapSyntaxes( ldapSytaxes );
267
268
269 Attribute matchingRules = subschemaSubentry.get( SchemaConstants.MATCHING_RULES_AT );
270 loadMatchingRules( matchingRules );
271
272
273 Attribute matchingRuleUse = subschemaSubentry.get( SchemaConstants.MATCHING_RULE_USE_AT );
274 loadMatchingRuleUses( matchingRuleUse );
275
276
277 Attribute normalizers = subschemaSubentry.get( SchemaConstants.NORMALIZERS_AT );
278 loadNormalizers( normalizers );
279
280
281 Attribute nameForms = subschemaSubentry.get( SchemaConstants.NAME_FORMS_AT );
282 loadNameForms( nameForms );
283
284
285 Attribute objectClasses = subschemaSubentry.get( SchemaConstants.OBJECT_CLASSES_AT );
286 loadObjectClasses( objectClasses );
287
288
289 Attribute syntaxCheckers = subschemaSubentry.get( SchemaConstants.SYNTAX_CHECKERS_AT );
290 loadSyntaxCheckers( syntaxCheckers );
291 }
292
293
294
295
296
297 private void loadAttributeTypes( Attribute attributeTypes ) throws LdapException
298 {
299 if ( attributeTypes == null )
300 {
301 return;
302 }
303
304 for ( Value<?> value : attributeTypes )
305 {
306 String desc = value.getString();
307
308 try
309 {
310 AttributeType attributeType = AT_DESCR_SCHEMA_PARSER.parseAttributeTypeDescription( desc );
311
312 updateSchemas( attributeType );
313 }
314 catch ( ParseException pe )
315 {
316 throw new LdapException( pe );
317 }
318 }
319 }
320
321
322
323
324
325 private void loadComparators( Attribute comparators ) throws LdapException
326 {
327 if ( comparators == null )
328 {
329 return;
330 }
331
332 for ( Value<?> value : comparators )
333 {
334 String desc = value.getString();
335
336 try
337 {
338 LdapComparatorDescription comparator = C_DESCR_SCHEMA_PARSER.parseComparatorDescription( desc );
339
340 updateSchemas( comparator );
341 }
342 catch ( ParseException pe )
343 {
344 throw new LdapException( pe );
345 }
346 }
347 }
348
349
350
351
352
353 private void loadDitContentRules( Attribute ditContentRules ) throws LdapException
354 {
355 if ( ditContentRules == null )
356 {
357 return;
358 }
359
360 for ( Value<?> value : ditContentRules )
361 {
362 String desc = value.getString();
363
364 try
365 {
366 DitContentRule ditContentRule = DCR_DESCR_SCHEMA_PARSER.parseDITContentRuleDescription( desc );
367
368 updateSchemas( ditContentRule );
369 }
370 catch ( ParseException pe )
371 {
372 throw new LdapException( pe );
373 }
374 }
375 }
376
377
378
379
380
381 private void loadDitStructureRules( Attribute ditStructureRules ) throws LdapException
382 {
383 if ( ditStructureRules == null )
384 {
385 return;
386 }
387
388 for ( Value<?> value : ditStructureRules )
389 {
390 String desc = value.getString();
391
392 try
393 {
394 DitStructureRule ditStructureRule = DSR_DESCR_SCHEMA_PARSER.parseDITStructureRuleDescription( desc );
395
396 updateSchemas( ditStructureRule );
397 }
398 catch ( ParseException pe )
399 {
400 throw new LdapException( pe );
401 }
402 }
403 }
404
405
406
407
408
409 private void loadLdapSyntaxes( Attribute ldapSyntaxes ) throws LdapException
410 {
411 if ( ldapSyntaxes == null )
412 {
413 return;
414 }
415
416 for ( Value<?> value : ldapSyntaxes )
417 {
418 String desc = value.getString();
419
420 try
421 {
422 LdapSyntax ldapSyntax = LS_DESCR_SCHEMA_PARSER.parseLdapSyntaxDescription( desc );
423
424 updateSchemas( ldapSyntax );
425 }
426 catch ( ParseException pe )
427 {
428 throw new LdapException( pe );
429 }
430 }
431 }
432
433
434
435
436
437 private void loadMatchingRules( Attribute matchingRules ) throws LdapException
438 {
439 if ( matchingRules == null )
440 {
441 return;
442 }
443
444 for ( Value<?> value : matchingRules )
445 {
446 String desc = value.getString();
447
448 try
449 {
450 MatchingRule matchingRule = MR_DESCR_SCHEMA_PARSER.parseMatchingRuleDescription( desc );
451
452 updateSchemas( matchingRule );
453 }
454 catch ( ParseException pe )
455 {
456 throw new LdapException( pe );
457 }
458 }
459 }
460
461
462
463
464
465 private void loadMatchingRuleUses( Attribute matchingRuleUses ) throws LdapException
466 {
467 if ( matchingRuleUses == null )
468 {
469 return;
470 }
471
472 for ( Value<?> value : matchingRuleUses )
473 {
474 String desc = value.getString();
475
476 try
477 {
478 MatchingRuleUse matchingRuleUse = MRU_DESCR_SCHEMA_PARSER.parseMatchingRuleUseDescription( desc );
479
480 updateSchemas( matchingRuleUse );
481 }
482 catch ( ParseException pe )
483 {
484 throw new LdapException( pe );
485 }
486 }
487 }
488
489
490
491
492
493 private void loadNameForms( Attribute nameForms ) throws LdapException
494 {
495 if ( nameForms == null )
496 {
497 return;
498 }
499
500 for ( Value<?> value : nameForms )
501 {
502 String desc = value.getString();
503
504 try
505 {
506 NameForm nameForm = NF_DESCR_SCHEMA_PARSER.parseNameFormDescription( desc );
507
508 updateSchemas( nameForm );
509 }
510 catch ( ParseException pe )
511 {
512 throw new LdapException( pe );
513 }
514 }
515 }
516
517
518
519
520
521 private void loadNormalizers( Attribute normalizers ) throws LdapException
522 {
523 if ( normalizers == null )
524 {
525 return;
526 }
527
528 for ( Value<?> value : normalizers )
529 {
530 String desc = value.getString();
531
532 try
533 {
534 NormalizerDescription normalizer = N_DESCR_SCHEMA_PARSER.parseNormalizerDescription( desc );
535
536 updateSchemas( normalizer );
537 }
538 catch ( ParseException pe )
539 {
540 throw new LdapException( pe );
541 }
542 }
543 }
544
545
546
547
548
549 private void loadObjectClasses( Attribute objectClasses ) throws LdapException
550 {
551 if ( objectClasses == null )
552 {
553 return;
554 }
555
556 for ( Value<?> value : objectClasses )
557 {
558 String desc = value.getString();
559
560 try
561 {
562 ObjectClass objectClass = OC_DESCR_SCHEMA_PARSER.parseObjectClassDescription( desc );
563
564 updateSchemas( objectClass );
565 }
566 catch ( ParseException pe )
567 {
568 throw new LdapException( pe );
569 }
570 }
571 }
572
573
574
575
576
577 private void loadSyntaxCheckers( Attribute syntaxCheckers ) throws LdapException
578 {
579 if ( syntaxCheckers == null )
580 {
581 return;
582 }
583
584 for ( Value<?> value : syntaxCheckers )
585 {
586 String desc = value.getString();
587
588 try
589 {
590 SyntaxCheckerDescription syntaxChecker = SC_DESCR_SCHEMA_PARSER.parseSyntaxCheckerDescription( desc );
591
592 updateSchemas( syntaxChecker );
593 }
594 catch ( ParseException pe )
595 {
596 throw new LdapException( pe );
597 }
598 }
599 }
600
601
602 private void updateSchemas( SchemaObject schemaObject )
603 {
604 String schemaName = schemaObject.getSchemaName();
605 Schema schema = null;
606
607 if ( Strings.isEmpty( schemaName ) || Strings.equals( "null", schemaName ) )
608 {
609 schemaName = "default";
610 schema = schemaMap.get( schemaName );
611 }
612 else
613 {
614 schema = schemaMap.get( schemaName );
615 }
616
617 if ( schema == null )
618 {
619 schema = new DefaultSchema( schemaName );
620
621 schemaMap.put( schemaName, schema );
622 }
623
624 schema.getContent().add( new SchemaObjectWrapper( schemaObject ) );
625
626 }
627
628
629
630
631
632 public List<Entry> loadAttributeTypes( Schema... schemas ) throws LdapException, IOException
633 {
634 List<Entry> attributeTypeEntries = new ArrayList<Entry>();
635
636 if ( schemas == null )
637 {
638 return attributeTypeEntries;
639 }
640
641 AttributesFactory factory = new AttributesFactory();
642
643 for ( Schema schema : schemas )
644 {
645 Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
646
647 for ( SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers )
648 {
649 SchemaObject schemaObject = schemaObjectWrapper.get();
650
651 if ( schemaObject instanceof AttributeType )
652 {
653 AttributeType attributeType = ( AttributeType ) schemaObject;
654
655 Entry attributeTypeEntry = factory.convert( attributeType, schema, null );
656
657 attributeTypeEntries.add( attributeTypeEntry );
658 }
659 }
660 }
661
662 return attributeTypeEntries;
663 }
664
665
666
667
668
669 public List<Entry> loadComparators( Schema... schemas ) throws LdapException, IOException
670 {
671 List<Entry> comparatorEntries = new ArrayList<Entry>();
672
673 if ( schemas == null )
674 {
675 return comparatorEntries;
676 }
677
678 for ( Schema schema : schemas )
679 {
680 Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
681
682 for ( SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers )
683 {
684 SchemaObject schemaObject = schemaObjectWrapper.get();
685
686 if ( schemaObject instanceof LdapComparatorDescription )
687 {
688 LdapComparatorDescription ldapComparatorDescription = ( LdapComparatorDescription ) schemaObject;
689 Entry lcEntry = getEntry( ldapComparatorDescription );
690
691 comparatorEntries.add( lcEntry );
692 }
693 }
694 }
695
696 return comparatorEntries;
697 }
698
699
700
701
702
703 public List<Entry> loadDitContentRules( Schema... schemas ) throws LdapException, IOException
704 {
705 List<Entry> ditContentRuleEntries = new ArrayList<Entry>();
706
707 if ( schemas == null )
708 {
709 return ditContentRuleEntries;
710 }
711
712 AttributesFactory factory = new AttributesFactory();
713
714 for ( Schema schema : schemas )
715 {
716 Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
717
718 for ( SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers )
719 {
720 SchemaObject schemaObject = schemaObjectWrapper.get();
721
722 if ( schemaObject instanceof DitContentRule )
723 {
724 DitContentRule ditContentRule = ( DitContentRule ) schemaObject;
725
726 Entry ditContentRuleEntry = factory.convert( ditContentRule, schema, null );
727
728 ditContentRuleEntries.add( ditContentRuleEntry );
729 }
730 }
731 }
732
733 return ditContentRuleEntries;
734 }
735
736
737
738
739
740 public List<Entry> loadDitStructureRules( Schema... schemas ) throws LdapException, IOException
741 {
742 List<Entry> ditStructureRuleEntries = new ArrayList<Entry>();
743
744 if ( schemas == null )
745 {
746 return ditStructureRuleEntries;
747 }
748
749 AttributesFactory factory = new AttributesFactory();
750
751 for ( Schema schema : schemas )
752 {
753 Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
754
755 for ( SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers )
756 {
757 SchemaObject schemaObject = schemaObjectWrapper.get();
758
759 if ( schemaObject instanceof DitStructureRule )
760 {
761 DitStructureRule ditStructureRule = ( DitStructureRule ) schemaObject;
762
763 Entry ditStructureRuleEntry = factory.convert( ditStructureRule, schema, null );
764
765 ditStructureRuleEntries.add( ditStructureRuleEntry );
766 }
767 }
768 }
769
770 return ditStructureRuleEntries;
771 }
772
773
774
775
776
777 public List<Entry> loadMatchingRuleUses( Schema... schemas ) throws LdapException, IOException
778 {
779 List<Entry> matchingRuleUseEntries = new ArrayList<Entry>();
780
781 if ( schemas == null )
782 {
783 return matchingRuleUseEntries;
784 }
785
786 AttributesFactory factory = new AttributesFactory();
787
788 for ( Schema schema : schemas )
789 {
790 Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
791
792 for ( SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers )
793 {
794 SchemaObject schemaObject = schemaObjectWrapper.get();
795
796 if ( schemaObject instanceof MatchingRuleUse )
797 {
798 MatchingRuleUse matchingRuleUse = ( MatchingRuleUse ) schemaObject;
799
800 Entry matchingRuleUseEntry = factory.convert( matchingRuleUse, schema, null );
801
802 matchingRuleUseEntries.add( matchingRuleUseEntry );
803 }
804 }
805 }
806
807 return matchingRuleUseEntries;
808 }
809
810
811
812
813
814 public List<Entry> loadMatchingRules( Schema... schemas ) throws LdapException, IOException
815 {
816 List<Entry> matchingRuleEntries = new ArrayList<Entry>();
817
818 if ( schemas == null )
819 {
820 return matchingRuleEntries;
821 }
822
823 AttributesFactory factory = new AttributesFactory();
824
825 for ( Schema schema : schemas )
826 {
827 Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
828
829 for ( SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers )
830 {
831 SchemaObject schemaObject = schemaObjectWrapper.get();
832
833 if ( schemaObject instanceof MatchingRule )
834 {
835 MatchingRule matchingRule = ( MatchingRule ) schemaObject;
836
837 Entry matchingRuleEntry = factory.convert( matchingRule, schema, null );
838
839 matchingRuleEntries.add( matchingRuleEntry );
840 }
841 }
842 }
843
844 return matchingRuleEntries;
845 }
846
847
848
849
850
851 public List<Entry> loadNameForms( Schema... schemas ) throws LdapException, IOException
852 {
853 List<Entry> nameFormEntries = new ArrayList<Entry>();
854
855 if ( schemas == null )
856 {
857 return nameFormEntries;
858 }
859
860 AttributesFactory factory = new AttributesFactory();
861
862 for ( Schema schema : schemas )
863 {
864 Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
865
866 for ( SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers )
867 {
868 SchemaObject schemaObject = schemaObjectWrapper.get();
869
870 if ( schemaObject instanceof NameForm )
871 {
872 NameForm nameForm = ( NameForm ) schemaObject;
873
874 Entry nameFormEntry = factory.convert( nameForm, schema, null );
875
876 nameFormEntries.add( nameFormEntry );
877 }
878 }
879 }
880
881 return nameFormEntries;
882 }
883
884
885
886
887
888 public List<Entry> loadNormalizers( Schema... schemas ) throws LdapException, IOException
889 {
890 List<Entry> normalizerEntries = new ArrayList<Entry>();
891
892 if ( schemas == null )
893 {
894 return normalizerEntries;
895 }
896
897 for ( Schema schema : schemas )
898 {
899 Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
900
901 for ( SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers )
902 {
903 SchemaObject schemaObject = schemaObjectWrapper.get();
904
905 if ( schemaObject instanceof NormalizerDescription )
906 {
907 NormalizerDescription normalizerDescription = ( NormalizerDescription ) schemaObject;
908 Entry normalizerEntry = getEntry( normalizerDescription );
909
910 normalizerEntries.add( normalizerEntry );
911 }
912 }
913 }
914
915 return normalizerEntries;
916 }
917
918
919
920
921
922 public List<Entry> loadObjectClasses( Schema... schemas ) throws LdapException, IOException
923 {
924 List<Entry> objectClassEntries = new ArrayList<Entry>();
925
926 if ( schemas == null )
927 {
928 return objectClassEntries;
929 }
930
931 AttributesFactory factory = new AttributesFactory();
932
933 for ( Schema schema : schemas )
934 {
935 Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
936
937 for ( SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers )
938 {
939 SchemaObject schemaObject = schemaObjectWrapper.get();
940
941 if ( schemaObject instanceof ObjectClass )
942 {
943 ObjectClass objectClass = ( ObjectClass ) schemaObject;
944
945 Entry objectClassEntry = factory.convert( objectClass, schema, null );
946
947 objectClassEntries.add( objectClassEntry );
948 }
949 }
950 }
951
952 return objectClassEntries;
953 }
954
955
956
957
958
959 public List<Entry> loadSyntaxCheckers( Schema... schemas ) throws LdapException, IOException
960 {
961 List<Entry> syntaxCheckerEntries = new ArrayList<Entry>();
962
963 if ( schemas == null )
964 {
965 return syntaxCheckerEntries;
966 }
967
968 for ( Schema schema : schemas )
969 {
970 Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
971
972 for ( SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers )
973 {
974 SchemaObject schemaObject = schemaObjectWrapper.get();
975
976 if ( schemaObject instanceof SyntaxCheckerDescription )
977 {
978 SyntaxCheckerDescription syntaxCheckerDescription = ( SyntaxCheckerDescription ) schemaObject;
979 Entry syntaxCheckerEntry = getEntry( syntaxCheckerDescription );
980
981 syntaxCheckerEntries.add( syntaxCheckerEntry );
982 }
983 }
984 }
985
986 return syntaxCheckerEntries;
987 }
988
989
990
991
992
993 public List<Entry> loadSyntaxes( Schema... schemas ) throws LdapException, IOException
994 {
995 List<Entry> syntaxEntries = new ArrayList<Entry>();
996
997 if ( schemas == null )
998 {
999 return syntaxEntries;
1000 }
1001
1002 AttributesFactory factory = new AttributesFactory();
1003
1004 for ( Schema schema : schemas )
1005 {
1006 Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
1007
1008 for ( SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers )
1009 {
1010 SchemaObject schemaObject = schemaObjectWrapper.get();
1011
1012 if ( schemaObject instanceof LdapSyntax )
1013 {
1014 LdapSyntax ldapSyntax = ( LdapSyntax ) schemaObject;
1015
1016 Entry ldapSyntaxEntry = factory.convert( ldapSyntax, schema, null );
1017
1018 syntaxEntries.add( ldapSyntaxEntry );
1019 }
1020 }
1021 }
1022
1023 return syntaxEntries;
1024 }
1025
1026
1027 private Entry getEntry( LdapComparatorDescription comparatorDescription )
1028 {
1029 Entry entry = new DefaultEntry();
1030
1031 entry.put( SchemaConstants.OBJECT_CLASS_AT,
1032 SchemaConstants.TOP_OC,
1033 MetaSchemaConstants.META_TOP_OC,
1034 MetaSchemaConstants.META_COMPARATOR_OC );
1035
1036 entry.put( MetaSchemaConstants.M_OID_AT, comparatorDescription.getOid() );
1037 entry.put( MetaSchemaConstants.M_FQCN_AT, comparatorDescription.getFqcn() );
1038
1039 if ( comparatorDescription.getBytecode() != null )
1040 {
1041 entry.put( MetaSchemaConstants.M_BYTECODE_AT,
1042 Base64.decode( comparatorDescription.getBytecode().toCharArray() ) );
1043 }
1044
1045 if ( comparatorDescription.getDescription() != null )
1046 {
1047 entry.put( MetaSchemaConstants.M_DESCRIPTION_AT, comparatorDescription.getDescription() );
1048 }
1049
1050 return entry;
1051 }
1052
1053
1054 private Entry getEntry( SyntaxCheckerDescription syntaxCheckerDescription )
1055 {
1056 Entry entry = new DefaultEntry();
1057
1058 entry.put( SchemaConstants.OBJECT_CLASS_AT,
1059 SchemaConstants.TOP_OC,
1060 MetaSchemaConstants.META_TOP_OC,
1061 MetaSchemaConstants.META_SYNTAX_CHECKER_OC );
1062
1063 entry.put( MetaSchemaConstants.M_OID_AT, syntaxCheckerDescription.getOid() );
1064 entry.put( MetaSchemaConstants.M_FQCN_AT, syntaxCheckerDescription.getFqcn() );
1065
1066 if ( syntaxCheckerDescription.getBytecode() != null )
1067 {
1068 entry.put( MetaSchemaConstants.M_BYTECODE_AT,
1069 Base64.decode( syntaxCheckerDescription.getBytecode().toCharArray() ) );
1070 }
1071
1072 if ( syntaxCheckerDescription.getDescription() != null )
1073 {
1074 entry.put( MetaSchemaConstants.M_DESCRIPTION_AT, syntaxCheckerDescription.getDescription() );
1075 }
1076
1077 return entry;
1078 }
1079
1080
1081 private Entry getEntry( NormalizerDescription normalizerDescription )
1082 {
1083 Entry entry = new DefaultEntry();
1084
1085 entry.put( SchemaConstants.OBJECT_CLASS_AT,
1086 SchemaConstants.TOP_OC,
1087 MetaSchemaConstants.META_TOP_OC,
1088 MetaSchemaConstants.META_NORMALIZER_OC );
1089
1090 entry.put( MetaSchemaConstants.M_OID_AT, normalizerDescription.getOid() );
1091 entry.put( MetaSchemaConstants.M_FQCN_AT, normalizerDescription.getFqcn() );
1092
1093 if ( normalizerDescription.getBytecode() != null )
1094 {
1095 entry.put( MetaSchemaConstants.M_BYTECODE_AT,
1096 Base64.decode( normalizerDescription.getBytecode().toCharArray() ) );
1097 }
1098
1099 if ( normalizerDescription.getDescription() != null )
1100 {
1101 entry.put( MetaSchemaConstants.M_DESCRIPTION_AT, normalizerDescription.getDescription() );
1102 }
1103
1104 return entry;
1105 }
1106 }