final Object instance, final Object value) throws ArchiveInjectionException {
// Value is obtained, set it
// Get Field from the class
JField jField = fieldMetadata.getJField();
Field field = null;
try {
field = clazz.getDeclaredField(jField.getName());
} catch (NoSuchFieldException e) {
throw new ArchiveInjectionException("Cannot get field '" + jField + "' on the class '" + clazz.getName() + "'", e);
}
// if instance is null, we're using static injection.
// But check that in this case, the field is a static field !
int modifier = field.getModifiers();
if (!Modifier.isStatic(modifier)) {
logger.error("The field ''{0}'' of the class ''{1}'' is not a static field and as the injection is being done in a static way, this field won't be defined !",
field, clazz);
return;
}
boolean accessible = field.isAccessible();
try {
// needs to be allowed to change value of the field
field.setAccessible(true);
// Set value
try {
field.set(instance, value);
} catch (IllegalAccessException e) {
throw new ArchiveInjectionException("Cannot set given value on the field '" + jField + "'.", e);
}
} finally {
// set back accessible attribute
field.setAccessible(accessible);
}
}