final Field f = getField(target, clazz);
if( Modifier.isStatic(f.getModifiers()) &&
(instance != null) ) {
throw new InjectionException
("Illegal use of static field " + f +
" on class that only supports instance-based"
+ " injection");
}
if( (instance == null) &&
!Modifier.isStatic(f.getModifiers()) ) {
throw new InjectionException
("Injected field " + f +
" on Application Client class " + clazz +
" must be declared static");
}
if(_logger.isLoggable(Level.FINE)) {
_logger.fine("Injecting dependency with logical name "
+ next.getComponentEnvName() +
" into field " + f + " on class " +
clazz);
}
// Wrap actual value insertion in doPrivileged to
// allow for private/protected field access.
if( System.getSecurityManager() != null ) {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedExceptionAction() {
public java.lang.Object run() throws Exception {
f.set(instance, value);
return null;
}
});
} else {
f.set(instance, value);
}
} else if( target.isMethodInjectable() ) {
final Method m = getMethod(next, target, clazz);
if( Modifier.isStatic(m.getModifiers()) &&
(instance != null) ) {
throw new InjectionException
("Illegal use of static method " + m +
" on class that only supports instance-based"
+ " injection");
}
if( (instance == null) &&
!Modifier.isStatic(m.getModifiers()) ) {
throw new InjectionException
("Injected method " + m +
" on Application Client class " + clazz +
" must be declared static");
}
if(_logger.isLoggable(Level.FINE)) {
_logger.fine("Injecting dependency with logical name "
+ next.getComponentEnvName() +
" into method " + m + " on class " +
clazz);
}
if( System.getSecurityManager() != null ) {
// Wrap actual value insertion in doPrivileged to
// allow for private/protected field access.
java.security.AccessController.doPrivileged(
new java.security.PrivilegedExceptionAction() {
public java.lang.Object run() throws Exception {
m.invoke(instance, new Object[] { value });
return null;
}});
} else {
m.invoke(instance, new Object[] { value });
}
}
}
} catch(Throwable t) {
String msg = "Exception attempting to inject "
+ next + " into " + clazz;
_logger.log(Level.FINE, msg, t);
InjectionException ie = new InjectionException(msg);
Throwable cause = (t instanceof InvocationTargetException) ?
((InvocationTargetException)t).getCause() : t;
ie.initCause( cause );
throw ie;
}
}
}