Previous | Next | Trail Map | Java Objects and the Directory | Object Factories

Interaction Between Object Factories and Service Providers

A service providers acts as the go-between for the application and the directory when the application stores or retrieves Java objects from the directory. When you write a service provider, you need to perform this go-between role by following the rules outlined for reading objects from the directory.

The following detailed description is intended for developers writing service providers. The insight it offers into the go-between role of service providers might also interest API users.

Relevant Methods

When returning objects to the JNDI client application, the service provider should use the guidelines described in this section. An object can be returned by using one of the following methods:

Framework Support

A service provider should use object factories configured with the provider and application. This allows the provider to be customized to support arbitrary types of objects (for which a corresponding object factory is available).

The JNDI framework provides utility methods that service providers can use to access object factories. A provider that implements only the Context (in the API reference documentation) interface should use NamingManager.getObjectInstance() (in the API reference documentation). A service provider that implements the DirContext (in the API reference documentation) interface should use DirectoryManager.getObjectInstance() (in the API reference documentation). These methods interact with the object factories to produce a Java object representing the information in the directory. Which object factories are used depends on the object read from the directory. If the object is a reference, then these methods use the object factory class named in the reference. If the reference contains a URL, then these methods use the corresponding URL context factory. Otherwise, they traverse the list of object factories specified in the Context.OBJECT_FACTORIES(in the API reference documentation) environment property and the provider resource file and try to find a factory that yields a non-null answer. (See the Beyond the Basics (in the Beyond the Basics trail) trail for details about environment properties and the provider resource file.)


As explained in the Other Uses section of this lesson, object factories also play a role in federation. How a service provider uses object factories to support federation is described in the Building a Service Provider (in the Building a Service Provider trail) trail.

Previous | Next | Trail Map | Java Objects and the Directory | Object Factories