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 lesson contains descriptions of the Reference 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 whose type is "URL" and whose contents is the URL string.
Here is an example of a reference to a file system context.You can then bind this reference in another naming system, such as the LDAP:// Create the file system reference Reference fsRef = new Reference("javax.naming.Context", new StringRefAddr("URL", "file:/tmp"));The LDAP and file system are now federated.ldapCtx.bind("cn=fs", fsRef);
Next, you supply a name to the LDAP service provider that spans both the LDAP naming system and the file system: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".Object obj = ldapCtx.lookup("cn=fs/tutorial/report.txt");
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() and DirectoryManager.getContinuationDirContext(), which are explained in the Building a Service Provider 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".