org.openbp.jaspira.plugin
Class PluginMgr

java.lang.Object
  extended by org.openbp.jaspira.plugin.PluginMgr

public final class PluginMgr
extends java.lang.Object

The PluginMgr is the central instance for managing classes and instances of plugins. It has methods for loading plugin-classr files, creating new instances of a given plugin and retrieving instances of already created plugins.

Author:
Stephan Moritz

Nested Class Summary
protected  class PluginMgr.PluginEntry
          A PluginEntry contains various information about a particular plugin type.
 
Field Summary
static int PLUGIN_CLASS_LOADED
          Plugin entry status: The class file has been loaded, but there a no instances.
static int PLUGIN_HAS_INSTANCES
          Plugin entry status: The plugin has instances.
static int PLUGIN_LOAD_FAILED
          Plugin entry status: An exception occurred during loading of class or instantiation.
static int PLUGIN_NOT_LOADED
          Plugin entry status: The class file has not yet been loaded.
 
Method Summary
 Plugin createCopy(Plugin source)
          Creates a duplicate of the supplied plugin via its state object.
 Plugin createInstance(java.lang.Class cls, Plugin parent)
          Create a new instance of the given class.
 Plugin createInstance(PluginProfile profile, java.lang.ClassLoader pluginClassLoader, Plugin parent)
          Creates a new instance of the given plugin.
 Plugin createInstance(PluginState state, Plugin parent)
          Creates a new instance via a supplied state object.
 Plugin createInstance(java.lang.String classname, Plugin parent)
          Creates a new instance of the given plugin.
 VisiblePlugin createVisibleInstance(java.lang.Class cls, Plugin parent)
          Create a new instance of the given class.
 VisiblePlugin createVisibleInstance(PluginState state, Plugin parent)
          Creates a new instance via a supplied state object.
 VisiblePlugin createVisibleInstance(java.lang.String classname, Plugin parent)
          Creates a new instance of the given plugin.
static PluginMgr getInstance()
          Returns the singleton instance of the plugin manager.
 Plugin getPlugin(java.lang.String uniqueId)
          Returns the (already existing instance) of a plugin with the given unique ID or null if there is no such instance.
 Plugin getPluginInstance(java.lang.String classname)
          Gets the instance of a given plugin (identified by its class name).
 java.util.List getPluginInstances()
          Returns a list of all loaded plugins.
 java.util.Iterator getPluginInstances(java.lang.String classname)
          Gets all currently available instances of a given plugin (identified by its class name).
 void loadCustomPlugins(java.lang.String settingName)
          This method loads custom plugins that may be specified in a property file.
 void loadPluginsFromResource()
          This method loads custom plugins from the 'plugin' directory.
 void registerPlugin(Plugin plugin)
          Registers an externally created Plugin with the manager.
 boolean removeInstance(Plugin plugin)
          Removes a plugin from its container, uninstalls it and deletes it.
 boolean removeInstance(java.lang.String uniqueId)
          Removes the instance of a plugin with the given uniqueID.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PLUGIN_NOT_LOADED

public static final int PLUGIN_NOT_LOADED
Plugin entry status: The class file has not yet been loaded.

See Also:
Constant Field Values

PLUGIN_CLASS_LOADED

public static final int PLUGIN_CLASS_LOADED
Plugin entry status: The class file has been loaded, but there a no instances.

See Also:
Constant Field Values

PLUGIN_HAS_INSTANCES

public static final int PLUGIN_HAS_INSTANCES
Plugin entry status: The plugin has instances.

See Also:
Constant Field Values

PLUGIN_LOAD_FAILED

public static final int PLUGIN_LOAD_FAILED
Plugin entry status: An exception occurred during loading of class or instantiation.

See Also:
Constant Field Values
Method Detail

getInstance

public static PluginMgr getInstance()
Returns the singleton instance of the plugin manager.


getPlugin

public Plugin getPlugin(java.lang.String uniqueId)
Returns the (already existing instance) of a plugin with the given unique ID or null if there is no such instance.


createInstance

public Plugin createInstance(java.lang.String classname,
                             Plugin parent)
Creates a new instance of the given plugin.

Parameters:
classname - Plugin class
parent - Parent for the new plugin in the plugin tree
Returns:
The new plugin or null if it could not be instantiated

createInstance

public Plugin createInstance(PluginProfile profile,
                             java.lang.ClassLoader pluginClassLoader,
                             Plugin parent)
Creates a new instance of the given plugin.

Parameters:
profile - Plugin profile
pluginClassLoader - Separate class loader for the plugin or null
parent - Parent for the new plugin in the plugin tree
Returns:
The new plugin or null if it could not be instantiated

createInstance

public Plugin createInstance(java.lang.Class cls,
                             Plugin parent)
Create a new instance of the given class.

Parameters:
cls - Plugin class
parent - Parent for the new plugin in the plugin tree
Returns:
The new plugin or null if it could not be instantiated

createInstance

public Plugin createInstance(PluginState state,
                             Plugin parent)
Creates a new instance via a supplied state object.

Parameters:
state - Plugin state for the new plugin
parent - Parent for the new plugin in the plugin tree
Returns:
The new plugin or null if it could not be instantiated

createVisibleInstance

public VisiblePlugin createVisibleInstance(java.lang.String classname,
                                           Plugin parent)
Creates a new instance of the given plugin.

Parameters:
classname - Plugin class
parent - Parent for the new plugin in the plugin tree
Returns:
The new plugin or null if it could not be instantiated

createVisibleInstance

public VisiblePlugin createVisibleInstance(java.lang.Class cls,
                                           Plugin parent)
Create a new instance of the given class.

Parameters:
cls - Plugin class
parent - Parent for the new plugin in the plugin tree
Returns:
The new plugin or null if it could not be instantiated

createVisibleInstance

public VisiblePlugin createVisibleInstance(PluginState state,
                                           Plugin parent)
Creates a new instance via a supplied state object.

Parameters:
state - Plugin state for the new plugin
parent - Parent for the new plugin in the plugin tree
Returns:
The new plugin or null if it could not be instantiated

createCopy

public Plugin createCopy(Plugin source)
Creates a duplicate of the supplied plugin via its state object.

Parameters:
source - Plugin to copy
Returns:
The new plugin or null if it could not be instantiated

registerPlugin

public void registerPlugin(Plugin plugin)
Registers an externally created Plugin with the manager. This should only be used in special cases.

Parameters:
plugin - Plugin to register

removeInstance

public boolean removeInstance(java.lang.String uniqueId)
Removes the instance of a plugin with the given uniqueID.

Parameters:
uniqueId - Id of the plugin to remove
Returns:
true There are no instances of this plugin left.
false There is at least one instance alive.

removeInstance

public boolean removeInstance(Plugin plugin)
Removes a plugin from its container, uninstalls it and deletes it.

Parameters:
plugin - Plugin to remove
Returns:
true There are no instances of this plugin left.
false There is at least one instance alive.

getPluginInstances

public java.util.Iterator getPluginInstances(java.lang.String classname)
Gets all currently available instances of a given plugin (identified by its class name).

Parameters:
classname - Plugin class
Returns:
An iterator of Plugin objects

getPluginInstance

public Plugin getPluginInstance(java.lang.String classname)
Gets the instance of a given plugin (identified by its class name). The plugin is expected to be present only once in the system.

Parameters:
classname - Plugin class
Returns:
The instance or null if no such plugin exists

getPluginInstances

public java.util.List getPluginInstances()
Returns a list of all loaded plugins.

Returns:
A list of Plugin objects

loadCustomPlugins

public void loadCustomPlugins(java.lang.String settingName)
This method loads custom plugins that may be specified in a property file. The property file entry (e. g. in the Cockpit.properties file) - if present - is expected to contain a space- or comma-separated list of plugin class names to load. Any error will be printed to the output, but ignored otherwise. \bNote\b: This function is preliminary until a full-fledged xml-based plugin loading mechanism has been implemented.

Parameters:
settingName - Name of the property file entry (e. g.

loadPluginsFromResource

public void loadPluginsFromResource()
This method loads custom plugins from the 'plugin' directory. This directory contains a sub directory for each plugin. Each sub directory contains a plugin profile ending with '.plugin.xml' and any jar files needed by the plugin.



Copyright © 2011. All Rights Reserved.