Copyright (C) 2000-2012 |
Whole document tree The Java Naming and Directory InterfaceTM technology (JNDI) provides a unified interface to multiple naming and directory services. As part of the Java enterprise API set, JNDI enables seamless connectivity to heterogeneous enterprise naming and directory services. Developers can now build powerful and portable directory-enabled Java applications using this industry-standard interface.
Technical OverviewDirectory services play a vital role in Intranets and Internets by providing access to a variety of information about users, machines, networks, services, and applications. By its very nature, a directory service incorporates a naming facility for providi ng human understandable namespaces that characterize the arrangement and identification of the various entities. The computing environment of an enterprise typically consists of several naming facilities often representing different parts of a composite namespace. For example, the Internet Domain Name System (DNS) may be used as the top-level naming facilit y for different organizations within an enterprise. The organizations themselves may use a directory service such as LDAP or NDS or NIS. From a user's perspective, there is one namespace consisting of composite names. URLs are examples of composite names because they span namespaces of multiple naming facilities. Applications which use directory services must support this user perspective. Many Java application developers can benefit from a directory service API that is not only independent of the particular directory or naming service implementation, but also enables seamless access to directory objects through multiple naming facilities. In fact, an application can attach its own objects to the namespace. Such a facility enables any Java application to discover and retrieve objects of any type. JNDI provides directory and naming functionality to Java applications. It is defined to be independent of any specific directory service implementation. Thus, a variety of directories, new and existing ones in the installed base, can be a ccessed in a common way. JNDI also defines a service provider's interface which allows various directory and naming service drivers to be plugged in. ExamplesHere are two examples to briefly illustrate some of the more commonly used features of JNDI. An application that wants to access a printer needs the corresponding printer object. This is simply done as follows: prt = (Printer) building7.lookup("puffin"); prt.print(document);
where JNDI does all the work of locating the information needed to construct the printer object. As another example, an application that wants to find a person's phone numbers, which are stored in the organization's directory, can simply do: String[] attrs = {"workPhone", "cellPhone", "faxNumber"}; bobsPhones = directory.getAttributes("cn=Bob,o=Widget,c=US", attrs); If there may be several Bobs in the Widget organization, the application can search the organization's directory to find the right Bob as follows: bob = directory.search("o=Widget,c=US","(cn=Bob)", controls); Other application examples include access to security credentials stored in an enterprise-wide directory service, access to electronic mail addresses, and access to addresses of a variety of existing services such as databases, network file systems, etc. Overview of InterfacesThe Naming Interface - javax.naming
Printer printer = (Printer) ctx.lookup("treekiller"); printer.print(report); The application is not exposed to any naming service implementation. In fact, a new type of naming service can be introduced without requiring the application to be modified or even disrupted if it is running. The Directory Interface - javax.naming.directory
Directory Objects and Attributes. The
Directory Objects as Naming Context. The
Searches. The The Event Interface - javax.naming.event
Naming Events. The
Naming Listeners. A The LDAP Interface - javax.naming.ldap
The The Service Provider Interface - javax.naming.spiThe JNDI SPI provides the means by which different naming/directory service providers can develop and hook up their implementations so that the corresponding services are accessible from applications that use JNDI. In add ition, because JNDI allows specification of names that span multiple namespaces, if one service provider implementation needs to interact with another in order to complete an operation, the SPI provides methods that allow different provid er implementations to cooperate to complete client JNDI operations. http://java.sun.com/jndi
Copyright © 1999, Sun Microsystems, Inc. All rights reserved. |