1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.forgerock.opendj.examples;
19
20 import org.forgerock.i18n.LocalizableMessage;
21 import org.forgerock.opendj.ldap.Connection;
22 import org.forgerock.opendj.ldap.DN;
23 import org.forgerock.opendj.ldap.LdapException;
24 import org.forgerock.opendj.ldap.LDAPConnectionFactory;
25 import org.forgerock.opendj.ldap.schema.AttributeType;
26 import org.forgerock.opendj.ldap.schema.MatchingRule;
27 import org.forgerock.opendj.ldap.schema.ObjectClass;
28 import org.forgerock.opendj.ldap.schema.Schema;
29 import org.forgerock.opendj.ldap.schema.Syntax;
30
31
32
33
34
35
36
37
38
39
40 public final class ReadSchema {
41
42
43
44
45
46
47 public static void main(final String[] args) {
48 if (args.length != 4) {
49 System.err.println("Usage: host port username password");
50 System.exit(1);
51 }
52
53
54 final String hostName = args[0];
55 final int port = Integer.parseInt(args[1]);
56 final String userName = args[2];
57 final String password = args[3];
58
59
60
61 final LDAPConnectionFactory factory = new LDAPConnectionFactory(hostName, port);
62 Connection connection = null;
63
64 try {
65 connection = factory.getConnection();
66 connection.bind(userName, password.toCharArray());
67
68
69 Schema schema = Schema.readSchemaForEntry(connection, DN.rootDN());
70
71 System.out.println("Attribute types");
72 for (AttributeType at : schema.getAttributeTypes()) {
73 System.out.println(" " + at.getNameOrOID());
74 }
75 System.out.println();
76
77 System.out.println("Object classes");
78 for (ObjectClass oc : schema.getObjectClasses()) {
79 System.out.println(" " + oc.getNameOrOID());
80 }
81 System.out.println();
82
83 System.out.println("Matching rules");
84 for (MatchingRule mr : schema.getMatchingRules()) {
85 System.out.println(" " + mr.getNameOrOID());
86 }
87 System.out.println();
88
89 System.out.println("Syntaxes");
90 for (Syntax s : schema.getSyntaxes()) {
91 System.out.println(" " + s.getDescription());
92 }
93 System.out.println();
94
95
96
97 System.out.println("WARNINGS");
98 for (LocalizableMessage m : schema.getWarnings()) {
99 System.out.println(" " + m);
100 }
101 System.out.println();
102 } catch (final LdapException e) {
103 System.err.println(e.getMessage());
104 System.exit(e.getResult().getResultCode().intValue());
105 return;
106 } finally {
107 if (connection != null) {
108 connection.close();
109 }
110 }
111
112 }
113
114 private ReadSchema() {
115
116 }
117 }