in velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java [96:206]
public synchronized void initialize(final RuntimeServices rs)
{
if (isInit)
{
log.debug("Re-initialization of ResourceLoader attempted and ignored.");
return;
}
ResourceLoader resourceLoader = null;
rsvc = rs;
log = rsvc.getLog("loader");
log.trace("ResourceManager initializing: {}", this.getClass());
assembleResourceLoaderInitializers();
for (ExtProperties configuration : sourceInitializerList)
{
/*
* Resource loader can be loaded either via class name or be passed
* in as an instance.
*/
String loaderClass = StringUtils.trim(configuration.getString(RuntimeConstants.RESOURCE_LOADER_CLASS));
ResourceLoader loaderInstance = (ResourceLoader) configuration.get(RuntimeConstants.RESOURCE_LOADER_INSTANCE);
if (loaderInstance != null)
{
resourceLoader = loaderInstance;
} else if (loaderClass != null)
{
resourceLoader = ResourceLoaderFactory.getLoader(rsvc, loaderClass);
} else
{
String msg = "Unable to find 'resource.loader." +
configuration.getString(RuntimeConstants.RESOURCE_LOADER_IDENTIFIER) +
".class' specification in configuration." +
" This is a critical value. Please adjust configuration.";
log.error(msg);
throw new VelocityException(msg, null, rsvc.getLogContext().getStackTrace());
}
resourceLoader.commonInit(rsvc, configuration);
resourceLoader.init(configuration);
resourceLoaders.add(resourceLoader);
}
/*
* now see if this is overridden by configuration
*/
logWhenFound = rsvc.getBoolean(RuntimeConstants.RESOURCE_MANAGER_LOGWHENFOUND, true);
/*
* now, is a global cache specified?
*/
String cacheClassName = rsvc.getString(RuntimeConstants.RESOURCE_MANAGER_CACHE_CLASS);
Object cacheObject = null;
if (StringUtils.isNotEmpty(cacheClassName))
{
try
{
cacheObject = ClassUtils.getNewInstance(cacheClassName);
}
catch (ClassNotFoundException cnfe)
{
String msg = "The specified class for ResourceCache (" + cacheClassName +
") does not exist or is not accessible to the current classloader.";
log.error(msg, cnfe);
throw new VelocityException(msg, cnfe);
}
catch (IllegalAccessException ae)
{
throw new VelocityException("Could not access class '"
+ cacheClassName + "'", ae);
}
catch (InstantiationException ie)
{
throw new VelocityException("Could not instantiate class '"
+ cacheClassName + "'", ie);
}
if (!(cacheObject instanceof ResourceCache))
{
String msg = "The specified resource cache class (" + cacheClassName +
") must implement " + ResourceCache.class.getName();
log.error(msg);
throw new RuntimeException(msg);
}
}
/*
* if we didn't get through that, just use the default.
*/
if (cacheObject == null)
{
cacheObject = new ResourceCacheImpl();
}
globalCache = (ResourceCache) cacheObject;
globalCache.initialize(rsvc);
isInit = true;
log.trace("Default ResourceManager initialization complete.");
}