org.deckfour.xes.extension
Class XExtensionManager

java.lang.Object
  extended by org.deckfour.xes.extension.XExtensionManager

public class XExtensionManager
extends Object

The extension manager is used to access, store, and manage extensions in a system. Extensions can be loaded from their given URI, which should point to the file defining the extension. Also, extensions can be registered locally, which then override any remotely-loaded extensions (which are more generic placeholders). Extension files downloaded from remote sources (which happens when the extension cannot be resolved locally) are cached on the local system, so that the network source of extension files is not put under extensive stress. The extension manager is a singleton, there is no need to instantiate more than one extension manager, which is necessary to avoid states of inconsistency.

Author:
Christian W. Guenther (christian@deckfour.org)

Field Summary
static long MAX_CACHE_MILLIS
          Maximal time for caching remotely-defined extensions in milliseconds.
 
Method Summary
protected  void cacheExtension(URI uri)
          Downloads and caches an extension from its remote definition file.
 XExtension getByIndex(int index)
          Retrieves an extension by ints index.
 XExtension getByName(String name)
          Retrieves an extension by its name.
 XExtension getByPrefix(String prefix)
          Retrieves an extension by its prefix.
 XExtension getByUri(URI uri)
          Retrieves an extension instance by its unique URI.
 int getIndex(XExtension extension)
          Resolves the index of an extension, given that this extension has been previously registered with this manager instance.
static XExtensionManager instance()
          Accesses the singleton instance of the extension manager.
protected  void loadExtensionCache()
          Loads all extensions stored in the local cache.
 void register(XExtension extension)
          Explicitly registers an extension instance with the extension manager.
protected  void registerStandardExtensions()
          Registers all defined standard extensions with the extension manager before caching.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_CACHE_MILLIS

public static final long MAX_CACHE_MILLIS
Maximal time for caching remotely-defined extensions in milliseconds. The default for this value is one day (24 hrs.)

See Also:
Constant Field Values
Method Detail

instance

public static XExtensionManager instance()
Accesses the singleton instance of the extension manager.

Returns:
Singleton extension manager.

register

public void register(XExtension extension)
Explicitly registers an extension instance with the extension manager.

Parameters:
extension - The extension to be registered.

getByUri

public XExtension getByUri(URI uri)
Retrieves an extension instance by its unique URI. If the extension has not been registered before, it is looked up in the local cache. If it cannot be found in the cache, the manager attempts to download it from its unique URI, and add it to the set of managed extensions.

Parameters:
uri - The unique URI of the requested extension.
Returns:
The requested extension.

getByName

public XExtension getByName(String name)
Retrieves an extension by its name. If no extension by that name can be found, this method returns null.

Parameters:
name - The name of the requested extension.
Returns:
The requested extension (may be null, if it cannot be found).

getByPrefix

public XExtension getByPrefix(String prefix)
Retrieves an extension by its prefix. If no extension by that prefix can be found, this method returns null.

Parameters:
prefix - The prefix of the requested extension.
Returns:
The requested extension (may be null, if it cannot be found).

getByIndex

public XExtension getByIndex(int index)
Retrieves an extension by ints index. If no extension with the given index is found, this method returns null.

Parameters:
index - The index of the requested extension.
Returns:
The requested extension (may be null, if it cannot be found).

getIndex

public int getIndex(XExtension extension)
Resolves the index of an extension, given that this extension has been previously registered with this manager instance. If the given index has not been registered previously, this method returns -1.

Parameters:
extension - The extension to look up the index for.
Returns:
Unique index of the requested extension (positive integer).

registerStandardExtensions

protected void registerStandardExtensions()
Registers all defined standard extensions with the extension manager before caching.


cacheExtension

protected void cacheExtension(URI uri)
Downloads and caches an extension from its remote definition file. The extension is subsequently placed in the local cache, so that future loading is accelerated.

Parameters:
uri - Unique URI of the extension which is to be cached.

loadExtensionCache

protected void loadExtensionCache()
Loads all extensions stored in the local cache. Cached extensions which exceed the maximum caching age are discarded, and downloaded freshly.