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

Attribute Type Definitions

An attribute type definition specifies the attribute's syntax and how attributes of that type are compared and sorted. The attribute types in the directory form a class hierarchy. For example, the "commonName" attribute type is a subclass of the "name" attribute type. However, attribute subclassing is not supported by many LDAP servers.

In the schema tree, the name "AttributeDefinition" is bound to a flat context containing DirContext(in the API reference documentation) objects representing attribute type definitions in the schema. For example, if a directory supports a "commonName" attribute, the "AttributeDefinition" context will have a binding with name "commonName" that is bound to a DirContext object.

Each object in the "AttributeDefinition" context has the following mandatory and optional attributes:
 

Attribute Identifier Attribute Value Description
NUMERICOID (mandatory) unique identifier (OID)
NAME attribute's name
DESC attribute's description
OBSOLETE "true" if obsolete; "false" or absent otherwise
SUP name of superior attribute type from which this attribute's type is derived
EQUALITY name or OID of matching rule if equality matching allowed; absent otherwise
ORDERING name or OID of matching rule if ordering matching allowed; absent otherwise
SUBSTRING name or OID of matching rule if substring matching allowed; absent otherwise
SYNTAX numeric OID of syntax of values of this type
SINGLE-VALUE "true" if attribute not multi-valued; "false" or absent otherwise.
COLLECTIVE "true" if attribute is collective; "false" or absent otherwise.
NO-USER-MODIFICATION "true" if not user-modifiable; "false" or absent otherwise.
USAGE description of attribute usage

These attributes correspond to the definition of "AttributeTypeDescription" in RFC 2252. All the attribute values are represented by the java.lang.String class. Some directories do not publish all of the schema data. For example, the Netscape Directory Server 4.1 does not publish the equality, ordering, and substring rules for its attribute definitions even though the server does support them for certain attributes. In these cases, the schema objects do not completely describe the attribute definitions.

Retrieving the Schema of an Attribute Type Definition

To retrieve the schema object of an attribute type definition, you look for it in the schema tree. For example, you can obtain the schema object representing the "cn" attribute by using the following code:
// Get the schema tree root
DirContext schema = ctx.getSchema("");

// Get schema object for "cn"
DirContext cnSchema = (DirContext)schema.lookup("AttributeDefinition/cn");
If you get the attributes of the "cnSchema" schema object, you will see:
NUMERICOID: 2.5.4.3
NAME: cn 
SYNTAX: 1.3.6.1.4.1.1466.115.121.1.15 
DESC: Standard Attribute

In addition to using lookup(), you can use methods such as list()(in the API reference documentation) or search()(in the API reference documentation) to retrieve schema objects from the schema tree.

Getting an Attribute's Type Definition

Given an Attribute(in the API reference documentation) object representing an LDAP attribute, you can get its schema object by invoking getAttributeDefinition()(in the API reference documentation) on it. So, another way of getting the schema object for "cn" is to get a "cn" attribute, and then invoke getAttributeDefinition(). Here's an example:

// Get an attribute of that type
Attributes attrs = ctx.getAttributes("cn=Ted Geisel, ou=People",
    new String[]{"cn"});
Attribute cnAttr = attrs.get("cn");

// Get its attribute type definition
DirContext cnSchema = cnAttr.getAttributeDefinition();

Adding a new Attribute Type Definition


Before you go on: See Object Class Definitions for notes regarding updating the schema.

Adding a new attribute type definition to the schema is like adding a new entry to the directory, because the schema tree and schema objects are DirContext objects. Here's an example that adds a new attribute type definition to the schema. First, it declares the attributes that describe the new attribute type definition, and then adds the definition to the schema by using DirContext.createSubcontext()(in the API reference documentation) .

// Specify attributes for schema object
Attributes attrs = new BasicAttributes(true); // ignore case
attrs.put("NUMERICOID", "1.3.6.1.4.1.42.2.27.4.2.3.1.1.2");
attrs.put("NAME", "fooAttr");
attrs.put("DESC", "for JNDITutorial example only");
attrs.put("SYNTAX", "1.3.6.1.4.1.1466.115.121.1.15");

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

// Add new schema object for "fooAttr"
DirContext newAttr = schema.createSubcontext("AttributeDefinition/fooAttr", attrs);

Modifying an Attribute Type Definition

You cannot modify an existing attribute definition. You must first delete the existing attribute definition and then add the updated version.

Deleting an Attribute Type Definition


Before you go on: See Object Class Definitions for notes regarding updating the schema.
Deleting an existing attribute type definition from the schema is like deleting an entry from the directory. Here's an example that removes the attribute type definition "fooAttr" from the schema by using DirContext.destroySubcontext()(in the API reference documentation) :
// Get the schema tree root
DirContext schema = ctx.getSchema("");

// Remove the schema object for "fooAttr"
schema.destroySubcontext("AttributeDefinition/fooAttr");
Some servers might not let you delete an attribute type defintion that's being used by entries in the directory. You might be able to get around this restriction by turning off schema-checking.


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