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