final Field f = getField(target, clazz);
if( Modifier.isStatic(f.getModifiers()) &&
(instance != null) ) {
throw new InjectionException(localStrings.getLocalString(
"injection-manager.illegal-use-of-static-field",
"Illegal use of static field on class that only supports instance-based injection: {0}",
f));
}
if( (instance == null) &&
!Modifier.isStatic(f.getModifiers()) ) {
throw new InjectionException(localStrings.getLocalString(
"injection-manager.appclient-injected-field-must-be-static",
"Injected field: {0} on Application Client class: {1} must be declared static",
f, clazz));
}
if(_logger.isLoggable(Level.FINE)) {
_logger.fine(localStrings.getLocalString(
"injection-manager.injecting-dependency-field",
"Injecting dependency with logical name: {0} into field: {1} on class: {2}",
next.getComponentEnvName(), f, 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(localStrings.getLocalString(
"injection-manager.illegal-use-of-static-method",
"Illegal use of static method on class that only supports instance-based injection: {0}",
m));
}
if( (instance == null) &&
!Modifier.isStatic(m.getModifiers()) ) {
throw new InjectionException(localStrings.getLocalString(
"injection-manager.appclient-injected-method-must-be-static",
"Injected method: {0} on Application Client class: {1} must be declared static",
m, clazz));
}
if(_logger.isLoggable(Level.FINE)) {
_logger.fine(localStrings.getLocalString(
"injection-manager.injecting-dependency-method",
"Injecting dependency with logical name: {0} into method: {1} on class: {2}",
next.getComponentEnvName(), m, 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) {
Throwable cause = (t instanceof InvocationTargetException) ?
((InvocationTargetException)t).getCause() : t;
String msg = localStrings.getLocalString(
"injection-manager.exception-to-inject",
"Exception attempting to inject {0} into {1}: {2}",
next, clazz, cause.getMessage());
_logger.log(Level.FINE, msg, t);
throw new InjectionException(msg, cause);
}
}
}