© 2005 BEA Systems, Inc.

com.bea.p13n.util
Class JndiHelper

java.lang.Object
  extended bycom.bea.p13n.util.JndiHelper

public class JndiHelper
extends Object


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

Constructor Detail

JndiHelper

public JndiHelper()
Method Detail

getContext

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
Throws:
NamingException - if InitialContext cannot be obtained

lookupNarrow

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
Throws:
NamingException - If the lookup() call fails
ClassCastException - If lookupName cannot be cast to lookupClass
See Also:
PortableRemoteObject.narrow(java.lang.Object, java.lang.Class)

© 2005 BEA Systems, Inc.

Copyright © 2005 BEA Systems, Inc. All Rights Reserved