Object Factories
Other Uses
The object factory is actually a general mechanism used throughout the JNDI. In this lesson, object factories are 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 trail and the Building a Service Provider trail.
Federation and Context Factories
You saw how an object can be bound into the directory. 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 .
The file system in this example is called the nns (see the Federation lesson). Just as the nature of the information stored in a directory about a Java object can vary (from a reference to attributes to a serialized object), so can the nature of the information stored in a directory about the nns. In the file system example, you might store a URL that identifies the file system's server and protocol information as a JNDI reference.
By storing nns information in a directory, you are federating. naming systems, thereby allowing them to resolve composite names. See the Federation lesson for details.
URL Context Factories A special kind of context factory is a URL context factory, which creates contexts for resolving URLs or contexts whose locations are 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 , the remote object is stored in the directory as a reference that contains an RMI URL. When the object is looked up from the directory, the JNDI uses an RMI URL context factory to look up and return the object from the RMI registry named in the URL.
Object Factories