org.jfree.resourceloader

Class ResourceManager


public class ResourceManager
extends java.lang.Object

The resource manager takes care about the loaded resources, performs caching, if needed and is the central instance when dealing with resources. Resource loading is a two-step process. In the first step, the ResourceLoader accesses the physical storage or network connection to read in the binary data. The loaded ResourceData carries versioning information with it an can be cached indendently from the produced result. Once the loading is complete, a ResourceFactory interprets the binary data and produces a Java-Object from it.

Resources are identified by an Resource-Key and some optional loader parameters (which can be used to parametrize the resource-factories).

Author:
Thomas Morgner
See Also:
ResourceData, ResourceLoader, ResourceFactory

Field Summary

static String
DATA_CACHE_PROVIDER_KEY
static String
FACTORY_CACHE_PROVIDER_KEY

Constructor Summary

ResourceManager()

Method Summary

Resource
create(ResourceKey key, ResourceKey context)
Resource
create(ResourceKey key, ResourceKey context, Class target)
Resource
create(ResourceKey key, ResourceKey context, Class[] target)
Resource
createDirectly(Object keyValue, Class target)
ResourceKey
createKey(Object data)
Creates a ResourceKey that carries no Loader-Parameters from the given object.
ResourceKey
createKey(Object data, Map parameters)
Creates a ResourceKey that carries the given Loader-Parameters contained in the optional map.
ResourceKey
deriveKey(ResourceKey parent, String path)
Derives a new key from the given resource-key.
ResourceKey
deriveKey(ResourceKey parent, String path, Map parameters)
Derives a new key from the given resource-key.
org.jfree.resourceloader.cache.ResourceDataCache
getDataCache()
org.jfree.resourceloader.cache.ResourceFactoryCache
getFactoryCache()
ResourceData
load(ResourceKey key)
void
registerDataCache()
void
registerDefaultFactories()
void
registerDefaultLoaders()
void
registerDefaults()
void
registerFactory(ResourceFactory factory)
void
registerFactoryCache()
void
registerLoader(ResourceLoader loader)
void
setDataCache(org.jfree.resourceloader.cache.ResourceDataCache dataCache)
void
setFactoryCache(org.jfree.resourceloader.cache.ResourceFactoryCache factoryCache)
URL
toURL(ResourceKey key)
Tries to convert the resource-key into an URL.

Field Details

DATA_CACHE_PROVIDER_KEY

public static final String DATA_CACHE_PROVIDER_KEY

FACTORY_CACHE_PROVIDER_KEY

public static final String FACTORY_CACHE_PROVIDER_KEY

Constructor Details

ResourceManager

public ResourceManager()

Method Details

create

public Resource create(ResourceKey key,
                       ResourceKey context)
            throws ResourceLoadingException,
                   ResourceCreationException

create

public Resource create(ResourceKey key,
                       ResourceKey context,
                       Class target)
            throws ResourceLoadingException,
                   ResourceCreationException

create

public Resource create(ResourceKey key,
                       ResourceKey context,
                       Class[] target)
            throws ResourceLoadingException,
                   ResourceCreationException

createDirectly

public Resource createDirectly(Object keyValue,
                               Class target)
            throws ResourceLoadingException,
                   ResourceCreationException,
                   ResourceKeyCreationException

createKey

public ResourceKey createKey(Object data)
            throws ResourceKeyCreationException
Creates a ResourceKey that carries no Loader-Parameters from the given object.
Parameters:
data - the key-data
Returns:
the generated resource-key, never null.
Throws:
ResourceKeyCreationException - if the key-creation failed.

createKey

public ResourceKey createKey(Object data,
                             Map parameters)
            throws ResourceKeyCreationException
Creates a ResourceKey that carries the given Loader-Parameters contained in the optional map.
Parameters:
data - the key-data
parameters - an optional map of parameters.
Returns:
the generated resource-key, never null.
Throws:
ResourceKeyCreationException - if the key-creation failed.

deriveKey

public ResourceKey deriveKey(ResourceKey parent,
                             String path)
            throws ResourceKeyCreationException
Derives a new key from the given resource-key. Only keys for a hierarchical storage system (like file-systems or URLs) can have derived keys. Since LibLoader 0.3.0 only hierarchical keys can be derived. For that, the deriving path must be given as String.

Before trying to derive the key, the system tries to interpret the path as absolute key-value.

Parameters:
parent - the parent key, must never be null
path - the relative path, that is used to derive the key.
Returns:
the derived key.

deriveKey

public ResourceKey deriveKey(ResourceKey parent,
                             String path,
                             Map parameters)
            throws ResourceKeyCreationException
Derives a new key from the given resource-key. Only keys for a hierarchical storage system (like file-systems or URLs) can have derived keys. Since LibLoader 0.3.0 only hierarchical keys can be derived. For that, the deriving path must be given as String.

The optional parameter-map will be applied to the derived key after the parent's parameters have been copied to the new key.

Before trying to derive the key, the system tries to interpret the path as absolute key-value.

Parameters:
parent - the parent key, or null to interpret the path as absolute key.
path - the relative path, that is used to derive the key.
Returns:
the derived key.

getDataCache

public org.jfree.resourceloader.cache.ResourceDataCache getDataCache()

getFactoryCache

public org.jfree.resourceloader.cache.ResourceFactoryCache getFactoryCache()

load

public ResourceData load(ResourceKey key)
            throws ResourceLoadingException

registerDataCache

public void registerDataCache()

registerDefaultFactories

public void registerDefaultFactories()

registerDefaultLoaders

public void registerDefaultLoaders()

registerDefaults

public void registerDefaults()

registerFactory

public void registerFactory(ResourceFactory factory)

registerFactoryCache

public void registerFactoryCache()

registerLoader

public void registerLoader(ResourceLoader loader)

setDataCache

public void setDataCache(org.jfree.resourceloader.cache.ResourceDataCache dataCache)

setFactoryCache

public void setFactoryCache(org.jfree.resourceloader.cache.ResourceFactoryCache factoryCache)

toURL

public URL toURL(ResourceKey key)
Tries to convert the resource-key into an URL. Not all resource-keys have an URL representation. This method exists to make it easier to connect LibLoader to other resource-loading frameworks.
Parameters:
key - the resource-key
Returns:
the URL for the key, or null if there is no such key.