org.pentaho.reporting.libraries.resourceloader

## Class ResourceManager

- java.lang.Object
- - org.pentaho.reporting.libraries.resourceloader.ResourceManager

    public final 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

Fields
`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 Summary

Constructors
Constructor and Description
`ResourceManager()` Default Constructor.
`ResourceManager(ResourceManagerBackend resourceManagerBackend)`
`ResourceManager(ResourceManager parent, ResourceManagerBackend backend)`

### Method Summary

Methods
`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.

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### BUNDLE_LOADER_PREFIX

    public static final java.lang.String BUNDLE_LOADER_PREFIX

See Also:
  Constant Field Values

#### LOADER_PREFIX

    public static final java.lang.String LOADER_PREFIX

See Also:
  Constant Field Values

#### FACTORY_TYPE_PREFIX

    public static final java.lang.String FACTORY_TYPE_PREFIX

See Also:
  Constant Field Values

#### BUNDLE_CACHE_PROVIDER_KEY

    public static final java.lang.String BUNDLE_CACHE_PROVIDER_KEY

See Also:
  Constant Field Values

#### DATA_CACHE_PROVIDER_KEY

    public static final java.lang.String DATA_CACHE_PROVIDER_KEY

See Also:
  Constant Field Values

#### FACTORY_CACHE_PROVIDER_KEY

    public static final java.lang.String FACTORY_CACHE_PROVIDER_KEY

See Also:
  Constant Field Values

### Constructor Detail

#### ResourceManager

    public ResourceManager()

Default Constructor.

#### ResourceManager

    public ResourceManager(ResourceManagerBackend resourceManagerBackend)

#### ResourceManager

    public ResourceManager(ResourceManager parent,
                   ResourceManagerBackend backend)

### Method Detail

#### getBackend

    public ResourceManagerBackend getBackend()

#### createKey

    public ResourceKey createKey(java.lang.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(java.lang.Object data,
                        java.util.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,
                        java.lang.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.
Throws:
  `ResourceKeyCreationException` - if deriving the key failed.

#### deriveKey

    public ResourceKey deriveKey(ResourceKey parent,
                        java.lang.String path,
                        java.util.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.
  `parameters` - a optional map containing resource-key parameters.
Returns:
  the derived key.
Throws:
  `ResourceKeyCreationException` - if deriving the key failed.

#### toURL

    public java.net.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.

#### createDirectly

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

Throws:
  `ResourceLoadingException`
  `ResourceCreationException`
  `ResourceKeyCreationException`

#### loadResourceBundle

    public ResourceBundleData loadResourceBundle(ResourceKey key)
                                          throws ResourceLoadingException

Tries to find the first resource-bundle-loader that would be able to process the key.

Parameters:
  `key` - the resource-key.
Returns:
  the resourceloader for that key, or null, if no resource-loader is able to process the key.
Throws:
  `ResourceLoadingException` - if an error occured.

#### load

    public ResourceData load(ResourceKey key)
                      throws ResourceLoadingException

Throws:
  `ResourceLoadingException`

#### loadRawData

    public ResourceData loadRawData(ResourceKey key)
                             throws UnrecognizedLoaderException,
                                    ResourceLoadingException

Throws:
  `UnrecognizedLoaderException`
  `ResourceLoadingException`

#### create

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

Throws:
  `ResourceLoadingException`
  `ResourceCreationException`

#### create

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

Throws:
  `ResourceLoadingException`
  `ResourceCreationException`

#### create

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

Throws:
  `ResourceLoadingException`
  `ResourceCreationException`

#### getDataCache

    public ResourceDataCache getDataCache()

#### setDataCache

    public void setDataCache(ResourceDataCache dataCache)

#### getFactoryCache

    public ResourceFactoryCache getFactoryCache()

#### setFactoryCache

    public void setFactoryCache(ResourceFactoryCache factoryCache)

#### getBundleCache

    public ResourceBundleDataCache getBundleCache()

#### setBundleCache

    public void setBundleCache(ResourceBundleDataCache bundleCache)

#### registerDefaults

    public void registerDefaults()

#### registerDefaultFactories

    public void registerDefaultFactories()

#### registerBundleDataCache

    public void registerBundleDataCache()

#### registerDataCache

    public void registerDataCache()

#### registerFactoryCache

    public void registerFactoryCache()

#### registerDefaultLoaders

    public void registerDefaultLoaders()

#### registerBundleLoader

    public void registerBundleLoader(ResourceBundleLoader loader)

#### registerLoader

    public void registerLoader(ResourceLoader loader)

#### registerFactory

    public void registerFactory(ResourceFactory factory)

#### shutDown

    public void shutDown()

#### serialize

    public java.lang.String serialize(ResourceKey bundleKey,
                             ResourceKey key)
                               throws ResourceException

Creates a String version of the `ResourceKey` that can be deserialized with the `deserialize()` method.

Parameters:
  `bundleKey` - the key to the bundle containing the resource, or null if no bundle exists.
  `key` - the key to be serialized
Throws:
  `ResourceException` - indicates an error trying to serialize the key
  `java.lang.NullPointerException` - indicates the supplied key is `null`

#### deserialize

    public ResourceKey deserialize(ResourceKey bundleKey,
                          java.lang.String serializedKey)
                            throws ResourceKeyCreationException

Converts a serialized version of a `ResourceKey` into an actual `ResourceKey` by locating the proper `ResourceLoader` that can perform the deserialization.

Parameters:
  `serializedKey` - the String serialized key to be deserialized
Returns:
  the `ResourceKey` that has been deserialized
Throws:
  `ResourceKeyCreationException` - indicates an error trying to create the `ResourceKey` from the deserialized version