| Previous | Table of Contents | Next |
In this code, a ModificationItem array is created, and all the necessary changes for Karen are added to it. The changes take the form of ModificationItems containing an operation to perform; an attribute to add, remove, or change; and an optional value to which the attribute is set.
Using ModificationItem, you can perform operations that affect the types of attributes contained in the server. This potentially changes the schema of the directory server. The next section shows the features of JNDI that allow you to explore the schema of a directory service.
For dynamic applications that need to read the structure of a directory, the schema is an important resource. The schema describes rules regarding the structure of the namespace and the attributes stored in it. The schema specifies the types of objects that can be added to the directory, the mandatory and optional attributes that are possible, and where the objects can be added in the schema. JNDI supports the notion of schemas expressed as an information tree. Programs can retrieve the schema associated with a directory object if the underlying context provides the appropriate support. The DirContext method getSchema is used to retrieve the root DirContext of the schema tree associated with the directory. The children of the schema root describe the rules that define the structure and attributes of the directory context. These children themselves are each of type DirContext. These contexts have a method getSchemaClassDefinition that contains information about a particular directory in the schema. You can also find out information about an attribute of an object by calling the Attribute methods getAttributeDefinition and getAttributeSyntaxDefinition. These methods are described in Table 5.15.
Using the schema methods of DirContext, you can identify the structure of a directory service and create dynamic queries and updates. For example, you could find out if the directory service supported a certain type of currency, then do your calculations in that currency. Schema access provides you a way to create truly dynamic applications that leverage many directory services with a consistent API.
The JNDI defines a class hierarchy for exceptions that can be thrown in the course of performing naming and directory operations. The JNDI exceptions are listed in Table 5.16.
The root of this class hierarchy is NamingException. Programs interested in dealing with a particular exception can catch the corresponding subclass of the exception. Otherwise, programs should catch NamingException.
| Table 5.15 Schema-Related Methods | |
| METHOD | USE |
|---|---|
| Schema methods defined in DirContext | |
| DirContext getSchema(Name name) | Returns the schema associated with the named object. |
| DirContext getSchema(String name) | Returns the schema associated with the named object. |
| DirContext getSchemaClassDefinition(Name name) | Returns the schema object class definition for the named object. This object defines how the objects are actually represented in the directory. |
| DirContext getSchemaClassDefinition(String name) | Returns the schema object class definition for the named object. This object defines how the objects are actually represented in the directory. |
| Schema methods defined in Attribute | |
| DirContext getAttributeDefinition() | Returns the attributes schema definition. |
| DirContext getAttributeSyntaxDefinition() | Returns the syntax definition associated with the attribute. This is the directory-dependent attribute description rather than the Java description of the attribute. For example, a Java object attribute might have a syntax definition of money. |
| Previous | Table of Contents | Next |