| Adding Directory Support

## Hybrid Naming and Directory Operations

> The `DirContext` interface contains the following methods (plus their `java.lang.String` overloads) that involve both updating the namespace and adding attributes:
> - `createSubcontext(Name name, Attributes attrs)`
> - `bind(Name name, Object obj, Attributes attrs)`
> - `rebind(Name name, Object obj, Attributes attrs)`
> How an API user uses of these methods is discussed in the Directory Operations lesson.

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

> - To an object in the namespace
> - To a set of attributes
> - To both an object and a set of attributes
> 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` 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 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.

> - `createSubcontext(Name name)`
> - `destroySubcontext(Name name)`
> - `bind(Name name, Object obj)`
> - `rebind(Name name, Object obj)`
> - `unbind(Name name)`
> 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)`, written in terms of `bind(Name name, Object obj, Attributes attrs)`.

> >     public void bind(Name name, Object obj) throws NamingException {
> >         bind(name, obj, null);
> >     }

> `unbind(Name name)` and `destroySubcontext(Name name)` need to get rid of the named object's attributes in addition to removing the object from the namespace.

| Adding Directory Support