Previous | Next | Trail Map | Java Objects and the Directory | Contents

Storing Objects in the Directory

Applications and services can use the directory in different ways to store and locate objects. For example, an application might store (a copy of) the object itself, a reference to an object, or attributes that describe the object. In general terms, a JavaTM object's serialized form contains the object's state and an object's reference is a compact representation of addressing information that can be used to contact the object. Some examples are given in the Naming Concepts (in the Getting Started trail) lesson. An object's attributes are properties that are used to describe the object; attributes might include addressing and/or state information.

Which of these three ways to use depends on the application/system that is being built and how it needs to interoperate with other applications and systems that will share the objects stored in the directory. Another factor is the support provided by the service provider and the underlying directory service.

Programmatically, all applications use one of the following methods when storing objects in the directory:

The application passes the object that it wants to store to one of these methods. Then, depending on the types of objects that the service provider supports, the object will be transformed into a representation acceptable to the underlying directory service.

This lesson shows how to create different types of objects and store them in the directory.

Before you go on: The examples in this lesson use the LDAP directory. The initial context used in these examples is initialized using the following environment properties.
// Set up environment for creating the initial context
Hashtable env = new Hashtable();
env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial");

Schema: To run these examples successfully, you must either turn off schema-checking in the server or add the Java schema and the CORBA schema that accompany this tutorial to the server. Both of these tasks are typically performed by the directory server's administrator. See the Preparations (in the Basics trail) lesson for more information.

Software Requirements: In addition to the software requirements listed in the Preparations (in the Basics trail) lesson, you also need the following archive files when using the examples related to RMI and CORBA: ldapbp.jar, and rmiregistry.jar. The ldapbp.jar can be downloaded as part of the LDAP service provider from the JNDI Web site. rmiregistry.jar is available as part of the Java 2 SDK, v1.3, so, if you are using that SDK, then you won't need to add rmiregistry.jar separately. Otherwise, you can download it from the JNDI Web site.

To try the CORBA and RMI/IIOP examples, you need the CORBA classes. If you are using the Java 2 SDK, v1.2 or higher releases, then you already have those classes. Otherwise, you need to install the Java IDL, a version of which comes with the RMI-IIOP Standard Extension.

If you are not using the Java 2 SDK, v1.3 and you want to try the RMI example that uses IIOP, then you need to install the RMI-IIOP Standard Extension.

OpenLDAP: In versions of the LDAP provider prior to the Java 2 SDK, v1.4, these examples will not work against the OpenLDAP directory server because these versions of the LDAP provider do not include the new entry's relative distinguished name (RDN) in the set of attributes to add. To workaround the problem, you must modify the examples to use DirContext.bind()(in the API reference documentation) or DirContext.rebind()(in the API reference documentation) and supply the RDN of the entry as an attribute in the Attributes parameter.

Windows Active Directory: Context.rebind()(in the API reference documentation) and DirContext.rebind()(in the API reference documentation) do not work against Active Directory because these methods work by reading the attributes of the entry to be updated, removing the entry, and then adding a new entry that contains the modified attributes. Active Directory returns some attributes that cannot be set by the user, causing the final addition step to fail. The workaround for this problem is to use DirContext.getAttributes()(in the API reference documentation) to obtain and save the attributes that you want to keep. Then, remove the entry and add it back with the saved attributes (and any others that you want to add) using DirContext.bind()(in the API reference documentation).

Previous | Next | Trail Map | Java Objects and the Directory | Contents