in velocity-tools-generic/src/main/java/org/apache/velocity/tools/config/ConfigurationUtils.java [380:436]
public static FactoryConfiguration getFromClass(Class factory)
{
//TODO: look for a getConfiguration() method
Method getConf = null;
try
{
// check for a public setup(Map) method first
getConf = factory.getMethod(CONFIG_FACTORY_METHOD, (Class[])null);
}
catch (NoSuchMethodException nsme)
{
throw new IllegalArgumentException("Could not find "+CONFIG_FACTORY_METHOD+" in class "+factory.getName(), nsme);
}
// get an instance if the method is not static
Object instance = null;
if (!Modifier.isStatic(getConf.getModifiers()))
{
try
{
instance = factory.newInstance();
}
catch (Exception e)
{
throw new IllegalArgumentException(factory.getName()+" must have usable default constructor or else "+CONFIG_FACTORY_METHOD+" must be declared static", e);
}
}
// invoke the method
try
{
FactoryConfiguration result =
(FactoryConfiguration)getConf.invoke(instance, (Object[])null);
if (result == null)
{
throw new IllegalArgumentException("Method "+CONFIG_FACTORY_METHOD+" in class "+factory.getName()+" should not return null or void");
}
else
{
return result;
}
}
catch (IllegalAccessException iae)
{
throw new IllegalArgumentException("Failed to invoke "+CONFIG_FACTORY_METHOD+" in class "+factory.getName(), iae);
}
catch (IllegalArgumentException iae)
{
// if this happens, it's more a problem w/this code than the users
throw iae;
}
catch (InvocationTargetException ite)
{
// if this happens, it's all their issue
throw new IllegalArgumentException("There was an exception while executing "+CONFIG_FACTORY_METHOD+" in class "+factory.getName(), ite.getCause());
}
}