for (Field field : cls.getDeclaredFields()) {
if (!ReflectionUtil.isAnnotationPresent(field, ExternalResource.class)) {
continue;
}
ExternalResource era = ReflectionUtil.getAnnotation(field, ExternalResource.class);
// Get the resource key. If it is a nested resource, also get the prefix.
String key = era.key();
if (key.length() == 0) {
key = field.getName();
}
if (object instanceof ExternalResourceAware) {
String prefix = ((ExternalResourceAware) object).getResourceName();
if (prefix != null) {
key = prefix + PREFIX_SEPARATOR + key;
}
}
// Obtain the resource
Object value = getResourceObject(context, key);
if (value instanceof ExternalResourceLocator) {
value = ((ExternalResourceLocator) value).getResource();
}
// Sanity checks
if (value == null && era.mandatory()) {
throw new ResourceInitializationException(new IllegalStateException("Mandatory resource ["
+ key + "] is not set on [" + baseCls + "]"));
}
// Now record the setting and optionally apply it to the given