LDAP presents the schema as an object. The name of this object is obtained from the rootDSE object. For eDirectory servers, it’s normally "cn=schema", located at the root. This object has an "objectClasses" attribute containing definitions of all the object classes in the schema, and an "attributeTypes" attribute defining all the attribute types.
The schema may be modified by modifying attribute values within this object. For a complete sample see ListSchema.java in the Sample Code.
NOTE:Novell recommends using the Novell Import Convert Export utility for making schema extensions. This utility allows you to input changes via LDIF files eliminating the need to embed schema changes in an application and allows users to view the schema changes in an easy-to-read format.
Reading the schema requires the following steps:
Connect to the LDAP server.
Read the schema using the LDAPConnection.fetchSchema method.
The FetchSchema method automatically uses the name of the schema object from the root DSE.
Output the classes and attributes.
Initially, we need to connect to the server:
LDAPConnection lc = new LDAPConnection(); lc.connect([LDAP Host], [ldapPort]); lc.bind(ldapVersion, [loginDN], [password]);
Next, we create an LDAPSchema object and fetch the schema:
LDAPSchema schema = lc.fetchSchema(getSchema = lc.getSchemaDN());
We now use an enumeration to read the attributes and classes from the schema:
Enumeration enum = schema.getAttributes()
while(enum.hasMoreElements())
{
LDAPAttributeSchema attr =
(LDAPAttributeSchema)enum.nextElement();
System.out.println(attr.getNames()[0]);
System.out.println(attr.getSyntaxString());
}
enum = schema.getObjectClasses();
while(enum.hasMoreElements())
{
LDAPObjectClassSchema objcls
(LDAPObjectClassSchema)enum.nextElement();
System.out.println(objcls.getNames()[0]);
}
See Section 7.0, JavaDoc API Reference, for more information on LDAP schema.