0
# Schema Management
1
2
Complete LDAP schema representation, validation, and manipulation capabilities for attribute types, object classes, matching rules, and schema-based entry validation.
3
4
## Capabilities
5
6
### Schema Retrieval and Representation
7
8
#### Schema
9
10
Complete LDAP schema representation containing all schema elements.
11
12
```java { .api }
13
/**
14
* Complete LDAP schema representation
15
*/
16
public class Schema implements Serializable {
17
// Schema retrieval
18
public static Schema getSchema(LDAPInterface connection) throws LDAPException;
19
public static Schema getSchema(LDAPInterface connection, String subschemaSubentryDN) throws LDAPException;
20
public static Schema parseSchemaEntry(Entry schemaEntry) throws LDAPException;
21
22
// Schema elements access
23
public Set<AttributeTypeDefinition> getAttributeTypes();
24
public AttributeTypeDefinition getAttributeType(String name);
25
public AttributeTypeDefinition getAttributeType(String name, boolean includeSubordinateTypes);
26
27
public Set<ObjectClassDefinition> getObjectClasses();
28
public ObjectClassDefinition getObjectClass(String name);
29
30
public Set<AttributeSyntaxDefinition> getAttributeSyntaxes();
31
public AttributeSyntaxDefinition getAttributeSyntax(String oid);
32
33
public Set<MatchingRuleDefinition> getMatchingRules();
34
public MatchingRuleDefinition getMatchingRule(String nameOrOID);
35
36
public Set<MatchingRuleUseDefinition> getMatchingRuleUses();
37
public MatchingRuleUseDefinition getMatchingRuleUse(String nameOrOID);
38
39
public Set<DITContentRuleDefinition> getDITContentRules();
40
public DITContentRuleDefinition getDITContentRule(String nameOrOID);
41
42
public Set<DITStructureRuleDefinition> getDITStructureRules();
43
public DITStructureRuleDefinition getDITStructureRule(int ruleID);
44
public DITStructureRuleDefinition getDITStructureRule(String nameOrOID);
45
46
public Set<NameFormDefinition> getNameForms();
47
public NameFormDefinition getNameForm(String nameOrOID);
48
49
// Schema validation
50
public EntryValidator getEntryValidator();
51
public EntryValidator getEntryValidator(boolean checkAttributeSyntax, boolean checkMissingRequiredAttributes, boolean checkSingleValuedAttributes, boolean checkNameFormCompliance, boolean checkDITContentRuleCompliance);
52
53
// Schema operations
54
public String getSchemaEntry(boolean includeBaseDNAndScope);
55
public Entry getSchemaEntryAsEntry();
56
public Schema mergeSchema(Schema schema);
57
}
58
```
59
60
### Attribute Type Definitions
61
62
#### AttributeTypeDefinition
63
64
Definition of LDAP attribute types with syntax, matching rules, and constraints.
65
66
```java { .api }
67
/**
68
* Definition of an LDAP attribute type
69
*/
70
public class AttributeTypeDefinition implements SchemaElement, Serializable {
71
// Constructors
72
public AttributeTypeDefinition(String definition) throws LDAPException;
73
74
// Basic properties
75
public String getOID();
76
public String[] getNames();
77
public String getNameOrOID();
78
public String getDescription();
79
public boolean isObsolete();
80
81
// Type hierarchy
82
public String getSuperiorType();
83
public AttributeTypeDefinition getSuperiorType(Schema schema);
84
public boolean isDescendantOf(AttributeTypeDefinition attributeType, Schema schema);
85
public boolean isAncestorOf(AttributeTypeDefinition attributeType, Schema schema);
86
87
// Syntax and matching
88
public String getSyntaxOID();
89
public AttributeSyntaxDefinition getAttributeSyntax(Schema schema);
90
public String getEqualityMatchingRule();
91
public MatchingRuleDefinition getEqualityMatchingRule(Schema schema);
92
public String getOrderingMatchingRule();
93
public MatchingRuleDefinition getOrderingMatchingRule(Schema schema);
94
public String getSubstringMatchingRule();
95
public MatchingRuleDefinition getSubstringMatchingRule(Schema schema);
96
97
// Constraints
98
public boolean isSingleValued();
99
public boolean isCollective();
100
public boolean isNoUserModification();
101
public AttributeUsage getUsage();
102
103
// String representation
104
public String toString();
105
public String toString(boolean includeFileLocation);
106
107
// Extensions
108
public Map<String, String[]> getExtensions();
109
public String[] getExtensionValues(String extensionName);
110
}
111
112
/**
113
* Attribute usage enumeration
114
*/
115
public enum AttributeUsage {
116
USER_APPLICATIONS("userApplications"),
117
DIRECTORY_OPERATION("directoryOperation"),
118
DISTRIBUTED_OPERATION("distributedOperation"),
119
DSA_OPERATION("dSAOperation");
120
121
public String getName();
122
public static AttributeUsage forName(String name);
123
}
124
```
125
126
### Object Class Definitions
127
128
#### ObjectClassDefinition
129
130
Definition of LDAP object classes with inheritance and attribute requirements.
131
132
```java { .api }
133
/**
134
* Definition of an LDAP object class
135
*/
136
public class ObjectClassDefinition implements SchemaElement, Serializable {
137
// Constructors
138
public ObjectClassDefinition(String definition) throws LDAPException;
139
140
// Basic properties
141
public String getOID();
142
public String[] getNames();
143
public String getNameOrOID();
144
public String getDescription();
145
public boolean isObsolete();
146
147
// Class hierarchy
148
public String[] getSuperiorClasses();
149
public Set<ObjectClassDefinition> getSuperiorClasses(Schema schema, boolean includeThis);
150
public ObjectClassType getObjectClassType();
151
public boolean isDescendantOf(ObjectClassDefinition objectClass, Schema schema);
152
public boolean isAncestorOf(ObjectClassDefinition objectClass, Schema schema);
153
154
// Attribute requirements
155
public String[] getRequiredAttributes();
156
public Set<AttributeTypeDefinition> getRequiredAttributes(Schema schema, boolean includeOptional);
157
public String[] getOptionalAttributes();
158
public Set<AttributeTypeDefinition> getOptionalAttributes(Schema schema, boolean includeRequired);
159
public boolean isRequiredAttribute(String attributeName, Schema schema);
160
public boolean isOptionalAttribute(String attributeName, Schema schema);
161
public boolean isRequiredOrOptionalAttribute(String attributeName, Schema schema);
162
163
// String representation
164
public String toString();
165
public String toString(boolean includeFileLocation);
166
167
// Extensions
168
public Map<String, String[]> getExtensions();
169
public String[] getExtensionValues(String extensionName);
170
}
171
172
/**
173
* Object class type enumeration
174
*/
175
public enum ObjectClassType {
176
ABSTRACT("ABSTRACT"),
177
STRUCTURAL("STRUCTURAL"),
178
AUXILIARY("AUXILIARY");
179
180
public String getName();
181
public static ObjectClassType forName(String name);
182
}
183
```
184
185
### Matching Rules and Syntaxes
186
187
#### MatchingRuleDefinition
188
189
Definition of LDAP matching rules for attribute comparison.
190
191
```java { .api }
192
/**
193
* Definition of an LDAP matching rule
194
*/
195
public class MatchingRuleDefinition implements SchemaElement, Serializable {
196
// Constructors
197
public MatchingRuleDefinition(String definition) throws LDAPException;
198
199
// Basic properties
200
public String getOID();
201
public String[] getNames();
202
public String getNameOrOID();
203
public String getDescription();
204
public boolean isObsolete();
205
206
// Syntax
207
public String getSyntaxOID();
208
public AttributeSyntaxDefinition getAttributeSyntax(Schema schema);
209
210
// String representation
211
public String toString();
212
public String toString(boolean includeFileLocation);
213
214
// Extensions
215
public Map<String, String[]> getExtensions();
216
public String[] getExtensionValues(String extensionName);
217
}
218
```
219
220
#### AttributeSyntaxDefinition
221
222
Definition of LDAP attribute syntaxes.
223
224
```java { .api }
225
/**
226
* Definition of an LDAP attribute syntax
227
*/
228
public class AttributeSyntaxDefinition implements SchemaElement, Serializable {
229
// Constructors
230
public AttributeSyntaxDefinition(String definition) throws LDAPException;
231
232
// Basic properties
233
public String getOID();
234
public String getDescription();
235
236
// String representation
237
public String toString();
238
public String toString(boolean includeFileLocation);
239
240
// Extensions
241
public Map<String, String[]> getExtensions();
242
public String[] getExtensionValues(String extensionName);
243
}
244
```
245
246
### DIT Rules and Name Forms
247
248
#### DITContentRuleDefinition
249
250
Definition of DIT content rules for structural object class constraints.
251
252
```java { .api }
253
/**
254
* Definition of a DIT content rule
255
*/
256
public class DITContentRuleDefinition implements SchemaElement, Serializable {
257
// Constructors
258
public DITContentRuleDefinition(String definition) throws LDAPException;
259
260
// Basic properties
261
public String getOID();
262
public String[] getNames();
263
public String getNameOrOID();
264
public String getDescription();
265
public boolean isObsolete();
266
267
// Structural object class
268
public String getStructuralClass();
269
public ObjectClassDefinition getStructuralClass(Schema schema);
270
271
// Auxiliary classes
272
public String[] getAuxiliaryClasses();
273
public Set<ObjectClassDefinition> getAuxiliaryClasses(Schema schema);
274
public String[] getProhibitedAuxiliaryClasses();
275
public Set<ObjectClassDefinition> getProhibitedAuxiliaryClasses(Schema schema);
276
277
// Attribute constraints
278
public String[] getRequiredAttributes();
279
public Set<AttributeTypeDefinition> getRequiredAttributes(Schema schema);
280
public String[] getOptionalAttributes();
281
public Set<AttributeTypeDefinition> getOptionalAttributes(Schema schema);
282
public String[] getProhibitedAttributes();
283
public Set<AttributeTypeDefinition> getProhibitedAttributes(Schema schema);
284
285
// String representation
286
public String toString();
287
288
// Extensions
289
public Map<String, String[]> getExtensions();
290
}
291
```
292
293
#### DITStructureRuleDefinition
294
295
Definition of DIT structure rules for hierarchical constraints.
296
297
```java { .api }
298
/**
299
* Definition of a DIT structure rule
300
*/
301
public class DITStructureRuleDefinition implements SchemaElement, Serializable {
302
// Constructors
303
public DITStructureRuleDefinition(String definition) throws LDAPException;
304
305
// Basic properties
306
public int getRuleID();
307
public String[] getNames();
308
public String getNameOrOID();
309
public String getDescription();
310
public boolean isObsolete();
311
312
// Name form and hierarchy
313
public String getNameFormID();
314
public NameFormDefinition getNameForm(Schema schema);
315
public int[] getSuperiorRuleIDs();
316
public Set<DITStructureRuleDefinition> getSuperiorRules(Schema schema);
317
318
// String representation
319
public String toString();
320
321
// Extensions
322
public Map<String, String[]> getExtensions();
323
}
324
```
325
326
#### NameFormDefinition
327
328
Definition of LDAP name forms for RDN constraints.
329
330
```java { .api }
331
/**
332
* Definition of an LDAP name form
333
*/
334
public class NameFormDefinition implements SchemaElement, Serializable {
335
// Constructors
336
public NameFormDefinition(String definition) throws LDAPException;
337
338
// Basic properties
339
public String getOID();
340
public String[] getNames();
341
public String getNameOrOID();
342
public String getDescription();
343
public boolean isObsolete();
344
345
// Structural object class
346
public String getStructuralClass();
347
public ObjectClassDefinition getStructuralClass(Schema schema);
348
349
// Required and optional naming attributes
350
public String[] getRequiredNamingAttributes();
351
public Set<AttributeTypeDefinition> getRequiredNamingAttributes(Schema schema);
352
public String[] getOptionalNamingAttributes();
353
public Set<AttributeTypeDefinition> getOptionalNamingAttributes(Schema schema);
354
355
// String representation
356
public String toString();
357
358
// Extensions
359
public Map<String, String[]> getExtensions();
360
}
361
```
362
363
### Schema Validation
364
365
#### EntryValidator
366
367
Comprehensive LDAP entry validation against schema rules.
368
369
```java { .api }
370
/**
371
* Validator for LDAP entries against schema rules
372
*/
373
public class EntryValidator {
374
// Constructors
375
public EntryValidator(Schema schema);
376
public EntryValidator(Schema schema, boolean checkAttributeSyntax, boolean checkMissingRequiredAttributes, boolean checkSingleValuedAttributes, boolean checkNameFormCompliance, boolean checkDITContentRuleCompliance);
377
378
// Validation methods
379
public List<String> validateEntry(Entry entry);
380
public List<String> validateEntry(Entry entry, boolean checkMissingAttributes);
381
public boolean entryIsValid(Entry entry);
382
public boolean entryIsValid(Entry entry, List<String> invalidReasons);
383
384
// Attribute validation
385
public List<String> validateAttribute(Attribute attribute, Entry entry);
386
public boolean attributeIsValid(Attribute attribute, Entry entry);
387
public boolean attributeIsValid(Attribute attribute, Entry entry, List<String> invalidReasons);
388
389
// Configuration access
390
public Schema getSchema();
391
public boolean checkAttributeSyntax();
392
public boolean checkMissingRequiredAttributes();
393
public boolean checkSingleValuedAttributes();
394
public boolean checkNameFormCompliance();
395
public boolean checkDITContentRuleCompliance();
396
}
397
```
398
399
### Schema Modification
400
401
#### Schema Utilities
402
403
```java { .api }
404
/**
405
* Utilities for schema manipulation and comparison
406
*/
407
public class SchemaValidator {
408
public static List<String> getSchemaEntryWarnings(Entry schemaEntry);
409
public static List<String> validateSchema(Schema schema);
410
public static List<String> validateSchema(Schema schema, Entry schemaEntry);
411
}
412
413
/**
414
* Schema comparison utilities
415
*/
416
public class SchemaComparator {
417
public static List<String> getSchemaCompatibilityWarnings(Schema oldSchema, Schema newSchema);
418
public static boolean schemasAreCompatible(Schema oldSchema, Schema newSchema);
419
}
420
```
421
422
## Usage Examples
423
424
### Retrieving and Examining Schema
425
426
```java
427
import com.unboundid.ldap.sdk.*;
428
import com.unboundid.ldap.sdk.schema.*;
429
430
LDAPConnection connection = new LDAPConnection("ldap.example.com", 389);
431
432
try {
433
connection.bind("cn=admin,dc=example,dc=com", "password");
434
435
// Retrieve schema from the server
436
Schema schema = Schema.getSchema(connection);
437
438
System.out.println("Schema retrieved successfully");
439
System.out.println("Number of attribute types: " + schema.getAttributeTypes().size());
440
System.out.println("Number of object classes: " + schema.getObjectClasses().size());
441
System.out.println("Number of matching rules: " + schema.getMatchingRules().size());
442
443
// Examine specific attribute type
444
AttributeTypeDefinition cnAttrType = schema.getAttributeType("cn");
445
if (cnAttrType != null) {
446
System.out.println("\nCommonName (cn) attribute type:");
447
System.out.println(" OID: " + cnAttrType.getOID());
448
System.out.println(" Names: " + Arrays.toString(cnAttrType.getNames()));
449
System.out.println(" Description: " + cnAttrType.getDescription());
450
System.out.println(" Syntax OID: " + cnAttrType.getSyntaxOID());
451
System.out.println(" Single-valued: " + cnAttrType.isSingleValued());
452
System.out.println(" Superior type: " + cnAttrType.getSuperiorType());
453
System.out.println(" Equality matching rule: " + cnAttrType.getEqualityMatchingRule());
454
}
455
456
// Examine specific object class
457
ObjectClassDefinition personOC = schema.getObjectClass("person");
458
if (personOC != null) {
459
System.out.println("\nPerson object class:");
460
System.out.println(" OID: " + personOC.getOID());
461
System.out.println(" Names: " + Arrays.toString(personOC.getNames()));
462
System.out.println(" Type: " + personOC.getObjectClassType());
463
System.out.println(" Superior classes: " + Arrays.toString(personOC.getSuperiorClasses()));
464
System.out.println(" Required attributes: " + Arrays.toString(personOC.getRequiredAttributes()));
465
System.out.println(" Optional attributes: " + Arrays.toString(personOC.getOptionalAttributes()));
466
}
467
468
} finally {
469
connection.close();
470
}
471
```
472
473
### Schema-Based Entry Validation
474
475
```java
476
import com.unboundid.ldap.sdk.*;
477
import com.unboundid.ldap.sdk.schema.*;
478
479
LDAPConnection connection = new LDAPConnection("ldap.example.com", 389);
480
481
try {
482
connection.bind("cn=admin,dc=example,dc=com", "password");
483
484
// Get schema
485
Schema schema = Schema.getSchema(connection);
486
487
// Create entry validator
488
EntryValidator validator = schema.getEntryValidator();
489
490
// Create test entry
491
Entry testEntry = new Entry(
492
"cn=John Doe,ou=people,dc=example,dc=com",
493
new Attribute("objectClass", "inetOrgPerson"),
494
new Attribute("cn", "John Doe"),
495
new Attribute("sn", "Doe"),
496
new Attribute("givenName", "John"),
497
new Attribute("mail", "john.doe@example.com"),
498
new Attribute("telephoneNumber", "+1-555-0123")
499
);
500
501
// Validate entry
502
List<String> validationErrors = validator.validateEntry(testEntry);
503
504
if (validationErrors.isEmpty()) {
505
System.out.println("Entry is valid according to schema");
506
} else {
507
System.out.println("Entry validation errors:");
508
for (String error : validationErrors) {
509
System.out.println(" - " + error);
510
}
511
}
512
513
// Test with invalid entry (missing required attribute)
514
Entry invalidEntry = new Entry(
515
"cn=Jane Smith,ou=people,dc=example,dc=com",
516
new Attribute("objectClass", "inetOrgPerson"),
517
new Attribute("cn", "Jane Smith")
518
// Missing required 'sn' attribute
519
);
520
521
validationErrors = validator.validateEntry(invalidEntry);
522
System.out.println("\nValidation errors for incomplete entry:");
523
for (String error : validationErrors) {
524
System.out.println(" - " + error);
525
}
526
527
} finally {
528
connection.close();
529
}
530
```
531
532
### Working with Attribute Types
533
534
```java
535
import com.unboundid.ldap.sdk.*;
536
import com.unboundid.ldap.sdk.schema.*;
537
538
LDAPConnection connection = new LDAPConnection("ldap.example.com", 389);
539
540
try {
541
connection.bind("cn=admin,dc=example,dc=com", "password");
542
Schema schema = Schema.getSchema(connection);
543
544
// Find all single-valued attributes
545
System.out.println("Single-valued attribute types:");
546
for (AttributeTypeDefinition attrType : schema.getAttributeTypes()) {
547
if (attrType.isSingleValued()) {
548
System.out.println(" " + attrType.getNameOrOID() + " - " + attrType.getDescription());
549
}
550
}
551
552
// Find attributes with specific syntax (e.g., telephone numbers)
553
System.out.println("\nTelephone number attributes:");
554
for (AttributeTypeDefinition attrType : schema.getAttributeTypes()) {
555
if ("1.3.6.1.4.1.1466.115.121.1.50".equals(attrType.getSyntaxOID())) {
556
System.out.println(" " + attrType.getNameOrOID());
557
}
558
}
559
560
// Examine attribute inheritance hierarchy
561
AttributeTypeDefinition nameAttr = schema.getAttributeType("name");
562
if (nameAttr != null) {
563
System.out.println("\nAttribute type hierarchy for 'name':");
564
System.out.println(" " + nameAttr.getNameOrOID());
565
566
// Find all descendants of 'name'
567
for (AttributeTypeDefinition attrType : schema.getAttributeTypes()) {
568
if (attrType.isDescendantOf(nameAttr, schema)) {
569
System.out.println(" -> " + attrType.getNameOrOID());
570
}
571
}
572
}
573
574
} finally {
575
connection.close();
576
}
577
```
578
579
### Working with Object Classes
580
581
```java
582
import com.unboundid.ldap.sdk.*;
583
import com.unboundid.ldap.sdk.schema.*;
584
585
LDAPConnection connection = new LDAPConnection("ldap.example.com", 389);
586
587
try {
588
connection.bind("cn=admin,dc=example,dc=com", "password");
589
Schema schema = Schema.getSchema(connection);
590
591
// Find all structural object classes
592
System.out.println("Structural object classes:");
593
for (ObjectClassDefinition objClass : schema.getObjectClasses()) {
594
if (objClass.getObjectClassType() == ObjectClassType.STRUCTURAL) {
595
System.out.println(" " + objClass.getNameOrOID() + " - " + objClass.getDescription());
596
}
597
}
598
599
// Analyze inetOrgPerson object class
600
ObjectClassDefinition inetOrgPerson = schema.getObjectClass("inetOrgPerson");
601
if (inetOrgPerson != null) {
602
System.out.println("\ninetOrgPerson analysis:");
603
604
// Get all required attributes (including inherited)
605
Set<AttributeTypeDefinition> allRequired = inetOrgPerson.getRequiredAttributes(schema, false);
606
System.out.println(" All required attributes (" + allRequired.size() + "):");
607
for (AttributeTypeDefinition attrType : allRequired) {
608
System.out.println(" - " + attrType.getNameOrOID());
609
}
610
611
// Get all optional attributes (including inherited)
612
Set<AttributeTypeDefinition> allOptional = inetOrgPerson.getOptionalAttributes(schema, false);
613
System.out.println(" All optional attributes (" + allOptional.size() + "):");
614
for (AttributeTypeDefinition attrType : allOptional) {
615
System.out.println(" - " + attrType.getNameOrOID());
616
}
617
618
// Check class hierarchy
619
System.out.println(" Superior classes:");
620
Set<ObjectClassDefinition> superiors = inetOrgPerson.getSuperiorClasses(schema, false);
621
for (ObjectClassDefinition superior : superiors) {
622
System.out.println(" - " + superior.getNameOrOID());
623
}
624
}
625
626
} finally {
627
connection.close();
628
}
629
```
630
631
### Entry Validation with Custom Rules
632
633
```java
634
import com.unboundid.ldap.sdk.*;
635
import com.unboundid.ldap.sdk.schema.*;
636
637
LDAPConnection connection = new LDAPConnection("ldap.example.com", 389);
638
639
try {
640
connection.bind("cn=admin,dc=example,dc=com", "password");
641
Schema schema = Schema.getSchema(connection);
642
643
// Create validator with specific rules
644
EntryValidator strictValidator = new EntryValidator(
645
schema,
646
true, // Check attribute syntax
647
true, // Check missing required attributes
648
true, // Check single-valued attributes
649
true, // Check name form compliance
650
true // Check DIT content rule compliance
651
);
652
653
// Create validator that only checks basic requirements
654
EntryValidator basicValidator = new EntryValidator(
655
schema,
656
false, // Don't check attribute syntax
657
true, // Check missing required attributes
658
false, // Don't check single-valued attributes
659
false, // Don't check name form compliance
660
false // Don't check DIT content rule compliance
661
);
662
663
// Test entry with multiple values for single-valued attribute
664
Entry testEntry = new Entry(
665
"cn=Test User,ou=people,dc=example,dc=com",
666
new Attribute("objectClass", "inetOrgPerson"),
667
new Attribute("cn", "Test User"),
668
new Attribute("sn", "User"),
669
new Attribute("displayName", "Test User", "T. User") // displayName is usually single-valued
670
);
671
672
// Validate with strict validator
673
List<String> strictErrors = strictValidator.validateEntry(testEntry);
674
System.out.println("Strict validation errors:");
675
if (strictErrors.isEmpty()) {
676
System.out.println(" None");
677
} else {
678
for (String error : strictErrors) {
679
System.out.println(" - " + error);
680
}
681
}
682
683
// Validate with basic validator
684
List<String> basicErrors = basicValidator.validateEntry(testEntry);
685
System.out.println("\nBasic validation errors:");
686
if (basicErrors.isEmpty()) {
687
System.out.println(" None");
688
} else {
689
for (String error : basicErrors) {
690
System.out.println(" - " + error);
691
}
692
}
693
694
} finally {
695
connection.close();
696
}
697
```
698
699
### Schema Export and Analysis
700
701
```java
702
import com.unboundid.ldap.sdk.*;
703
import com.unboundid.ldap.sdk.schema.*;
704
import java.io.*;
705
706
LDAPConnection connection = new LDAPConnection("ldap.example.com", 389);
707
708
try {
709
connection.bind("cn=admin,dc=example,dc=com", "password");
710
Schema schema = Schema.getSchema(connection);
711
712
// Export schema to file
713
Entry schemaEntry = schema.getSchemaEntryAsEntry();
714
FileWriter writer = new FileWriter("schema-export.ldif");
715
writer.write(schemaEntry.toLDIFString());
716
writer.close();
717
718
System.out.println("Schema exported to schema-export.ldif");
719
720
// Generate schema statistics
721
System.out.println("\nSchema Statistics:");
722
System.out.println(" Attribute Types: " + schema.getAttributeTypes().size());
723
System.out.println(" Object Classes: " + schema.getObjectClasses().size());
724
System.out.println(" Matching Rules: " + schema.getMatchingRules().size());
725
System.out.println(" Attribute Syntaxes: " + schema.getAttributeSyntaxes().size());
726
System.out.println(" DIT Content Rules: " + schema.getDITContentRules().size());
727
System.out.println(" DIT Structure Rules: " + schema.getDITStructureRules().size());
728
System.out.println(" Name Forms: " + schema.getNameForms().size());
729
730
// Analyze object class types
731
int structural = 0, auxiliary = 0, abstractClasses = 0;
732
for (ObjectClassDefinition objClass : schema.getObjectClasses()) {
733
switch (objClass.getObjectClassType()) {
734
case STRUCTURAL:
735
structural++;
736
break;
737
case AUXILIARY:
738
auxiliary++;
739
break;
740
case ABSTRACT:
741
abstractClasses++;
742
break;
743
}
744
}
745
746
System.out.println("\nObject Class Types:");
747
System.out.println(" Structural: " + structural);
748
System.out.println(" Auxiliary: " + auxiliary);
749
System.out.println(" Abstract: " + abstractClasses);
750
751
// Find most commonly used attribute syntaxes
752
Map<String, Integer> syntaxCounts = new HashMap<>();
753
for (AttributeTypeDefinition attrType : schema.getAttributeTypes()) {
754
String syntaxOID = attrType.getSyntaxOID();
755
if (syntaxOID != null) {
756
syntaxCounts.put(syntaxOID, syntaxCounts.getOrDefault(syntaxOID, 0) + 1);
757
}
758
}
759
760
System.out.println("\nMost common attribute syntaxes:");
761
syntaxCounts.entrySet().stream()
762
.sorted(Map.Entry.<String, Integer>comparingByValue().reversed())
763
.limit(5)
764
.forEach(entry -> {
765
AttributeSyntaxDefinition syntax = schema.getAttributeSyntax(entry.getKey());
766
String description = (syntax != null) ? syntax.getDescription() : "Unknown";
767
System.out.println(" " + entry.getKey() + " (" + entry.getValue() + " attributes) - " + description);
768
});
769
770
} finally {
771
connection.close();
772
}
773
```