Looking Up Objects in a JNDI Context
by, 07-07-2012 at 04:12 PM (505 Views)
By name retrieval of an object from naming or directory system is known as looking up object. This is lookup() methodís job. Lookup performance is considered analogous to obtain a friendís number from some phone book by his name. JNDI could be used so that to look up or retrieve EJB components from remote object or application server, from remote ďRMIĒ registry.
When lookup() is called, childís name is specified of the required context.A java.lang.Object is returned by lookup() which presents child. How it is done is represented here:
An object is retrieved by calling lookup() from naming system. These objects java representation is determined by the JNDI service provider and there is no way to affect the decision of provider. It depends at the naming system as well as the providerís design that whether Context would be implemented or not by the retrieved object. E.g. if Sun filesystem provider of Sun is used and directory is the current context, java.io.File instance is returned when child is looked up.Java Code:Object obj = initialContext.lookup(name);
Instance of RefFSContext or FSContext is returned when directory is looked up. Both of them would be implementing Context. Let us say for example when NDS provider of Novell is used and current context used is the tree of NDS. If an organization is looked up, OrganizationDirContext is gotten back which will be implementing Novell's NdsObject and bothContext interface. Class which you obtain from lookup() would be depending upon the implementation of service provider.