in velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java [768:847]
private void initializeResourceManager()
{
/*
* Which resource manager?
*/
Object inst = getProperty(RuntimeConstants.RESOURCE_MANAGER_INSTANCE);
String rm = getString(RuntimeConstants.RESOURCE_MANAGER_CLASS);
if (inst != null)
{
if (ResourceManager.class.isAssignableFrom(inst.getClass()))
{
resourceManager = (ResourceManager)inst;
resourceManager.initialize(this);
}
else
{
String msg = inst.getClass().getName() + " object set as resource.manager.instance is not a valid org.apache.velocity.runtime.resource.ResourceManager.";
log.error(msg);
throw new VelocityException(msg);
}
}
else if (rm != null && rm.length() > 0)
{
/*
* if something was specified, then make one.
* if that isn't a ResourceManager, consider
* this a huge error and throw
*/
Object o = null;
try
{
o = ClassUtils.getNewInstance( rm );
}
catch (ClassNotFoundException cnfe )
{
String err = "The specified class for ResourceManager (" + rm
+ ") does not exist or is not accessible to the current classloader.";
log.error(err);
throw new VelocityException(err, cnfe);
}
catch (InstantiationException ie)
{
throw new VelocityException("Could not instantiate class '" + rm + "'", ie);
}
catch (IllegalAccessException ae)
{
throw new VelocityException("Cannot access class '" + rm + "'", ae);
}
if (!(o instanceof ResourceManager))
{
String err = "The specified class for ResourceManager (" + rm
+ ") does not implement " + ResourceManager.class.getName()
+ "; Velocity is not initialized correctly.";
log.error(err);
throw new VelocityException(err);
}
resourceManager = (ResourceManager) o;
resourceManager.initialize(this);
setProperty(RESOURCE_MANAGER_INSTANCE, resourceManager);
}
else
{
/*
* someone screwed up. Lets not fool around...
*/
String err = "It appears that no class or instance was specified as the"
+ " ResourceManager. Please ensure that all configuration"
+ " information is correct.";
log.error(err);
throw new VelocityException( err );
}
}