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 representing 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, the "SyntaxDefinition" context will have a binding with name "1.3.6.1.4.1.1466.115.121.1.15" that is bound to a DirContext object.

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

Attribute Identifier Attribute Value Description
NUMERICOID (mandatory) unique identifier (OID)
DESC syntax's description

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 representing 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 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, you will see:
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 4.1 because it does not publish syntax definitions in the schema.

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 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 4.1 because it does not publish syntax definitions in the schema.

Creating, Modifying, or Updating an Attribute Syntax Definition

It does not make sense to dynamically create, delete, or modify attribute syntaxes. 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