Section 9.1. JNDI Architecture


9.1. JNDI Architecture

The architecture of JNDI is somewhat like the JDBC architecture in that both provide a standard protocol-independent API built on top of protocol-specific driver or provider implementations. This layer insulates an application from the actual data source it is using, so, for example, it doesn't matter whether the application is accessing an NDS or LDAP directory service.

The JNDI architecture includes both an application programming interface (API) and a service provider interface (SPI), as shown in Figure 9-1. A Java application uses the JNDI API to access naming and directory services, primarily through the Context and DirContext interfaces. The JNDI API is defined in the javax.naming and javax.naming.directory packages. Note that JNDI is a standard extension to the Java 2 platform; it is included in the core APIs starting with JDK 1.3. If you are using an earlier version of the Java environment, the JNDI API classes and various providers are also available separately at http://java.sun.com/products/jndi. This chapter covers JNDI Version 1.2, which is the version included in JDK 1.3, 1.4, and 1.5, and is a standard component in the J2EE 1.3 and 1.4 specifications.

Figure 9-1. The JNDI architecture


In order for an application to actually interact with a particular naming or directory service, there must be a JNDI service provider for that service. This is where the JNDI SPI comes in. A service provider is a set of classes that implements various JNDI interfaces for a specific naming or directory service, much as a JDBC driver implements various JDBC interfaces for a particular database system. The provider can also implement other interfaces that aren't part of JNDI, such as Novell's NdsObject interface.

The classes and interfaces in the javax.naming.spi package are of interest only to developers who are creating service providers. For instance, the NamingManager class defines methods for creating Context objects and otherwise controlling the operation of the underlying service provider. As an application programmer, you don't have to worry about the JNDI SPI. All you have to do is make sure that you have a service provider for each naming or directory service you want to use. Sun maintains a list of available service providers on the JNDI web page.



Java Enterprise in a Nutshell
Java Enterprise in a Nutshell (In a Nutshell (OReilly))
ISBN: 0596101422
EAN: 2147483647
Year: 2004
Pages: 269

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net