*/
public static Resource getResource(String resourceName, int resourceType)
throws ResourceNotFoundException, ParseErrorException, Exception
{
Resource resource = null;
ResourceLoader resourceLoader = null;
/*
* Check to see if the resource was placed in the cache.
* If it was placed in the cache then we will use
* the cached version of the resource. If not we
* will load it.
*/
if (globalCache.containsKey(resourceName))
{
resource = (Resource) globalCache.get(resourceName);
/*
* The resource knows whether it needs to be checked
* or not, and the resource's loader can check to
* see if the source has been modified. If both
* these conditions are true then we must reload
* the input stream and parse it to make a new
* AST for the resource.
*/
if ( resource.requiresChecking() )
{
/*
* touch() the resource to reset the counters
*/
resource.touch();
if( resource.isSourceModified() )
{
try
{
/*
* read how old the resource is _before_
* processing (=>reading) it
*/
long howOldItWas = resourceLoader.getLastModified( resource );
/*
* read in the fresh stream and parse
*/
resource.process();
/*
* now set the modification info and reset
* the modification check counters
*/
resource.setLastModified( howOldItWas );
}
catch( ResourceNotFoundException rnfe )
{
Runtime.error("ResourceManager.getResource() exception: " + rnfe);
throw rnfe;
}
catch( ParseErrorException pee )
{
Runtime.error("ResourceManager.getResource() exception: " + pee);
throw pee;
}
catch( Exception eee )
{
Runtime.error("ResourceManager.getResource() exception: " + eee);
throw eee;
}
}
}
return resource;
}
else
{
/*
* it's not in the cache
*/
try
{
resource = ResourceFactory.getResource(resourceName, resourceType);
resource.setName(resourceName);
/*
* Now we have to try to find the appropriate
* loader for this resource. We have to cycle through
* the list of available resource loaders and see
* which one gives us a stream that we can use to
* make a resource with.
*/
//! Bug this is being run more then once!
long howOldItWas = 0; // Initialize to avoid warnings
for (int i = 0; i < resourceLoaders.size(); i++)
{
resourceLoader = (ResourceLoader) resourceLoaders.get(i);
resource.setResourceLoader(resourceLoader);
/*
* catch the ResourceNotFound exception
* as that is ok in our new multi-loader environment
*/
try
{
if (resource.process())
{
/*
* FIXME (gmj)
* moved in here - technically still
* a problem - but the resource needs to be
* processed before the loader can figure
* it out due to to the new
* multi-path support - will revisit and fix
*/
Runtime.info("ResourceManager : found " + resourceName +
" with loader " + resourceLoader.getClassName());
howOldItWas = resourceLoader.getLastModified( resource );
break;
}
}
catch( ResourceNotFoundException rnfe )
{
/*
* that's ok - it's possible to fail in
* multi-loader environment
*/
}
}
/*
* Return null if we can't find a resource.
*/
if (resource.getData() == null)
throw new ResourceNotFoundException("Unable to find resource '" + resourceName + "'");
resource.setLastModified( howOldItWas );
resource.setModificationCheckInterval(
resourceLoader.getModificationCheckInterval());
resource.touch();
/*
* Place the resource in the cache if the resource
* loader says to.
*/
if (resourceLoader.isCachingOn())
globalCache.put(resourceName, resource);
}
catch( ResourceNotFoundException rnfe2 )
{
Runtime.error("ResourceManager : unable to find resource '" + resourceName + "' in any resource loader.");