public class PluginsManager
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
PluginsManager.PluginPeer
This class represents a Plugin in the application.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
KEY_PLUGIN_CLASS
"MDIPluginClass":The Plugin ClassPath manifest key.
|
static java.lang.String |
KEY_PLUGIN_DEPENDENCIES
"MDIPluginDependencies": The manifest key to set the list of other Plugins on which this Plugin is dependant on.
|
static java.lang.String |
KEY_PLUGIN_TYPE
"MDIPluginType":The Plugin type manifest key.
|
static java.net.URL |
PLUGINS_XSD
The Plugins XML configuration file Schema.
|
Constructor and Description |
---|
PluginsManager(java.io.File pluginsDir)
Constructor, with only one directory containing the Plugins paths.
|
PluginsManager(java.io.File pluginsDir,
java.io.File pluginsConfig)
Constructor, with only one directory containing the Plugins paths.
|
PluginsManager(java.util.List<java.net.URL> pluginsDirList)
Constructor, with as many URLs as necessary containing the Plugins paths.
|
Modifier and Type | Method and Description |
---|---|
void |
addListener(PluginsListener listener)
Add a Plugin Listener.
|
void |
applyCommandLineArguments()
Apply the launch arguments.
|
void |
dispose()
Ask each Plugin to dispose of its resources.
|
void |
emitException(java.lang.Throwable e,
java.lang.String message,
short type)
Emit an exception.
|
void |
emitException(java.lang.Throwable e,
java.lang.String message,
java.lang.String name,
short type)
Emit an exception for a Plugin.
|
boolean |
executeCustomAction(java.lang.String actionName,
short blockingType,
java.lang.Object... arguments)
Execute a custom action.
|
java.net.URLClassLoader |
getClassloader()
Return the classLoader used to load the plugins.
|
java.util.Map<java.lang.String,java.lang.Short> |
getCustomActions()
Return the custom actions.
|
java.util.Map<java.lang.String,java.lang.Boolean> |
getEnabledPlugins()
Returned the enabled Plugins of this application.
|
java.util.Map<java.lang.String,Plugin> |
getLoadedPluginList()
Return the list of available Plugins, for the plugins who have successfuly been loaded.
|
java.util.List<Plugin> |
getLoadedPlugins()
Return the list of loaded Plugins.
|
MDIApplication |
getMDIApplication()
Return the application.
|
java.util.Map<java.lang.String,PluginsManager.PluginPeer> |
getPluginList()
Return the list of available Plugins.
|
int |
getPluginsSize()
Return the number of loaded Plugins.
|
java.io.File |
getStartDirectory()
Return the starting directory.
|
void |
initAfterGUI(MDIApplication app)
Called after the GUI initialization.
|
void |
initPlugins(MDIApplication app)
Initialize all plugins.
|
java.lang.Object |
loadAndInstanciatePluginClass(java.lang.String name)
Load a class found in a Plugin, and create a new instance from this class.
|
java.lang.Class<?> |
loadPluginClass(java.lang.String name)
Load a class found in a Plugin.
|
void |
registerPlugins(MDIApplication app)
Register all Plugins.
|
void |
removeListener(PluginsListener listener)
Remove a Plugin listener.
|
void |
resetPluginSettings()
Reset all the Plugins Settings.
|
void |
setAdditionalPluginTypes(java.util.Map<java.lang.String,AppliManifestType> additionalPluginTypes)
Set additional Plugin types for the Plugin manager.
|
void |
setAllowedPluginTypes(java.util.Map<java.lang.String,java.lang.Boolean> allowedPluginTypes)
Set the allowed Plugins Types for the Plugin manager.
|
void |
setApplicationID(java.lang.String applicationID)
Set the Application ID.
|
void |
setCustomActions(java.util.Map<java.lang.String,java.lang.Short> customActions)
Add a custom action.
|
void |
setEnabledPlugins(java.util.Map<java.lang.String,java.lang.Boolean> enabledPlugins)
Returned the enabled Plugins of this application.
|
void |
setManagerListener(PluginsManagerListener listener)
Set a listener which will be fired for each exception encountered during the Plugins loading, or some informations on the Plugins loading.
|
void |
setMDIApplication(MDIApplication app)
Set the application.
|
void |
setPluginsEDTSupport(PluginsEDTSupport pluginsEDTSupport)
Set the initialization support of the
MDIPlugin s. |
void |
setProgress(ProgressInterface progress,
int progressMax)
Configure the Progress bar during the Plugins loading and initialization.
|
void |
setStartDirectory(java.io.File dir)
Set the starting directory.
|
public static final java.net.URL PLUGINS_XSD
public static final java.lang.String KEY_PLUGIN_TYPE
setAllowedPluginTypes(java.util.Map)
method. Plugins which are not allowed will not be loaded by the PluginsManager.public static final java.lang.String KEY_PLUGIN_CLASS
setApplicationID(java.lang.String)
value.
MDIPluginClass: org.mypackage.MyClassIn this case the parser will return org.mypackage.MyClass in all cases.
MDIPluginClass: appli:org.mypackage.MyClassIn this case the parser will return "org.mypackage.MyClass" if the PluginManager is initialized with "appli" or null, and null in all other cases.
MDIPluginClass: appli:org.mypackage.MyClass;appli2:org.mypackage.MyClass2In this case the parser will return "org.mypackage.MyClass" if the parser is initialized with "appli" or null, "org.mypackage.MyClass2" if the parser is initialized with "appli2", and null in all other cases.
public static final java.lang.String KEY_PLUGIN_DEPENDENCIES
PluginElementTypes.PROPERTY_DEPEND
property, the manage won't even try to load the Plugin
if a Plugin on which the associated Plugin depends on is not present.
Note that:
KEY_PLUGIN_CLASS
)MDIPluginClass: org.package1.plugin1And another one with the following manifest declarations:
MDIPluginClass: org.package2.plugin2 MDIPluginDependencies: org.package1.plugin1The second Plugin will only be loaded if the first one is found and loaded.
MDIPluginClass: org.package1.plugin1and:
MDIPluginClass: org.package2.plugin2And a last one with the following manifest declarations:
MDIPluginClass: org.package3.plugin3 MDIPluginDependencies: org.package1.plugin1;org.package2.plugin2
MDIPluginClass: appli1:org.package1.plugin1;appli2:org.package1.plugin2And another one with the following manifest declarations:
MDIPluginClass: org.package3.plugin3 MDIPluginDependencies: org.package1.plugin1The second Plugin will only be loaded if the first one is found and loaded, wheach means that it won't be loaded if the application ID is different from "appli1".
public PluginsManager(java.io.File pluginsDir, java.io.File pluginsConfig)
Plugin
class is defined in a XML
File.
The Schema of the File is:
<xs:element name="Plugins"> <xs:complexType> <xs:sequence> <xs:element maxOccurs="unbounded" ref="plugin" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="plugin"> <xs:complexType> <xs:attribute name="mainclass" type="xs:string" use="required" /> <xs:attribute name="desc" type="xs:string" /> </xs:complexType> </xs:element>
Example, for one Plugin:
<Plugins> <plugin mainclass="org.mdi.examples.simple.plugins.OpenImagePlugin" desc="OpenImagePlugin" /> </Plugins>
pluginsDir
- the directory were to look for Plugins packaged as Jar FilespluginsConfig
- the XML File name used to define the path to the Plugin
classespublic PluginsManager(java.util.List<java.net.URL> pluginsDirList)
Plugin
class is in the Plugin
Manifest.
The Manifest contain several specific attributes:
Plugin
classpluginsDirList
- the URL list listing directories containing the plugins, or the plugins Jar themselvespublic PluginsManager(java.io.File pluginsDir)
Plugin
class is in the Plugin
Manifest.
The Manifest contain several specific attributes:
Plugin
classpluginsDir
- the directory were to look for Plugins packaged as Jar Filespublic void setMDIApplication(MDIApplication app)
app
- the applicationpublic MDIApplication getMDIApplication()
public void setStartDirectory(java.io.File dir)
dir
- the starting directorypublic java.io.File getStartDirectory()
public void setPluginsEDTSupport(PluginsEDTSupport pluginsEDTSupport)
MDIPlugin
s.pluginsEDTSupport
- the EDT supportMDIPluginsInitMode
public void setManagerListener(PluginsManagerListener listener)
listener
- the listenerpublic void setApplicationID(java.lang.String applicationID)
applicationID
- the Application IDpublic void setProgress(ProgressInterface progress, int progressMax)
progress
- the Progress barprogressMax
- the maximum value of the progress bar at the end of the initializationpublic void setAdditionalPluginTypes(java.util.Map<java.lang.String,AppliManifestType> additionalPluginTypes)
setAllowedPluginTypes(java.util.Map)
, the manifest
key for these types is up to the application. It allows to define additional constraints which will define if Plugins will be loaded.
additionalPluginTypes
- the Map of additional Plugin typespublic void setAllowedPluginTypes(java.util.Map<java.lang.String,java.lang.Boolean> allowedPluginTypes)
allowedPluginTypes
- the allowed Plugin Types as a MapsetAdditionalPluginTypes(java.util.Map)
public java.net.URLClassLoader getClassloader()
public java.lang.Class<?> loadPluginClass(java.lang.String name)
It is necessary to use this method to load any classes found in Plugins, except the core class that implements the Plugin
interface, because only
the PluginManager get holds of the classLoader that is able to load all the Plugins
name
- the class namepublic void emitException(java.lang.Throwable e, java.lang.String message, short type)
e
- the throwablemessage
- the messagetype
- the exception typepublic void emitException(java.lang.Throwable e, java.lang.String message, java.lang.String name, short type)
e
- the throwablemessage
- the messagename
- the plugin nametype
- the exception typepublic void initAfterGUI(MDIApplication app)
MDIPlugin.initAfterGUI(org.mdi.bootstrap.MDIApplication)
for each MDIPlugin
.app
- the MDIApplicationpublic void applyCommandLineArguments()
public java.lang.Object loadAndInstanciatePluginClass(java.lang.String name)
name
- the class nameloadPluginClass(String)
public void addListener(PluginsListener listener)
listener
- the Plugin Listenerpublic void removeListener(PluginsListener listener)
listener
- the Plugin Listenerpublic int getPluginsSize()
public void resetPluginSettings()
public void initPlugins(MDIApplication app)
app
- the Applicationpublic void registerPlugins(MDIApplication app) throws org.xml.sax.SAXException, java.io.IOException
Plugin
classapp
- the Applicationorg.xml.sax.SAXException
- if a SAXException is encountered while registering the Pluginsjava.io.IOException
- if an IOException is encountered while registering the Pluginspublic java.util.List<Plugin> getLoadedPlugins()
getPluginList()
public java.util.Map<java.lang.String,PluginsManager.PluginPeer> getPluginList()
PluginsManager.PluginPeer
.
A Plugin in the plugin configuration file will be added in this list if the loading process of the Plugin main class is successful. However, the Plugin
will really be loaded (and associated actions created) only if it have been enabled.getLoadedPlugins()
,
getLoadedPluginList()
public void dispose()
public java.util.Map<java.lang.String,Plugin> getLoadedPluginList()
getLoadedPlugins()
public void setEnabledPlugins(java.util.Map<java.lang.String,java.lang.Boolean> enabledPlugins)
enabledPlugins
- the enabled Pluginspublic java.util.Map<java.lang.String,java.lang.Boolean> getEnabledPlugins()
public void setCustomActions(java.util.Map<java.lang.String,java.lang.Short> customActions)
customActions
- the custom actionspublic java.util.Map<java.lang.String,java.lang.Short> getCustomActions()
public boolean executeCustomAction(java.lang.String actionName, short blockingType, java.lang.Object... arguments)
actionName
- the custom action nameblockingType
- the blocking typearguments
- the arguments