Java Reference
In-Depth Information
5.2.1. JNDI primer for EJB
In essence, JNDI is the JDBC of naming and directory services. Just as JDBC provides a
standard Java API to access all kinds of databases, JNDI standardizes naming and directory
service access. If you've ever used your computer's file system, you already know what a
naming and directory service is. A computer's file system is a basic directory service. You
can use the file system to browse and look up a file you have on your desktop. If you've
ever used a Lightweight Directory Access Protocol (LDAP) or Microsoft Active Directory
(AD) server, you're familiar with a more robust naming and directory service.
As figure 5.2 shows, JNDI provides a uniform abstraction over a number of different nam-
ing services, such as LDAP, Domain Naming System (DNS), Network Information Service
(NIS), Novell Directory Services (NDS), remote method invocation (RMI), Common Ob-
ject Request Broker Architecture (CORBA), and so on. Once you get an instance of a JNDI
context, you can use it to locate resources in any underlying naming service available to
the context. Under the hood, JNDI negotiates with each available naming service, giving
the service the name of the resource; then the service uses that name to figure out where
the resource actually resides.
Figure 5.2. JNDI provides a single unified API to access various naming services such as LDAP, DNS, NDS, NIS,
RMI, and CORBA. Any naming service with a JNDI SPI provider can be plugged into the API seamlessly.
As an analogy, think of JDBC. An SQL SELECT statement is the resource name. The data-
base server is the naming service, and JDBC is the standard API. When the SQL SELECT
is executed, the database server uses it to find the real resource (the data), which may really
reside in a linked table on a completely separate database server.
JNDI plays a vital role in Java EE, although it's largely hidden behind the scenes. JNDI is
used as the central repository for resources managed by the container. As a result, every
bean managed by the container is automatically registered with JNDI. In addition, a typical
 
Search WWH ::




Custom Search