JndiHelper Class

com.bea.p13n.util
JndiHelper Class

public class JndiHelper

    extends Object

Hierarchy
Object
  JndiHelper

Constructor Summary

JndiHelper()

 

Method Summary

public static Context
getContext()
Returns a reference to an InitialContext object.
public static Object
lookupNarrow(String lookupName, Class lookupClass)
Convenience method for getting a remote JNDI reference to an object.
 
Methods from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
   

Constructor Detail

JndiHelper

public JndiHelper()
 

Method Detail

getContext() Method

public static Context getContext()
throws NamingException
Returns a reference to an InitialContext object. This method is functionally equivalent to: "new InitialContext()", but the use of this method allows for centralized configuration and caching strategies.

Returns

ctx The Context reference

Exceptions

NamingException
if InitialContext cannot be obtained

lookupNarrow(String, Class) Method

public static Object lookupNarrow(String lookupName, 
                                  Class lookupClass)
throws NamingException, ClassCastException
Convenience method for getting a remote JNDI reference to an object. This will mostly be used to locate a remote EJB's home interface, but is generic to allow location of any JNDI-bound object.

The code this executes looks like:

    PortableRemoteObject.narrow(
      JndiHelper.getContext().lookup(lookupName),
      lookupClass);
  

Parameters

lookupName
The JNDI name of the object to locate
lookupClass
The desired class type

Returns

An object which can be cast to the desired type

Exceptions

NamingException
If the lookup() call fails
ClassCastException
If lookupName cannot be cast to lookupClass

Related Topics

PortableRemoteObject.narrow(Object, Class)