Previous | Next | Trail Map | Tips for LDAP Users | Schema

Schema in the JNDI

The JNDI contains methods that access schema information about object classes, attribute types, and attribute syntaxes. These methods are listed in the following table.

Method Description
DirContext.getSchema()(in the API reference documentation) Returns the schema tree for the named object.
DirContext.getSchemaClassDefinition()(in the API reference documentation) Returns the object class definition for the named object.
Attribute.getAttributeDefinition()(in the API reference documentation) Returns the attribute definition for this attribute.
Attribute.getAttributeSyntaxDefinition()(in the API reference documentation) Returns the syntax definition for this attribute.

DirContext.getSchema() is described in this section. The other methods are described in more detail elsewhere in this lesson.

The JNDI provides general descriptions of how these methods should behave but does not specify many details, such as the structure and contents of the schema tree, the attributes of the DirContext(in the API reference documentation) objects returned by the schema methods, or the effect of modifications to the schema tree and data on the directory itself. These details are currently determined by the underlying service provider and directory service because schema data is specific to each service. However, it makes sense for such details to be specified for a particular style of directory. For example, all LDAP-style directories should return schema information in a particular way. The Guidelines for LDAP Service Providers describes the recommended schema tree and attributes for LDAP-style directories.

Relationship to the LDAP Schema

The methods in the preceding table are invoked on the object for which you want the schema information. When you are using the LDAP service provider, the objects returned by these methods are derived from schema information in the LDAP directory. The provider first tries to obtain the information from the subschema subentry of the object's corresponding LDAP entry. If this entry is not available, then it consults the root DSE's subschema subentry. If neither of these two sources is available, then an OperationNotSupportedException(in the API reference documentation) is thrown.

The sections Object Class Definitions, Attribute Type Definitions, Attribute Syntax Definitions, and Attribute Matching Rule Definitions give specifics about how the attributes in the subschema subentry are mapped to the objects returned by the JNDI methods.

The Schema Tree

The JNDI specifies that DirContext.getSchema() returns the root of the schema tree. The tree contains the bindings listed in the following table.

Name Binding
AttributeDefinition The root of the attribute type definition namespace.
ClassDefinition The root of the object class definition namespace.
SyntaxDefinition The root of the attribute syntax definition namespace.

Any or all of these bindings may be absent if the underlying directory does not publish such schema data or if the service provider does not support their retrieval. The SunONE Directory Server v5.1, for example, does not publish syntax definitions.

Service providers may also make available additional bindings in the schema tree, for example, bindings for matching rules and extensions. Sun's LDAP service provider, for example, supports looking up matching rule definitions from the "MatchingRule" binding in the schema tree.

Here's an example that retrieves the schema tree root for the LDAP entry "ou=People" and lists its contents.

// Get the schema tree root
DirContext schema = ctx.getSchema("ou=People");

// List the contents of root
NamingEnumeration bds = schema.list("");
while (bds.hasMore()) {
Here's the output produced by this example.

Previous | Next | Trail Map | Tips for LDAP Users | Schema