More on JNDI Names

JNDI has to support different naming conventions for different Service Providers in the most transparent manner possible. Generally, programmers will specify JNDI names as strings, but a little understanding of how JNDI interprets bound names will help circumvent many simple problems that can occur when using names.

Special Characters

JNDI applies minimal interpretation to names specified as String objects. JNDI uses the forward slash character (/) as a name separator to provide a simple name hierarchy called a Composite Name. It is conventional for these composite names to be used to group related names (such as plumbers in the phone book). As an example, JDBC data sources take names of jdbc/XXX and EJBs the form ejb/XXX. While this is only a convention, it does help separate different sorts of named objects within the JNDI name space.

Composite and Compound Names

Composite names can span different naming systems. An LDAP name can combine with a file system name to get a composite name:

cn=Martin Bond, ou=Authors, o=SAMS, c=us/agency/agency.ldif

Here a filename (agency/agency.ldif) is appended to an LDAP name. How JNDI interprets this is up to the individual Service Provider.

Incidentally, JNDI calls structured names like the DNS and LDAP compound names. JNDI does not interpret compound names, but simply passes them through to the Service Provider.

Besides forward slash (/), JNDI also treats backslash (), single quote ('), and double quote (") characters as special. If a compound name or a component of a name contains any of these characters, they must be escaped using the backslash character ().

If the underlying Service Provider uses the forward slash as a name separator (for example, the CORBA name service), there appears to be a conflict between JNDI and the Service Provider. In practice, there is unlikely to be a problem because JNDI recognizes two sorts of name separation—weak and strong. JNDI always passes the entire name to the Service provider. A strong name separation implementation (such as LDAP or DNS) simply processes the first part of the composite name and returns the remainder to the JNDI Naming Manager to pass on to other name services. A weak name separation implementation will simply process the entire composite name.The COSNaming server used in the J2EE RI uses weak separation, as does the RMIRegistry naming service.

For those programmers who need to do more that use names to look up and bind objects, JNDI provides several classes for manipulating and parsing composite and compound names. The JNDI name support classes in the javax.naming package are Name, CompositeName, and CompoundName.

URLs

In certain contexts, JNDI recognizes a URL (Uniform Resource Locator). The primary use of URLs is to identify the JNDI server usually through the java.naming.provider.url property, as shown in the following:

java.naming.provider.url=ldap://localhost:389

You can also specify a URL as a parameter to the lookup() and bind() methods in the Context class. For example,

Context ic = new InitialContext();
Object obj = ic.lookup("ldap://localhost:389/cn=Winston,dc=my-domain,dc=com");

This overrides the default context and forces JNDI to perform the lookup against the specified server. You need to take care with this approach, because the class path must contain the necessary Service Provider classes, and these must be able to process the request bind or lookup operation. In practice, this means that the URL must use the same Service Provider classes as the initial context.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.73.127