Retrieving an object by name from a naming system or
directory is called looking up the object. This
is the job of the
Context. Performing a lookup is
analogous to getting the number of a friend from a telephone book by
looking up his name. You can use JNDI to look up and retrieve an EJB
home interface from an application server or a remote object from a
remote RMI registry.
When you call
specify the name of the child of the
Context you want to find.
lookup() returns a
java.lang.Object that represents the child.
Here’s how we did it in the
Object obj = initialContext.lookup(name);
lookup() retrieves an
object from the underlying naming system. The JNDI service provider
determines the Java representation of these objects, and we have no
way of affecting the provider’s decision. Depending on the naming
system and the design of the provider, the object you retrieve may or
may not implement
example, if you use the Sun filesystem provider and your current
context is a directory, looking up a child that is a file returns an
up a directory, however, returns an instance of
RefFSContext, both of which implement
Context. As another example, say
you use Novell’s NDS provider and the current context is an NDS tree.
If you look up an organization, you get back an
OrganizationDirContext that implements both
Context and Novell’s
NdsObject interface. ...