Download PDF Home History |  | API Search Feedback FAQ

> ## JNDI Naming

> In a distributed application, components need to access other components and resources such as databases. For example, a servlet might invoke remote methods on an enterprise bean that retrieves information from a database. In the J2EE platform, the Java Naming and Directory Interface (JNDI) naming service enables components to locate other components and resources. To locate a JDBC resource, for example, an enterprise bean invokes the JNDI `lookup` method. The JNDI naming service maintains a set of bindings that relate names to objects. The `lookup` method passes a JNDI name parameter and returns the related object.

> JNDI provides a naming context, which is a a set of name-to-object bindings. All naming operations are relative to a context. A name that is bound within a context is the JNDI name of the object. In Specifying a Resource Reference, for example, the JNDI name for the JDBC resource (or data source) is `jdbc/ejbTutorialDB`. A `Context` object provides the methods for binding names to objects, unbinding names from objects, renaming objects, and listing the bindings. JNDI also provides subcontext functionality. Much like a directory in a file system, a subcontext is a context within a context. This hierarchical structure permits better organization of information. For naming services that support subcontexts, the `Context` class also provides methods for creating and destroying subcontexts.

> For detailed information about JNDI, see The JNDI Tutorial:

>     http://java.sun.com/products/jndi/tutorial

> Table 31-1 describes JNDI subcontexts for connection factories in the Sun Java System Application Server Platform Edition 8.

> Table 31-1 JNDI Subcontexts for Connection Factories
> Resource Manager Type | Connection Factory Type | JNDI Subcontext
> --- | --- | ---
> JDBC | `javax.sql.DataSource` | `java:comp/env/jdbc`
> JMS | `javax.jms.TopicConnectionFactory` `javax.jms.QueueConnectionFactory` | `java:comp/env/jms`
> JavaMail | `javax.mail.Session` | `java:comp/env/mail`
> URL | `java.net.URL` | `java:comp/env/url`
> Connector | `javax.resource.cci.ConnectionFactory` | `java:comp/env/eis`
> JAXR Resource Adapter | `javax.xml.registry.ConnectionFactory` | `java:comp/env/eis/JAXR`

> Note: To avoid collisions with names of other enterprise resources in the JNDI namespace, and to avoid portability problems, all names in a J2EE application should begin with the string `java:comp/env`.

Download PDF Home History |  | API Search Feedback FAQ

All of the material in The J2EE(TM) 1.4 Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.