com.virtuosotechnologies.lib.plugin
Class SimpleFramework

java.lang.Object
  extended bycom.virtuosotechnologies.lib.plugin.SimpleFramework
All Implemented Interfaces:
Framework

public class SimpleFramework
extends Object
implements Framework

A simple implementation of Framework. This implementation is for systems in which all plugins exist within the same Java VM (that is, a non-distributed system). The plug method uses the current thread to perform all plugin initialization.

This class is synchronized and thread-safe. Note, however, that Framework is generally not designed to be re-entrant (e.g. you can't have two calls to plug() happening simultaneously, whether in the same or different threads.)


Field Summary
 
Fields inherited from interface com.virtuosotechnologies.lib.plugin.Framework
CONTINUE_ON_DUPLICATE_PLUGINS_PROPERTY, CONTINUE_ON_SUPPRESSED_PLUGINS_PROPERTY, CURRENT_FRAMEWORK_APIVERSION
 
Constructor Summary
SimpleFramework()
          Constructor.
 
Method Summary
 void addFrameworkProgressListener(FrameworkProgressListener listener)
          Register a listener on the Framework.
 ObjectSet getAvailableAPINames()
          Get the names of the currently available APIs as an ObjectSet of Strings.
 ObjectSet getAvailableAPIVersions(String name)
          Get the names of the currently available versions of the given API as an ObjectSet of Strings.
 ObjectSet getPluginIDSet()
          Get the ids of the currently available plugins as an ObjectSet of PluginIDs.
 PluginInfo getPluginInfo(PluginID plugin)
          Get the PluginInfo object for the given plugin.
 RequestablePropertySet getProperties()
          Get properties of this Framework.
 PluginID getProvidingPluginFor(String name, APIVersion version)
          Get the PluginID of the plugin that provides the given API and version.
 void plug(PluginInfo[] infoArray)
          Attempt to plug in the given Plugins.
 APIProvider provideAPI(Class cls, APIVersion version, String description, Object impl)
          Register an API with no providing plugin.
 void removeFrameworkProgressListener(FrameworkProgressListener listener)
          Remove a listener on the Framework.
 void unplug(PluginID[] idArray)
          Attempt to unplug in the given Plugins.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleFramework

public SimpleFramework()
Constructor.

Method Detail

getProperties

public RequestablePropertySet getProperties()
Get properties of this Framework.

Specified by:
getProperties in interface Framework
Returns:
RequestablePropertySet containing properties, some of which may be editable

getPluginIDSet

public ObjectSet getPluginIDSet()
Get the ids of the currently available plugins as an ObjectSet of PluginIDs. The ObjectSet tracks changes to the installed plugins.

Specified by:
getPluginIDSet in interface Framework
Returns:
ObjectSet of Strings

getPluginInfo

public PluginInfo getPluginInfo(PluginID plugin)
Get the PluginInfo object for the given plugin. Returns null if the plugin id is not present.

Specified by:
getPluginInfo in interface Framework
Parameters:
plugin - plugin id
Returns:
PluginInfo

getAvailableAPINames

public ObjectSet getAvailableAPINames()
Get the names of the currently available APIs as an ObjectSet of Strings. The ObjectSet tracks changes to the available APIs.

Specified by:
getAvailableAPINames in interface Framework
Returns:
ObjectSet of Strings

getAvailableAPIVersions

public ObjectSet getAvailableAPIVersions(String name)
Get the names of the currently available versions of the given API as an ObjectSet of Strings. The ObjectSet tracks changes to the available APIs.

Specified by:
getAvailableAPIVersions in interface Framework
Parameters:
name - name of API to query
Returns:
ObjectSet of APIVersions, or null if the given API is not found.

getProvidingPluginFor

public PluginID getProvidingPluginFor(String name,
                                      APIVersion version)
                               throws APINotAvailableException
Get the PluginID of the plugin that provides the given API and version. You need to specify the exact API version.

Specified by:
getProvidingPluginFor in interface Framework
Parameters:
name - name of API to query
version - version of API to query
Returns:
PluginID of the plugin providing the API, or null if it's being provided directly through the framework.
Throws:
APINotAvailableException - the given api and version not provided.

provideAPI

public APIProvider provideAPI(Class cls,
                              APIVersion version,
                              String description,
                              Object impl)
                       throws DuplicateAPIException
Register an API with no providing plugin.

Specified by:
provideAPI in interface Framework
Parameters:
cls - interface class
version - API version
description - description String
impl - implementation object
Returns:
the newly-created APIProvider
Throws:
DuplicateAPIException - the given API version already exists.

plug

public void plug(PluginInfo[] infoArray)
          throws PluginException
Attempt to plug in the given Plugins. Note that this method is not re-entrant. For example, it cannot be called from within a plugin's initialization or cleanup code.

Specified by:
plug in interface Framework
Parameters:
infoArray - array of PluginInfo objects
Throws:
PluginException - couldn't start up the plugins
IllegalStateException - a plug or unplug job is already in progress

unplug

public void unplug(PluginID[] idArray)
            throws PluginException
Attempt to unplug in the given Plugins. Note that this method is not re-entrant. For example, it cannot be called from within a plugin's initialization or cleanup code.

Specified by:
unplug in interface Framework
Parameters:
idArray - array of name PluginIDs
Throws:
PluginException - couldn't shut down the plugins
IllegalStateException - a plug or unplug job is already in progress

addFrameworkProgressListener

public void addFrameworkProgressListener(FrameworkProgressListener listener)
Register a listener on the Framework.

Specified by:
addFrameworkProgressListener in interface Framework
Parameters:
listener - the listener

removeFrameworkProgressListener

public void removeFrameworkProgressListener(FrameworkProgressListener listener)
Remove a listener on the Framework.

Specified by:
removeFrameworkProgressListener in interface Framework
Parameters:
listener - the listener