Interface ResourceLoader
-
- All Known Implementing Classes:
ClassloaderResourceLoader
,FileObjectResourceLoader
,FileResourceLoader
,RawResourceLoader
,URLResourceLoader
,ZipResourceLoader
public interface ResourceLoader
A resource loader knows how to get binary rawdata from a location specified by an resource key. A resource key is a wrapper around any kind of data that is suitable to identify a resource location. The resource key can also hold configuration data for the factory. If the storage system is hierarchical, a new resource key can be derived from a given path-string.- Author:
- Thomas Morgner
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description ResourceKey
createKey(Object value, Map factoryKeys)
Creates a new resource key from the given object and the factory keys.ResourceKey
deriveKey(ResourceKey parent, String path, Map factoryKeys)
Derives a new resource key from the given key.ResourceKey
deserialize(ResourceKey bundleKey, String stringKey)
Creates aResourceKey
based off theString
representation of the key.boolean
isSupportedDeserializer(String data)
Determines if the resource loader is capable of deserializing the serialized version of the ResourceKey.boolean
isSupportedKey(ResourceKey key)
Checks, whether this resource loader implementation was responsible for creating this key.ResourceData
load(ResourceKey key)
Loads the binary data represented by this key.String
serialize(ResourceKey bundleKey, ResourceKey key)
Serializes the resource key to a String representation which can be recreated using thedeserialize(ResourceKey)
method.
URL
toURL(ResourceKey key)
Generates aURL
version of the suppliedResourceKey
.
-
-
-
Method Detail
-
isSupportedKey
boolean isSupportedKey(ResourceKey key)
Checks, whether this resource loader implementation was responsible for creating this key.- Parameters:
key
- the key that should be tested.- Returns:
- true, if the key is supported.
-
createKey
ResourceKey createKey(Object value, Map factoryKeys) throws ResourceKeyCreationException
Creates a new resource key from the given object and the factory keys.- Parameters:
value
- the key value.factoryKeys
- optional parameter map (can be null).- Returns:
- the created key or null, if the format was not recognized.
- Throws:
ResourceKeyCreationException
- if creating the key failed.
-
deriveKey
ResourceKey deriveKey(ResourceKey parent, String path, Map factoryKeys) throws ResourceKeyCreationException
Derives a new resource key from the given key. If neither a path nor new factory-keys are given, the parent key is returned.- Parameters:
parent
- the parentpath
- the derived path (can be null).factoryKeys
- the optional factory keys (can be null).- Returns:
- the derived key.
- Throws:
ResourceKeyCreationException
- if the key cannot be derived for any reason.
-
load
ResourceData load(ResourceKey key) throws ResourceLoadingException
Loads the binary data represented by this key.- Parameters:
key
-- Returns:
- Throws:
ResourceLoadingException
-
toURL
URL toURL(ResourceKey key)
Generates aURL
version of the suppliedResourceKey
.- Parameters:
key
- theResourceKey
from which aURL
will be created- Returns:
- the URL representation of the
ResourceKey
-
isSupportedDeserializer
boolean isSupportedDeserializer(String data)
Determines if the resource loader is capable of deserializing the serialized version of the ResourceKey.- Parameters:
data
- the serialized version of the resource key- Returns:
true
if thisResourceLoader
is capable of deserializing the serialized version of this resource key,false
otherwise.
-
serialize
String serialize(ResourceKey bundleKey, ResourceKey key) throws ResourceException
Serializes the resource key to a String representation which can be recreated using thedeserialize(ResourceKey)
method.
- Parameters:
bundleKey
-key
-- Returns:
- a
String
which is a serialized version of the
ResourceKey
- Throws:
ResourceException
- indicates an error serializing the resource key
-
deserialize
ResourceKey deserialize(ResourceKey bundleKey, String stringKey) throws ResourceKeyCreationException
Creates aResourceKey
based off theString
representation of the key. TheString
should have been created using theserialize
method.- Parameters:
bundleKey
-stringKey
- theString
representation of theResourceKey
@return aResourceKey
which matches theString
representation- Throws:
ResourceKeyCreationException
- indicates an error occurred in the creation or deserialization of theResourceKey
-
-