Previous | Next | Trail Map | Beyond the Basics | URLs

URLs as References for Federation

Federation is the process of "hooking" together naming systems so that the aggregate system can process composite names. One basic means by which you federate systems is to bind the reference of one naming system in a context in another naming system. The Storing Objects in the Directory (in the Java Objects and the Directory trail) lesson contains descriptions of the Reference(in the API reference documentation) class and how to store and read references from the directory.

The contents of a reference used for federation is unrestricted, but a useful and common type of reference is one that contains a URL string. You can create a Reference for a URL string by creating a StringRefAddr(in the API reference documentation) whose type is "URL" and whose contents is the URL string.

Here is an example of a reference to a file system context.

// Create the file system reference
Reference fsRef = new Reference("javax.naming.Context", 
    new StringRefAddr("URL", "file:/tmp"));
You can then bind this reference in another naming system, such as the LDAP:
ldapCtx.bind("cn=fs", fsRef);
The LDAP and file system are now federated.

Next, you supply a name to the LDAP service provider that spans both the LDAP naming system and the file system:

Object obj = ldapCtx.lookup("cn=fs/tutorial/report.txt");
Although the name "cn=fs" is in the LDAP naming system, it is naming an object in the file system, the object (context) named by the URL string "file:/tmp".

When the LDAP service provider processes the "cn=fs" entry, it asks the JNDI to return the context identified by that entry so that it can continue the operation. The service provider does this by using NamingManager.getContinuationContext()(in the API reference documentation) and DirectoryManager.getContinuationDirContext()(in the API reference documentation), which are explained in the Building a Service Provider (in the Building a Service Provider trail) trail. The JNDI, when given a reference that contains a "URL" StringRefAddr and no factory class name, will turn the URL string in the reference into a context by using the same algorithm used for locating a URL context implementation, as explained in the URLs as Names to the Initial Context section of this lesson. In the previous example, the JNDI uses the file URL context implementation to process the URL string "file:/tmp". It then uses the resulting context to process the remainder of the name, "tutorial/report.txt".

Previous | Next | Trail Map | Beyond the Basics | URLs