org.yajul.jndi
Class JndiHelper

java.lang.Object
  extended by org.yajul.jndi.JndiHelper

public class JndiHelper
extends java.lang.Object

Helper functions for JNDI.
User: Joshua Davis Date: Sep 9, 2007 Time: 10:17:15 AM


Constructor Summary
JndiHelper()
           
 
Method Summary
static
<T> T
lookup(javax.naming.InitialContext context, java.lang.Class<T> clazz, java.lang.String name)
          Encapsulates the standard JNDI lookup calls for EJBs, etc.
 
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

lookup

public static <T> T lookup(javax.naming.InitialContext context,
                           java.lang.Class<T> clazz,
                           java.lang.String name)
Encapsulates the standard JNDI lookup calls for EJBs, etc. in a method that throws an uncheckeced exception. The typical use case would be inside an EAR where a failed lookup means some kind of unrecoverable deployment problem. That eliminates some of the redundant code sprinkled throughout an application.
This should not be used to replace EJB3 injection, but it does come in handy when there are EJB3 beans that have circular dependencies, which makes lookup (Service Locator pattern) necessary.

Parameters:
context - The initial context. Null to use the default new InitialContext()
clazz - the expected type of the object in JNDI. For an EJB, this will be the local interface class.
name - The JNDI name for the object, e.g. XxxDao/local or, XxxDao/Remote
Returns:
the JNDI object
Throws:
LookupException - if the lookup fails for any reason


Copyright © 2008. All Rights Reserved.