Java Naming and Directory Interface

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

The JNDI API is used by the Java RMI and J2EE APIs to lookup 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:

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 Strings are the most commonly used way of naming an object. A name is bound to an object in the directory. This is done 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 lookup 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.
args.put( Context.INITIAL_CONTEXT_FACTORY, "com.jnidprovider.TheirContextFactory");
//The next argument is the URL specifying where the data store is:
args.put( Context.PROVIDER_URL, "http://jndiprovider-database" );
//You may also have to provide security creditials
//next you create the initial context
Context myCurrentContext = new InitialContext( args );

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

Object reference = myCurrentContext.lookup( "com.mydomain.MyBean" );
//this step is needed for EJBs.
MyBean myBean = (MyBean) PortableRemoteObject.narrow( ref, 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.

See [ftp://ftp.javasoft.com/docs/j2se1.3/jndiexecsumm.pdf]

Navigation

  • Art and Cultures
    • Art (https://academickids.com/encyclopedia/index.php/Art)
    • Architecture (https://academickids.com/encyclopedia/index.php/Architecture)
    • Cultures (https://www.academickids.com/encyclopedia/index.php/Cultures)
    • Music (https://www.academickids.com/encyclopedia/index.php/Music)
    • Musical Instruments (http://academickids.com/encyclopedia/index.php/List_of_musical_instruments)
  • Biographies (http://www.academickids.com/encyclopedia/index.php/Biographies)
  • Clipart (http://www.academickids.com/encyclopedia/index.php/Clipart)
  • Geography (http://www.academickids.com/encyclopedia/index.php/Geography)
    • Countries of the World (http://www.academickids.com/encyclopedia/index.php/Countries)
    • Maps (http://www.academickids.com/encyclopedia/index.php/Maps)
    • Flags (http://www.academickids.com/encyclopedia/index.php/Flags)
    • Continents (http://www.academickids.com/encyclopedia/index.php/Continents)
  • History (http://www.academickids.com/encyclopedia/index.php/History)
    • Ancient Civilizations (http://www.academickids.com/encyclopedia/index.php/Ancient_Civilizations)
    • Industrial Revolution (http://www.academickids.com/encyclopedia/index.php/Industrial_Revolution)
    • Middle Ages (http://www.academickids.com/encyclopedia/index.php/Middle_Ages)
    • Prehistory (http://www.academickids.com/encyclopedia/index.php/Prehistory)
    • Renaissance (http://www.academickids.com/encyclopedia/index.php/Renaissance)
    • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
    • United States (http://www.academickids.com/encyclopedia/index.php/United_States)
    • Wars (http://www.academickids.com/encyclopedia/index.php/Wars)
    • World History (http://www.academickids.com/encyclopedia/index.php/History_of_the_world)
  • Human Body (http://www.academickids.com/encyclopedia/index.php/Human_Body)
  • Mathematics (http://www.academickids.com/encyclopedia/index.php/Mathematics)
  • Reference (http://www.academickids.com/encyclopedia/index.php/Reference)
  • Science (http://www.academickids.com/encyclopedia/index.php/Science)
    • Animals (http://www.academickids.com/encyclopedia/index.php/Animals)
    • Aviation (http://www.academickids.com/encyclopedia/index.php/Aviation)
    • Dinosaurs (http://www.academickids.com/encyclopedia/index.php/Dinosaurs)
    • Earth (http://www.academickids.com/encyclopedia/index.php/Earth)
    • Inventions (http://www.academickids.com/encyclopedia/index.php/Inventions)
    • Physical Science (http://www.academickids.com/encyclopedia/index.php/Physical_Science)
    • Plants (http://www.academickids.com/encyclopedia/index.php/Plants)
    • Scientists (http://www.academickids.com/encyclopedia/index.php/Scientists)
  • Social Studies (http://www.academickids.com/encyclopedia/index.php/Social_Studies)
    • Anthropology (http://www.academickids.com/encyclopedia/index.php/Anthropology)
    • Economics (http://www.academickids.com/encyclopedia/index.php/Economics)
    • Government (http://www.academickids.com/encyclopedia/index.php/Government)
    • Religion (http://www.academickids.com/encyclopedia/index.php/Religion)
    • Holidays (http://www.academickids.com/encyclopedia/index.php/Holidays)
  • Space and Astronomy
    • Solar System (http://www.academickids.com/encyclopedia/index.php/Solar_System)
    • Planets (http://www.academickids.com/encyclopedia/index.php/Planets)
  • Sports (http://www.academickids.com/encyclopedia/index.php/Sports)
  • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
  • Weather (http://www.academickids.com/encyclopedia/index.php/Weather)
  • US States (http://www.academickids.com/encyclopedia/index.php/US_States)

Information

  • Home Page (http://academickids.com/encyclopedia/index.php)
  • Contact Us (http://www.academickids.com/encyclopedia/index.php/Contactus)

  • Clip Art (http://classroomclipart.com)
Toolbox
Personal tools