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

Other Uses

The object factory is actually a general mechanism used throughout the JNDI. In this lesson, you've seen object factories used to transform information stored in the directory into Java objects that applications can use. And typically, these objects are objects that the application uses directly (for example, like a Person object or a Drink or Fruit object). The following discussion introduces you to other uses of object factories. It is intended as background information for API users. Developers of service providers can find full discussions of these topics in the Beyond the Basics (in the Beyond the Basics trail) and Building a Service Provider (in the Building a Service Provider trail) trails.

Federation and Context Factories

You saw how an object can be bound into the directory. Well what if the object happens to be the root of another naming system? In the LDAP, for example, you can bind an object that is the root of a file system. You can then supply an object factory whose role it is to convert the information stored in the LDAP directory about the file system into the root context of the file system. This type of object factory is called a context factory. Given information about the context object to create, a context factory will create and return an instance of Context (in the API reference documentation).

The file system in this example is referred to as the next naming system. Just as the nature of the information stored in a directory about a Java object can vary (from a reference to attributes to serialized object), so can the nature of the information stored in a directory about the next naming system. In the file system example, you might store a URL identifying the file system's server and protocol information as a JNDI reference.

By storing next naming system information in a directory, you are effectively "hooking together" naming systems. Hooking naming systems together so that they can resolve names that span from one naming system to the next is referred to as federation.

URL Context Factories

A special kind of context factory is a URL context factory, which creates contexts for resolving URLs or contexts whose location is specified by URLs. For example, an LDAP URL context factory can create a context for accepting arbitrary LDAP URLs. The same LDAP URL context factory can create a context identified by an LDAP URL; that context will then be able to resolve names relative to the location specified by the URL.

URL context factories are used for federation and are also used by the initial context to resolve and process requests for URLs. In fact, in the remote reference example (in the Java Objects and the Directory trail), the remote object is stored in the directory as a reference containing an "rmi" URL. When the object is looked up from the directory, JNDI uses an "rmi" URL context factory to look up and return the object from the RMI registry named in the URL.


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