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

Attribute Syntax Definitions

An attribute's syntax specifies the representation of the attribute's values. Examples of attribute syntaxes are Directory String, which specifies a case-insensitive character string encoded using the ISO 10646 character set, and Octet String, which specifies a sequence of octets.

In the schema tree, the name "SyntaxDefinition" is bound to a flat context containing DirContext(in the API reference documentation) objects that represent syntax definitions in the schema. For example, if a directory supports the 1.3.6.1.4.1.1466.115.121.1.15 (Directory String) syntax, then the "SyntaxDefinition" context will have a binding with the name "1.3.6.1.4.1.1466.115.121.1.15" that is bound to a DirContext object.

Each object in the "SyntaxDefinition" context has the mandatory and optional attributes listed in the following table.
 

Attribute Identifier Attribute Value Description
NUMERICOID (mandatory) Unique object identifier (OID)
DESC Description of syntax

These attributes correspond to the definition of "SyntaxDescription" in RFC 2252. All the attribute values are represented by the java.lang.String class.

Retrieving the Schema of an Attribute Syntax Definition

To retrieve the schema object of an attribute syntax, you look for it in the schema tree. For example, you can obtain the schema object that represents the Directory String syntax by using the following code. The OID for Directory String is 1.3.6.1.4.1.1466.115.121.1.15.
// Get the schema tree root
DirContext schema = ctx.getSchema("");

// Get the schema object for Directory String's syntax
DirContext dsSchema =
  (DirContext)schema.lookup("SyntaxDefinition/1.3.6.1.4.1.1466.115.121.1.15");
If you get the attributes of the dsSchema schema object, then you will see the following.
NUMERICOID: 1.3.6.1.4.1.1466.115.121.1.15 
DESC: Directory String

Note: This example won't work with the Netscape Directory Server v4.1 because that server does not publish syntax definitions in the schema.

You can use not only lookup() to retrieve schema objects from the schema tree, but also such methods as list()(in the API reference documentation) or search()(in the API reference documentation).

Getting an Attribute's Syntax Definition

Given an Attribute(in the API reference documentation) object representing an LDAP attribute, you can get its schema object by invoking getAttributeSyntaxDefinition()(in the API reference documentation) on it. For example, to retrieve the schema object for the Directory String syntax, you first fetch an attribute that uses that syntax (such as the "cn" attribute) and then invoke getAttributeSyntaxDefinition() on it. Here's an example.

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

// Get its attribute syntax definition
DirContext dsSyntax = cnAttr.getAttributeSyntaxDefinition();

Note: This example won't work with the Netscape Directory Server v4.1 because that server does not publish syntax definitions in the schema.

Creating, Modifying, or Updating an Attribute Syntax Definition

Dynamically creating, deleting, or modifying attribute syntaxes does not make sense. Even if the LDAP server allows you to add a syntax to (or delete a syntax from) its schema, the necessary implementation changes must be done on the LDAP server to support the new syntax. Most servers support a fixed set of syntaxes. Changing that set programmatically is usually not a supported feature.


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