dsto.dfc.util.plugins
Class PluginManager

java.lang.Object
  extended by dsto.dfc.util.plugins.PluginManager

public class PluginManager
extends Object

Manages dynamic loading of plugin classes contained in a JAR file. A plugin JAR (usually with a ".jpi" extension) must have a "Plugin-Class" property in its manifest specifying the plugin initialisation class. When loaded, the plugin class's

   public static void initPlugin ()
 

method is called. This method may perform any initialisation required by the plugin.

NOTE: For plugins to work, the system must be using DfcClassLoader to load the application. See BootStrapLoader for one way to accomplish this.

Version:
$Revision$

Field Summary
static PluginManager INSTANCE
           
static String PLUGIN_EXTENSION
           
static FilenameFilter PLUGIN_FILENAME_FILTER
           
protected  ArrayList plugins
           
protected  URLSearchPath searchPath
           
 
Constructor Summary
protected PluginManager()
           
 
Method Summary
 String addPlugin(String path)
          Load a plugin and initialise it.
 void addSearchPathEntry(String directory)
           
 void addToPluginClasspath(String newPathEntry)
          Add a new entry to the plugin classpath.
 String getPluginClassName(String path)
          Returns the name of the jar file plugin class, or null if no "Plugin-Class" manifest attributes was defined.
static String getPluginName(String path)
          Get the logical name for a plugin.
 String[] getPlugins()
          Get the loaded plugin names.
protected  void initPluginClass(String path)
           
 boolean isPluginLoaded(String path)
          Test whether a plugin is loaded.
 String[] listPlugins()
          Find all plugins currently available on the plugin search path.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PLUGIN_EXTENSION

public static final String PLUGIN_EXTENSION
See Also:
Constant Field Values

PLUGIN_FILENAME_FILTER

public static final FilenameFilter PLUGIN_FILENAME_FILTER

INSTANCE

public static final PluginManager INSTANCE

plugins

protected ArrayList plugins

searchPath

protected URLSearchPath searchPath
Constructor Detail

PluginManager

protected PluginManager()
Method Detail

addSearchPathEntry

public void addSearchPathEntry(String directory)

listPlugins

public String[] listPlugins()
Find all plugins currently available on the plugin search path.


getPlugins

public String[] getPlugins()
Get the loaded plugin names.


getPluginName

public static String getPluginName(String path)
Get the logical name for a plugin. The logical name is the plugin path name, minus any directories and the extension.


isPluginLoaded

public boolean isPluginLoaded(String path)
Test whether a plugin is loaded.

Parameters:
path - A plugin path or logical name.
Returns:
True if plugin is logical.

addPlugin

public String addPlugin(String path)
                 throws PluginException
Load a plugin and initialise it. If plugin has already been loaded this has no effect.

Parameters:
path - The path pointing to the plugin file.
Returns:
The logical name by which the plugin is known. This is the plugin file name, minus any directories and the extension.
Throws:
PluginException
See Also:
isPluginLoaded(java.lang.String), getPluginName(java.lang.String)

addToPluginClasspath

public void addToPluginClasspath(String newPathEntry)
Add a new entry to the plugin classpath.


initPluginClass

protected void initPluginClass(String path)
                        throws IOException,
                               IllegalAccessException,
                               NoSuchMethodException,
                               InvocationTargetException,
                               ClassNotFoundException
Throws:
IOException
IllegalAccessException
NoSuchMethodException
InvocationTargetException
ClassNotFoundException

getPluginClassName

public String getPluginClassName(String path)
                          throws IOException
Returns the name of the jar file plugin class, or null if no "Plugin-Class" manifest attributes was defined.

Throws:
IOException


Copyright © 2008 Commonwealth of Australia