use of org.apache.knox.gateway.config.Default in project knox by apache.
the class DefaultConfigurationInjector method injectMethodValue.
private void injectMethodValue(Method method, Object target, ConfigurationAdapter adapter, ConfigurationBinding binding) throws ConfigurationException {
Configure methodTag = method.getAnnotation(Configure.class);
if (methodTag != null) {
Alias aliasTag = method.getAnnotation(Alias.class);
String methodName = getConfigName(method, aliasTag);
Class[] argTypes = method.getParameterTypes();
Object[] args = new Object[argTypes.length];
Annotation[][] argTags = method.getParameterAnnotations();
for (int i = 0; i < argTypes.length; i++) {
String argName = getConfigName(methodName, argTags[i]);
String bndName = getBindName(target, argName, binding);
Object argValue = retrieveValue(target, bndName, argName, argTypes[i], adapter, binding);
if (argValue == null) {
Default defTag = findAnnotation(argTags[i], Default.class);
if (defTag != null) {
String strValue = defTag.value();
argValue = convertValue(target, argName, strValue, argTypes[i]);
} else {
throw new ConfigurationException(String.format("Failed to find configuration for %s as %s of %s via %s", bndName, argName, target.getClass().getName(), adapter.getClass().getName()));
}
}
args[i] = argValue;
}
if (!method.isAccessible()) {
method.setAccessible(true);
}
try {
method.invoke(target, args);
} catch (Exception e) {
throw new ConfigurationException(String.format("Failed to inject method configuration via %s of %s", methodName, target.getClass().getName()), e);
}
}
}
Aggregations