JndiFieldInjectorpublic class JndiFieldInjector extends Object implements Injector, PojoInjector
Fields Summary |
---|
private static final Logger | log | private Field | field | private String | jndiName | private Context | ctx |
Constructors Summary |
---|
public JndiFieldInjector(Field field, String jndiName, Context ctx)
this.field = field;
this.field.setAccessible(true);
this.jndiName = jndiName;
this.ctx = ctx;
| public JndiFieldInjector(Field field, Context ctx)
this(field, field.getName(), ctx);
|
Methods Summary |
---|
public java.lang.reflect.Field | getField()
return field;
| public java.lang.Class | getInjectionClass()
return field.getType();
| 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, field.getType());
try
{
field.set(instance, dependency);
}
catch (IllegalArgumentException e)
{
String type = "UNKNOWN";
String interfaces = "";
if (dependency != null)
{
type = dependency.getClass().getName();
Class[] intfs = dependency.getClass().getInterfaces();
for (Class intf : intfs) interfaces += ", " + intf.getName();
}
throw new RuntimeException("Non matching type for inject of field: " + field + " for type: " + type + " of jndiName " + jndiName + "\nintfs: " + interfaces, e);
}
catch (IllegalAccessException e)
{
throw new RuntimeException(e);
}
| protected java.lang.Object | lookup(java.lang.String jndiName, java.lang.Class field)
Object dependency = null;
try
{
dependency = ctx.lookup(jndiName);
if (dependency instanceof javax.xml.rpc.Service && !field.isAssignableFrom(javax.xml.rpc.Service.class))
{
javax.xml.rpc.Service service = (javax.xml.rpc.Service)dependency;
dependency = service.getPort(field);
}
}
catch (NamingException e)
{
e.printStackTrace();
throw new RuntimeException("Unable to inject jndi dependency: " + jndiName + " into field " + field, e);
}
catch (javax.xml.rpc.ServiceException e)
{
e.printStackTrace();
throw new RuntimeException("Unable to inject jndi webservice dependency: " + jndiName + " into field " + field, e);
}
return dependency;
| public java.lang.String | toString()
return super.toString() + "{field=" + field + ",jndiName=" + jndiName + "}";
|
|