* @return the resourceloader for that key, or null, if no resource-loader is able to process the key.
* @throws ResourceLoadingException if an error occured.
*/
public synchronized ResourceBundleData loadResourceBundle(final ResourceKey key) throws ResourceLoadingException
{
final ResourceBundleDataCache bundleCache = getBundleCache();
final ResourceBundleDataCacheEntry cached = bundleCache.get(key);
if (cached != null)
{
final ResourceBundleData data = cached.getData();
// check, whether it is valid.
final long version = data.getVersion(this);
if ((cached.getStoredVersion() < 0) ||
(version >= 0 && cached.getStoredVersion() == version))
{
// now also make sure that the underlying data has not changed.
// This may look a bit superfluous, but the repository may not provide
// sensible cacheable information.
//
// As condition of satisfaction, try to find the first piece of data that
// is in the cache and see whether it has changed.
ResourceKey bundleKey = data.getBundleKey();
int counter = 1;
while (bundleKey != null)
{
final ResourceDataCacheEntry bundleRawDataCacheEntry = getDataCache().get(bundleKey);
if (bundleRawDataCacheEntry != null)
{
final ResourceData bundleRawData = bundleRawDataCacheEntry.getData();
if (bundleRawData != null)
{
if (isValidData(bundleRawDataCacheEntry, bundleRawData))
{
logger.debug("Returning cached entry [" + counter + "]");
return data;
}
getDataCache().remove(bundleRawData);
}
}
bundleKey = bundleKey.getParent();
counter += 1;
}
}
bundleCache.remove(data);
}
final ResourceBundleData data = backend.loadResourceBundle(this, key);
if (data != null && isResourceDataCacheable(data))
{
bundleCache.put(this, data);
}
return data;
}