Previous | Next | Trail Map | Building a Service Provider | Adding Directory Support

Hybrid Naming and Directory Operations

The DirContext(in the API reference documentation) interface contains the following methods (plus their java.lang.String overloads) that involve both updating the namespace and adding attributes: How an API user uses of these methods is discussed in the Directory Operations (in the Basics trail) lesson.

bind() and rebind() can be used to bind a name as follows:

Depending on the underlying directory service, a context implementation might support one or all of these. If an implementation supports all three, then it should be ready to accept null as the object or Attributes(in the API reference documentation) parameter. Both parameters may be null in the same call if the context implementation supports adding only a name to the namespace, without also adding an associated object or attributes.

If the underlying directory supports storing only attributes, then the context implementation can decide whether it wants to support binding non-null objects and, if so, how to map Java objects to attributes. See the Representation in the Directory (in the Java Objects and the Directory trail) lesson for a discussion of object representations. See also later in this lesson for a description of how to make the context implementation extensible in the types of objects that it will accept.

The implementation of these methods in particular depends on the attribute model of the underlying directory service. This is because one method invocation might involve both updating the namespace and adding attributes. If at all possible, the namespace update and attribute addition should occur atomically. Again, whether this is achievable depends on the facilities provided by the underlying directory service. An actual implementation might need to do no more than pass the name and request to the underlying directory service for processing.


Implementation Tip: The semantics of rebind() requires that the existing object's attributes be left untouched if the input Attributes parameter is null.

Implications on Pure Naming Operations

The context implementation not only must provide definitions for createSubcontext(), bind(), and rebind(). It also must ensure that the implementations of the pure naming methods take attributes into account. Following are the pure naming methods.

For example, you might implement these pure naming methods in terms of their counterparts that take an Attributes parameter. Here is a sample implementation of bind(Name name, Object obj)(in the API reference documentation), written in terms of bind(Name name, Object obj, Attributes attrs)(in the API reference documentation).
public void bind(Name name, Object obj) throws NamingException {
    bind(name, obj, null);
}
unbind(Name name)(in the API reference documentation) and destroySubcontext(Name name)(in the API reference documentation) need to get rid of the named object's attributes in addition to removing the object from the namespace.


Previous | Next | Trail Map | Building a Service Provider | Adding Directory Support