JndiMethodInjectorpublic class JndiMethodInjector extends Object implements Injector, PojoInjector
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.Class | getInjectionClass()
return setMethod.getParameterTypes()[0];
| public void | inject(org.jboss.ejb3.BeanContext bctx)
inject(bctx, bctx.getInstance());
| public void | inject(org.jboss.ejb3.BeanContext bctx, java.lang.Object instance)
inject(instance);
| public void | inject(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.Object | lookup(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;
|
|