org.java.plugin
Class PluginController

java.lang.Object
  extended by org.java.plugin.PluginController

public class PluginController
extends java.lang.Object

The plugin Controller provides methods to initialize the plugin framework, load plugin location and access plugins


Constructor Summary
PluginController(java.lang.ClassLoader pluginsClassLoader, ObjectFactory objectFactory)
           
 
Method Summary
 void activatePlugin(Plugin plugin)
          Activate plugin.
 void activatePlugin(PluginDescriptor descriptor)
          Activate plugin.
 void activatePlugin(java.lang.String id)
          Activate plugin.
 void addPluginLifecycleListener(PluginLifecycleListener listener)
          Adds a PluginLifecycleListener.
protected  void configureObjectFactory()
          Translates Application configuration to JPF ExtendedProperties before it configures and returns a new ObjectFactory.
static PluginController create()
          Create a new PluginController with default configuration
static PluginController create(java.util.Properties config)
          Create a new PluginController with a custom runtime configuration
static PluginController create(java.util.Properties config, java.util.List<? extends com.google.inject.Module> modules)
          Create a new PluginController with a custom runtime configuration and a list of Guice Modules used to configure the main Injector.
 java.util.Properties getConfiguration()
          Returns the current configuration
 PluginManager getJPFManager()
           
 Plugin getPlugin(java.lang.String uniqueID)
          Looks for plug-in with given ID and activates it if it is not activated yet.
 java.lang.ClassLoader getPluginClassLoader(PluginDescriptor descriptor)
          Access the Plugins Classloader
 java.util.List<PluginDescriptor> getPluginDescriptions()
          Returns a list of all currently available PluginDescriptors
 java.lang.ClassLoader getPluginsClassLoader()
          Access the global classloader
 void initialize(java.util.Properties config)
           
protected  void integrityCheck()
           
protected  java.lang.String integrityCheckReport2str(IntegrityCheckReport report)
           
protected  void loadConfiguration(java.util.Properties config)
          Load boot configuration.
The configuration defaults are hardcoded here and can easily be overwritten using a resource bundle.
 boolean registerLocation(java.io.File... location)
          Register a new plugin folder.
 void registerPlugins(java.net.URL... pluginURLs)
          Register custom plugins.
 void removePluginLifecycleListener(PluginLifecycleListener listener)
          Removed PluginLifecycleListener.
 void shutdown()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PluginController

@Inject
public PluginController(java.lang.ClassLoader pluginsClassLoader,
                               ObjectFactory objectFactory)
Method Detail

addPluginLifecycleListener

public void addPluginLifecycleListener(PluginLifecycleListener listener)
Adds a PluginLifecycleListener. Does nothing when listener was added before

Parameters:
listener - the listener
See Also:
PluginLifecycleListener

removePluginLifecycleListener

public void removePluginLifecycleListener(PluginLifecycleListener listener)
Removed PluginLifecycleListener. Does nothing when listener was not attached.

Parameters:
listener - the listener
See Also:
PluginLifecycleListener

initialize

public void initialize(java.util.Properties config)

configureObjectFactory

protected void configureObjectFactory()
Translates Application configuration to JPF ExtendedProperties before it configures and returns a new ObjectFactory.


getPluginsClassLoader

public java.lang.ClassLoader getPluginsClassLoader()
Access the global classloader

Returns:
classloader in global scope

getPluginClassLoader

public java.lang.ClassLoader getPluginClassLoader(PluginDescriptor descriptor)
Access the Plugins Classloader

Returns:
classloader for given plugin descriptor

getJPFManager

public PluginManager getJPFManager()
Returns:
jpfManager

registerLocation

public boolean registerLocation(java.io.File... location)
                         throws JpfException
Register a new plugin folder. This adds the given directory as plugin repository and restarts scanning.

Parameters:
location - the new location
Returns:
true if successfully registered
Throws:
JpfException - when an error occures while scanning for plugins

registerPlugins

public void registerPlugins(java.net.URL... pluginURLs)
                     throws JpfException
Register custom plugins. The given URLs must point to valid plugin definition XML files.

Parameters:
pluginURLs - the locations to register
Throws:
JpfException - in case registration fails

shutdown

public void shutdown()

loadConfiguration

protected void loadConfiguration(java.util.Properties config)
Load boot configuration.
The configuration defaults are hardcoded here and can easily be overwritten using a resource bundle. Also, overriding properties can be done using system properties or via command line configuration.
The load order is defaults->system properties->cmd line options

Parameters:
config - runtime configuration

getConfiguration

public java.util.Properties getConfiguration()
Returns the current configuration

Returns:
configuration of this plugin manager

integrityCheck

protected void integrityCheck()

integrityCheckReport2str

protected java.lang.String integrityCheckReport2str(IntegrityCheckReport report)

getPlugin

public Plugin getPlugin(java.lang.String uniqueID)
                 throws PluginLifecycleException
Looks for plug-in with given ID and activates it if it is not activated yet. Note that this method will never return null.

Parameters:
uniqueID - unique plugin id
Returns:
plugin or null
Throws:
PluginLifecycleException - if plugin could not be resolved

activatePlugin

public void activatePlugin(Plugin plugin)
                    throws PluginLifecycleException
Activate plugin. The Plugin becomes activated if it is not already active or in activating stage.

Parameters:
plugin - the plugin to be started
Throws:
PluginLifecycleException - if an error occures while the plugin is started

activatePlugin

public void activatePlugin(PluginDescriptor descriptor)
                    throws PluginLifecycleException
Activate plugin. The Plugin becomes activated if it is not already active or in activating stage.

Parameters:
descriptor - the plugin descriptor
Throws:
PluginLifecycleException - if an error occures while the plugin is started

activatePlugin

public void activatePlugin(java.lang.String id)
                    throws PluginLifecycleException
Activate plugin. The Plugin becomes activated if it is not already active or in activating stage.

Parameters:
id - the plugin to be started
Throws:
PluginLifecycleException - if an error occures while the plugin is started

getPluginDescriptions

public java.util.List<PluginDescriptor> getPluginDescriptions()
Returns a list of all currently available PluginDescriptors

Returns:
list of PluginDescriptors
See Also:
PluginDescriptor

create

public static PluginController create()
Create a new PluginController with default configuration

Returns:
pluginController with default configuration

create

public static PluginController create(java.util.Properties config)
Create a new PluginController with a custom runtime configuration

Parameters:
config - the runtime configuration
Returns:
pluginController with custom configuration

create

public static PluginController create(java.util.Properties config,
                                      java.util.List<? extends com.google.inject.Module> modules)
Create a new PluginController with a custom runtime configuration and a list of Guice Modules used to configure the main Injector.

Parameters:
config - the runtime configuration
modules - a list of modules
Returns:
pluginController with custom configuration


Copyright © 2010. All Rights Reserved.