Class<?> configurationClass;
try {
configurationClass = Class.forName(className);
} catch (ClassNotFoundException e) {
throw new ConstrettoException(String.format("Could not load configuration class \"%s\"", className), e);
}
final List<Method> methods = findStaticNonArgsMethodsReturningConstrettoConfiguration(configurationClass);
if (methods.isEmpty()) {
throw new ConstrettoException("Could not find a static factory non-arg method that creates a " +
"org.constretto.ConstrettoConfiguration instance in your configuration class (or superclass). " +
"In order to use automatic setup of Constretto-Spring BeanPostProcessors " +
"you will have to define one");
} else if (methods.size() > 1) {
throw new ConstrettoException("Found more than static non-arg method returning a " +
"org.constretto.ConstrettoConfiguration instance in your configuration class (or superclass). " +
"To use automatic setup of Constretto Spring BeanPostProcessors you should have only one");
} else {
Method factoryMethod = methods.get(0);
try {
return (ConstrettoConfiguration) factoryMethod.invoke(null);
} catch (IllegalAccessException e) {
throw new ConstrettoException(String.format("Could not invoke factory method \"%1$s\" in configuration class \"%2$s\"", factoryMethod.getName(), configurationClass.getName()), e);
} catch (InvocationTargetException e) {
throw new ConstrettoException(String.format("Could not invoke factory method \"%1$s\" in configuration class \"%2$s\"", factoryMethod.getName(), configurationClass.getName()), e);
}
}
}