this.configurationDocumentation = configurationDocumentation;
}
void assignConfiguration(Object obj, Field field, Map<String, String> contextOverrides) throws Exception
{
Configuration configuration = field.getAnnotation(Configuration.class);
String configurationName = configuration.value();
ConfigurationKey key = new ConfigurationKey(configurationName, KeyParser.parse(configurationName, contextOverrides));
Object value = null;
boolean has = configurationProvider.has(key);
if ( has )
{
try
{
if ( Supplier.class.isAssignableFrom(field.getType()) )
{
ParameterizedType type = (ParameterizedType)field.getGenericType();
Type actualType = type.getActualTypeArguments()[0];
Class<?> actualClass;
if (actualType instanceof Class) {
actualClass = (Class<?>) actualType;
} else if (actualType instanceof ParameterizedType) {
actualClass = (Class<?>) ((ParameterizedType) actualType).getRawType();
} else {
throw new UnsupportedOperationException("Supplier parameter type " + actualType
+ " not supported (" + field.getName() + ")");
}
Supplier<?> current = (Supplier<?>)field.get(obj);
value = getConfigurationSupplier(field, key, actualClass, current);
if ( value == null )
{
log.error("Field type not supported: " + actualClass + " (" + field.getName() + ")");
field = null;
}
}
else
{
Supplier<?> supplier = getConfigurationSupplier(field, key, field.getType(), Suppliers.ofInstance(field.get(obj)));
if ( supplier == null )
{
log.error("Field type not supported: " + field.getType() + " (" + field.getName() + ")");
field = null;
}
else
{
value = supplier.get();
}
}
}
catch ( IllegalArgumentException e )
{
ignoreTypeMismtachIfConfigured(configuration, configurationName, e);
field = null;
}
catch ( ConversionException e )
{
ignoreTypeMismtachIfConfigured(configuration, configurationName, e);
field = null;
}
}
if ( field != null )
{
String defaultValue;
if ( Supplier.class.isAssignableFrom(field.getType()) )
{
defaultValue = String.valueOf(((Supplier<?>)field.get(obj)).get());
}
else
{
defaultValue = String.valueOf(field.get(obj));
}
String documentationValue;
if ( has )
{
field.set(obj, value);
documentationValue = String.valueOf(value);
if ( Supplier.class.isAssignableFrom(field.getType()) )
{
documentationValue = String.valueOf(((Supplier<?>)value).get());
}
else
{
documentationValue = String.valueOf(documentationValue);
}
}
else
{
documentationValue = "";
}
configurationDocumentation.registerConfiguration(field, configurationName, has, defaultValue, documentationValue, configuration.documentation());
}
}