public final class ResourceManager
extends java.lang.Object
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).ResourceData
,
ResourceLoader
,
ResourceFactory
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
BUNDLE_CACHE_PROVIDER_KEY |
static java.lang.String |
BUNDLE_LOADER_PREFIX |
static java.lang.String |
DATA_CACHE_PROVIDER_KEY |
static java.lang.String |
FACTORY_CACHE_PROVIDER_KEY |
static java.lang.String |
FACTORY_TYPE_PREFIX |
static java.lang.String |
LOADER_PREFIX |
Constructor and Description |
---|
ResourceManager()
Default Constructor.
|
ResourceManager(ResourceManagerBackend resourceManagerBackend) |
ResourceManager(ResourceManager parent,
ResourceManagerBackend backend) |
Modifier and Type | Method and Description |
---|---|
Resource |
create(ResourceKey key,
ResourceKey context) |
Resource |
create(ResourceKey key,
ResourceKey context,
java.lang.Class target) |
Resource |
create(ResourceKey key,
ResourceKey context,
java.lang.Class[] target) |
Resource |
createDirectly(java.lang.Object keyValue,
java.lang.Class target) |
ResourceKey |
createKey(java.lang.Object data)
Creates a ResourceKey that carries no Loader-Parameters from the given object.
|
ResourceKey |
createKey(java.lang.Object data,
java.util.Map parameters)
Creates a ResourceKey that carries the given Loader-Parameters contained in the optional map.
|
ResourceKey |
deriveKey(ResourceKey parent,
java.lang.String path)
Derives a new key from the given resource-key.
|
ResourceKey |
deriveKey(ResourceKey parent,
java.lang.String path,
java.util.Map parameters)
Derives a new key from the given resource-key.
|
ResourceKey |
deserialize(ResourceKey bundleKey,
java.lang.String serializedKey)
Converts a serialized version of a
ResourceKey into an actual ResourceKey
by locating the proper ResourceLoader that can perform the deserialization. |
ResourceManagerBackend |
getBackend() |
ResourceBundleDataCache |
getBundleCache() |
ResourceDataCache |
getDataCache() |
ResourceFactoryCache |
getFactoryCache() |
ResourceData |
load(ResourceKey key) |
ResourceData |
loadRawData(ResourceKey key) |
ResourceBundleData |
loadResourceBundle(ResourceKey key)
Tries to find the first resource-bundle-loader that would be able to process the key.
|
void |
registerBundleDataCache() |
void |
registerBundleLoader(ResourceBundleLoader loader) |
void |
registerDataCache() |
void |
registerDefaultFactories() |
void |
registerDefaultLoaders() |
void |
registerDefaults() |
void |
registerFactory(ResourceFactory factory) |
void |
registerFactoryCache() |
void |
registerLoader(ResourceLoader loader) |
java.lang.String |
serialize(ResourceKey bundleKey,
ResourceKey key)
Creates a String version of the
ResourceKey that can be deserialized with the
deserialize() method. |
void |
setBundleCache(ResourceBundleDataCache bundleCache) |
void |
setDataCache(ResourceDataCache dataCache) |
void |
setFactoryCache(ResourceFactoryCache factoryCache) |
void |
shutDown() |
java.net.URL |
toURL(ResourceKey key)
Tries to convert the resource-key into an URL.
|
public static final java.lang.String BUNDLE_LOADER_PREFIX
public static final java.lang.String LOADER_PREFIX
public static final java.lang.String FACTORY_TYPE_PREFIX
public static final java.lang.String BUNDLE_CACHE_PROVIDER_KEY
public static final java.lang.String DATA_CACHE_PROVIDER_KEY
public static final java.lang.String FACTORY_CACHE_PROVIDER_KEY
public ResourceManager()
public ResourceManager(ResourceManagerBackend resourceManagerBackend)
public ResourceManager(ResourceManager parent, ResourceManagerBackend backend)
public ResourceManagerBackend getBackend()
public ResourceKey createKey(java.lang.Object data) throws ResourceKeyCreationException
data
- the key-dataResourceKeyCreationException
- if the key-creation failed.public ResourceKey createKey(java.lang.Object data, java.util.Map parameters) throws ResourceKeyCreationException
data
- the key-dataparameters
- an optional map of parameters.ResourceKeyCreationException
- if the key-creation failed.public ResourceKey deriveKey(ResourceKey parent, java.lang.String path) throws ResourceKeyCreationException
parent
- the parent key, must never be nullpath
- the relative path, that is used to derive the key.ResourceKeyCreationException
- if deriving the key failed.public ResourceKey deriveKey(ResourceKey parent, java.lang.String path, java.util.Map parameters) throws ResourceKeyCreationException
parent
- the parent key, or null to interpret the path as absolute key.path
- the relative path, that is used to derive the key.parameters
- a optional map containing resource-key parameters.ResourceKeyCreationException
- if deriving the key failed.public java.net.URL toURL(ResourceKey key)
key
- the resource-keypublic Resource createDirectly(java.lang.Object keyValue, java.lang.Class target) throws ResourceLoadingException, ResourceCreationException, ResourceKeyCreationException
public ResourceBundleData loadResourceBundle(ResourceKey key) throws ResourceLoadingException
key
- the resource-key.ResourceLoadingException
- if an error occured.public ResourceData load(ResourceKey key) throws ResourceLoadingException
ResourceLoadingException
public ResourceData loadRawData(ResourceKey key) throws UnrecognizedLoaderException, ResourceLoadingException
public Resource create(ResourceKey key, ResourceKey context, java.lang.Class target) throws ResourceLoadingException, ResourceCreationException
public Resource create(ResourceKey key, ResourceKey context) throws ResourceLoadingException, ResourceCreationException
public Resource create(ResourceKey key, ResourceKey context, java.lang.Class[] target) throws ResourceLoadingException, ResourceCreationException
public ResourceDataCache getDataCache()
public void setDataCache(ResourceDataCache dataCache)
public ResourceFactoryCache getFactoryCache()
public void setFactoryCache(ResourceFactoryCache factoryCache)
public ResourceBundleDataCache getBundleCache()
public void setBundleCache(ResourceBundleDataCache bundleCache)
public void registerDefaults()
public void registerDefaultFactories()
public void registerBundleDataCache()
public void registerDataCache()
public void registerFactoryCache()
public void registerDefaultLoaders()
public void registerBundleLoader(ResourceBundleLoader loader)
public void registerLoader(ResourceLoader loader)
public void registerFactory(ResourceFactory factory)
public void shutDown()
public java.lang.String serialize(ResourceKey bundleKey, ResourceKey key) throws ResourceException
ResourceKey
that can be deserialized with the
deserialize()
method.bundleKey
- the key to the bundle containing the resource, or null if no bundle exists.key
- the key to be serializedResourceException
- indicates an error trying to serialize the keyjava.lang.NullPointerException
- indicates the supplied key is null
public ResourceKey deserialize(ResourceKey bundleKey, java.lang.String serializedKey) throws ResourceKeyCreationException
ResourceKey
into an actual ResourceKey
by locating the proper ResourceLoader
that can perform the deserialization.serializedKey
- the String serialized key to be deserializedResourceKey
that has been deserializedResourceKeyCreationException
- indicates an error trying to create the ResourceKey
from the deserialized version