FileDocCategorySizeDatePackage
JndiMethodInjector.javaAPI DocJBoss 4.2.13522Fri Jul 13 20:53:46 BST 2007org.jboss.injection

JndiMethodInjector

public class JndiMethodInjector extends Object implements Injector, PojoInjector
Comment
author
Bill Burke
version
$Revision: 60233 $
deprecated
use JndiPropertyInjector

Fields Summary
private static final Logger
log
private Method
setMethod
private String
jndiName
private Context
ctx
Constructors Summary
public JndiMethodInjector(Method setMethod, String jndiName, Context ctx)


         
   
      this.setMethod = setMethod;
      setMethod.setAccessible(true);
      this.jndiName = jndiName;
      this.ctx = ctx;
   
Methods Summary
public java.lang.ClassgetInjectionClass()

      return setMethod.getParameterTypes()[0];
   
public voidinject(org.jboss.ejb3.BeanContext bctx)

      inject(bctx, bctx.getInstance());
   
public voidinject(org.jboss.ejb3.BeanContext bctx, java.lang.Object instance)

      inject(instance);
   
public voidinject(java.lang.Object instance)

      Object dependency = lookup(jndiName, setMethod.getParameterTypes()[0]);

      Object[] args = {dependency};
      try
      {
         setMethod.invoke(instance, args);
      }
      catch (IllegalAccessException e)
      {
         throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
      }
      catch (IllegalArgumentException e)
      {
         String type = "UNKNOWN";
         if (dependency != null) type = dependency.getClass().getName();
         throw new RuntimeException("Non matching type for @Inject of setter: " + setMethod + " for type: " + type, e);  //To change body of catch statement use Options | File Templates.
      }
      catch (InvocationTargetException e)
      {
         throw new RuntimeException(e.getCause());  //To change body of catch statement use Options | File Templates.
      }
   
protected java.lang.Objectlookup(java.lang.String jndiName, java.lang.Class param)

      Object dependency = null;
      
      try
      {
         dependency = ctx.lookup(jndiName);
      }
      catch (NamingException e)
      {
         e.printStackTrace();
         throw new RuntimeException("Unable to @Inject jndi dependency: " + jndiName + " into method " + setMethod, e);
      }
      return dependency;