Search: in
Java Naming and Directory Interface
Java Naming and Directory Interface Encyclopedia
  Tutorials     Encyclopedia     Dictionary     Directory  
Java_Naming_and_Directory_Interface Email this to a friend      Java_Naming_and_Directory_Interface

Java Naming and Directory Interface

The Java Naming and Directory Interface (JNDI) is an API for directory service that allows clients to discover and lookup data and objects via a name. Like all Java APIs that interface with host systems, JNDI is independent of the underlying implementation. Additionally, it specifies a service provider interface (SPI) that allows directory service implementations to be plugged into the framework. The implementations may make use of a server, a flat file, or a database; the choice is up to the vendor.

Contents


Background

The JNDI API is used by the Java RMI and Java EE APIs to look up objects in a network. Jini has its own lookup service and does not use the JNDI API.

The API provides:

  • a mechanism to bind an object to a name
  • a directory lookup interface that allows general queries
  • an event interface that allows clients to determine when directory entries have been modified
  • LDAP extensions to support the additional capabilities of an LDAP service.

The SPI portion allows support for practically any kind of naming or directory service including:

The JNDI specification was first released by Sun Microsystems on March 10, 1997.http://www.sun.com/smi/Press/sunflash/1997-03/sunflash.970310.10204.html As of 2006, the current version is JNDI 1.2

Basic lookup

JNDI organizes its names into a hierarchy. A name can be any string such as "com.mydomain.ejb.MyBean". A name can also be an object that supports the Name interface, however a string is the most common way to name an object. A name is bound to an object in the directory by storing either the object or a reference to the object in the directory service identified by the name.

The JNDI API defines a context that specifies where to look for an object. The initial context is typically used as a starting point.

In the simplest case, an initial context must be created using the specific implementation and extra parameters required by the implementation. The initial context will be used to look up a name. The initial context is analogous to the root or top of a directory tree for a file system. Below is an example of creating an initial context:

Hashtable args = new Hashtable();
//first you must specify the context factory.
//This is how you choose between jboss implementation
// vs. an implementation from Sun or other vendors.
args.put( Context.INITIAL_CONTEXT_FACTORY, "com.jndiprovider.TheirContextFactory" );
//The next argument is the URL specifying where the data store is:
args.put( Context.PROVIDER_URL, "jndiprovider-database" );
//You may also have to provide security credentials
//next you create the initial context
Context myCurrentContext = new InitialContext( args );

A context is then used to look up previously bound names in that context. For example:

Object reference = myCurrentContext.lookup( "com.mydomain.MyBean" );
//this step is needed for EJB beans.
MyBean myBean = (MyBean) PortableRemoteObject.narrow( reference, MyBean.class );

Searching

Attributes may be attached to special entries called directories. Directories are required in order to enable searching for objects by their associated attributes. Directories are a type of context, they restrict the name space much like a directory structure on a file system does.

External links

ca:Java Naming and Directory Interface da:JNDI de:Java Naming and Directory Interface es:JNDI fr:JNDI ko:JNDI ja:Java Naming and Directory Interface pl:JNDI pt:JNDI sv:JNDI zh:JNDI





Source: Wikipedia | The above article is available under the GNU FDL. | Edit this article



Related Links in Java Naming and Directory Interface

Search for Java Naming and Directory Interface in Tutorials
Search for Java Naming and Directory Interface in Encyclopedia
Search for Java Naming and Directory Interface in Dictionary
Search for Java Naming and Directory Interface in Open Directory
Search for Java Naming and Directory Interface in Store
Search for Java Naming and Directory Interface in PriceGig



Help build the largest human-edited directory on the web.
Submit a Site - Open Directory Project - Become an Editor

Advertisement

Advertisement



Java Naming and Directory Interface
Java_Naming_and_Directory_Interface top Java_Naming_and_Directory_Interface

Home - Add TutorGig to Your Site - Disclaimer

©2008-2009 TutorGig.com. All Rights Reserved. Privacy Statement