public class IlvPluginManager extends Object
IlvPlugin
.
It also saves and restores the settings of
the plug-ins from the user settings of the application. For example, it
saves in the user settings if the plug-ins
were installed during the last application session.
Where are the plug-ins of an application?
A plug-in manager finds its plug-ins in a root directory that is accessed
with the methods setRootDirectory(java.io.File)
and getRootDirectory()
.
Basically, one plug-in is defined for each subdirectory of this
root directory. In each subdirectory, the plug-in manager looks for
a plugin.xml
file that defines the plug-in. If no such file
is found, the directory is not considered to contain a
plug-in.
A plugin can also be contained in a jar. In this case, the method
setRootDirectory(java.io.File)
cannot be used. Instead, the location of
the file plugin.xml
inside the jar must be given to the
manager as root URL with the method setRootURL(java.net.URL)
.
How to create a plug-in manager?
Here is a schematic code example that creates and initializes a plug-in
manager. The plug-ins are contained in a root directory:
java.io.File pluginsRootDirectory = ... IlvApplication application = ... ... IlvPluginManager pluginManager = new IlvPluginManager(); pluginManager.setRootDirectory(pluginsRootDirectory); pluginManager.setApplication(application); ... application.initialize();Here is a schematic code example for the case that the plug-in is contained inside a jar file:
java.net.URL pluginURL = getClass().getResource("plugin.xml"); IlvApplication application = ... ... IlvPluginManager pluginManager = new IlvPluginManager(); pluginManager.setRootURL(pluginURL); pluginManager.setApplication(application); ... application.initialize();It is important that a plug-in is initialized and set to an application before the application is initialized. The plug-in manager must be able to add the resource files (settings and internationalization files) of its plug-ins before the application initializes the components that depend on those settings. (See
IlvApplication.initialize()
.)
You can find documentation and examples of using plug-ins in the Rogue Wave JViews Application Framework User's Manual, in the chapter on Plug-ins.
IlvPlugin
Modifier and Type | Field and Description |
---|---|
static String |
INSTALL_BY_DEFAULT
Installation mode that specifies that a plug-in should automatically be installed
when launching the application.
|
static String |
NEVER_INSTALL_BY_DEFAULT
Installation mode that specifies never to install a plug-in by default
when launching the application.
|
static String |
NOT_INSTALL_BY_DEFAULT
Installation mode that specifies not to install a plug-in by default
when launching the application.
|
Constructor and Description |
---|
IlvPluginManager()
Constructs an
IlvPluginManager . |
Modifier and Type | Method and Description |
---|---|
void |
addPluginListener(PluginListener listener)
Adds a plug-in listener for receiving plug-in events.
|
void |
addRootDirectory(File directory)
Adds the specified
directory to the list of directories
this plugin manager will scan to find its plugins. |
void |
addRootURL(URL url)
Adds the specified
url to the list of root URLs
this plugin manager will scan to find its plugins. |
protected void |
firePluginEvent(PluginEvent event)
Fires the specified plug-in
event to the plugin listeners
registered with this plug-in manager. |
IlvApplication |
getApplication()
Returns the application of the plug-in manager.
|
IlvPlugin |
getPlugin(int index)
Returns the plug-in stored at the specified
index . |
IlvPlugin |
getPlugin(String id)
Returns the plug-in with the specified ID.
|
int |
getPluginCount()
Returns the number of plug-ins of the plug-in manager.
|
static ArrayList<IlvPluginManager> |
getPluginManagers(IlvApplication application)
Returns the plugin managers of the application.
|
IlvPlugin[] |
getPlugins()
Returns the array of plug-ins owned by the plug-in manager.
|
IlvPlugin[] |
getRequiredPlugins(IlvPlugin plugin)
Returns the plug-ins that the specified
plugin depends on to be
installed. |
File |
getRootDirectory()
Returns the root directory containing all the plug-ins.
|
File |
getRootDirectory(int index)
Returns the root directory of this plugin manager at the specified
storage
index . |
int |
getRootDirectoryCount()
Returns the number of root directories that have been
specified to this plugin manager.
|
URL |
getRootURL()
Returns the root URL containing all the plug-ins.
|
URL |
getRootURL(int index)
Returns the root URL of this plugin manager at the specified
storage
index . |
int |
getRootURLCount()
Returns the number of root URLs that have been
specified to this plugin manager.
|
IlvSettings |
getSettings()
Returns the settings that initialize the plug-in manager.
|
IlvSettingsElement |
getSettingsElement()
Returns the settings element that provides the settings for this
plug-in manager.
|
IlvSettingsQuery |
getSettingsQuery()
Returns the query that selects the settings element of the plug-in manager.
|
boolean |
initializedOnUserSettings()
Determines whether the plug-in manager has been initialized with the
user settings.
|
boolean |
installPlugin(IlvPlugin plugin)
Installs the specified
plugin . |
protected void |
invokePluginInstaller(IlvPlugin plugin,
boolean install)
Invokes the
IlvPluginInstaller of the specified
plugin . |
protected boolean |
isInitiallyInstalled(IlvPlugin plugin)
Determines whether the specified plug-in should be installed when the
application is being launched.
|
void |
readPlugins()
Reads the plug-ins of the application.
|
protected void |
readSettings(IlvSettingsElement settingsElement)
Reads the settings of the plug-in manager.
|
void |
removePluginListener(PluginListener listener)
Removes the specified plug-in listener so that it no longer receives plug-in
events.
|
void |
setApplication(IlvApplication application)
Sets the
application that this plug-in manager will manage
the plug-ins for. |
void |
setRootDirectory(File directory)
Sets the root directory containing all the plug-ins.
|
void |
setRootURL(URL url)
Sets the root URL containing all the plug-ins.
|
void |
setSettings(IlvSettings settings)
Sets the settings of the plug-in manager.
|
void |
setSettingsElement(IlvSettingsElement element)
Forces the settings of the plug-in manager to be read and written from the
specified settings element.
|
void |
setSettingsQuery(IlvSettingsQuery query)
Sets the query that selects the settings element which defines the
plug-in manager.
|
boolean |
uninstallPlugin(IlvPlugin plugin,
boolean dependentPlugins)
Uninstalls the specified
plugin . |
void |
uninstallPlugins()
Uninstalls the plug-ins of the plug-in manager.
|
protected void |
writeSettings(IlvSettingsElement settingsElement)
Writes the settings of the plug-in manager.
|
public static final String INSTALL_BY_DEFAULT
If the plug-in has been uninstalled with the method
uninstallPlugin(IlvPlugin, boolean)
during the last application session,
the plug-in will not be installed automatically and must be explicitly
reinstalled with the method
installPlugin(IlvPlugin)
.
public static final String NOT_INSTALL_BY_DEFAULT
installPlugin(IlvPlugin)
during the last application session,
it will be installed when launching the application.INSTALL_BY_DEFAULT
,
Constant Field Valuespublic static final String NEVER_INSTALL_BY_DEFAULT
installPlugin(IlvPlugin)
.For example, this mode can be convenient for plug-ins where their installation depends on the arguments given to the application command line.
public void setApplication(IlvApplication application)
application
that this plug-in manager will manage
the plug-ins for.public IlvApplication getApplication()
public void setRootURL(URL url)
url
- The root URL.getRootURL()
,
addRootURL(URL)
public URL getRootURL()
setRootURL(java.net.URL)
,
getRootURL(int)
public void addRootURL(URL url)
url
to the list of root URLs
this plugin manager will scan to find its plugins.
Typically, this is the URL of the root directory of the plug-ins.
It can however also be the URL inside a jar that points to the file
plugin.xml that describes the plugin.url
- The new root URL of this plugin manager.getRootURL()
,
setRootURL(java.net.URL)
public int getRootURLCount()
addRootURL(URL)
,
setRootURL(java.net.URL)
public URL getRootURL(int index)
index
.index
- The storage index of the root URL to return.null
.addRootURL(URL)
,
setRootURL(java.net.URL)
,
getRootURLCount()
public void setRootDirectory(File directory)
directory
- The root file directory.getRootDirectory()
,
addRootDirectory(java.io.File)
public File getRootDirectory()
getRootURL()
.public void addRootDirectory(File directory)
directory
to the list of directories
this plugin manager will scan to find its plugins.directory
- The new root directory of this plugin manager.getRootDirectory()
,
setRootDirectory(java.io.File)
public int getRootDirectoryCount()
addRootURL(URL)
that do not correspond to any file, this method returns
nonsense. Therefore, it is usually safer to use getRootURLCount()
to retrieve the number of root URLs.addRootDirectory(java.io.File)
,
setRootDirectory(java.io.File)
public File getRootDirectory(int index)
index
.
If root URLs have been added to the plugin manager with addRootURL(URL)
that do not correspond to any file, this method returns
nonsense. Therefore, it is usually safer to use getRootURL(int)
to retrieve the root URL.index
- The storage index of the root directory to return.null
.addRootDirectory(java.io.File)
,
setRootDirectory(java.io.File)
,
getRootDirectoryCount()
public void readPlugins()
protected boolean isInitiallyInstalled(IlvPlugin plugin)
This method checks first whether the plug-in installer of the specified
plugin
authorizes the installation of the plug-in. If yes,
the install mode of the plug-in will be compared with the following
values:
INSTALL_BY_DEFAULT
: The plug-in is automatically
installed, unless it has been explicitly uninstalled in the previous
application session.NOT_INSTALL_BY_DEFAULT
: The plug-in is not automatically
installed, unless it has been explicitly installed in the previous
application session.NEVER_INSTALL_BY_DEFAULT
: The plug-in is never
automatically installed."installMode"
attribute
in the settings defining the specified plug-in.true
if the plug-in can be initially installed;
false
otherwise.IlvPlugin.getInstallMode()
,
IlvPluginInstaller.canInstall(ilog.views.appframe.IlvApplication, ilog.views.appframe.plugin.IlvPlugin)
public void uninstallPlugins() throws IlvPluginException
IlvPluginException
installPlugin(IlvPlugin)
public boolean installPlugin(IlvPlugin plugin) throws IlvPluginException
plugin
.plugin
- The plug-in to install.true
if the plug-in could be installed;
false
otherwise.IlvPluginException
uninstallPlugin(ilog.views.appframe.plugin.IlvPlugin, boolean)
public boolean uninstallPlugin(IlvPlugin plugin, boolean dependentPlugins) throws IlvPluginException
plugin
.
If the dependentPlugins
parameter is true
, all
the plug-ins that depend on this plug-in are uninstalled before the specified plug-in.plugin
- The plug-in to uninstall.dependentPlugins
- If true
all the plug-ins that depend
on the specified plug-in are uninstalled before the specified plug-in
is uninstalled; otherwise, only the specified plug-in is uninstalled.true
if the plug-in(s) could be uninstalled;
false
otherwise.IlvPluginException
installPlugin(IlvPlugin)
protected void invokePluginInstaller(IlvPlugin plugin, boolean install) throws Exception
IlvPluginInstaller
of the specified
plugin
.plugin
- The plugin to invoke the plugin installer from.install
- If true
, the IlvPluginInstaller.install(ilog.views.appframe.IlvApplication, ilog.views.appframe.plugin.IlvPlugin)
method of the plugin installer is called. Otherwise, the
IlvPluginInstaller.install(ilog.views.appframe.IlvApplication, ilog.views.appframe.plugin.IlvPlugin)
method of the plugin installer is
called.Exception
public int getPluginCount()
getPlugin(int)
,
getPlugins()
public IlvPlugin[] getPlugins()
getPlugin(int)
,
getPluginCount()
public IlvPlugin getPlugin(int index)
index
.index
- The storage index of the plug-in to return.getPlugin(String)
,
getPluginCount()
public IlvPlugin getPlugin(String id)
id
- The ID of the plug-in to return.null
if no
plug-in could be found with this ID.getPlugin(int)
public IlvPlugin[] getRequiredPlugins(IlvPlugin plugin)
plugin
depends on to be
installed.plugin
- The plug-in to retrieve the required plug-ins from.protected void readSettings(IlvSettingsElement settingsElement)
settingsElement
- The root settings element that contains the settings
of the plug-in manager.writeSettings(ilog.views.appframe.settings.IlvSettingsElement)
protected void writeSettings(IlvSettingsElement settingsElement)
settingsElement
- The root settings element for writing the settings
of the plug-in manager.readSettings(ilog.views.appframe.settings.IlvSettingsElement)
public IlvSettings getSettings()
readSettings(ilog.views.appframe.settings.IlvSettingsElement)
,
setSettings(ilog.views.appframe.settings.IlvSettings)
public void setSettings(IlvSettings settings)
settings
- The new settings of the plug-in manager.getSettings()
,
readSettings(ilog.views.appframe.settings.IlvSettingsElement)
public void setSettingsQuery(IlvSettingsQuery query)
query
- The settings query.getSettingsQuery()
,
readSettings(ilog.views.appframe.settings.IlvSettingsElement)
,
getSettingsElement()
public IlvSettingsQuery getSettingsQuery()
setSettingsQuery(ilog.views.appframe.settings.IlvSettingsQuery)
public void setSettingsElement(IlvSettingsElement element)
getSettings()
with the query getSettingsQuery()
.element
- The new settings element that provides the settings of the
plug-in manager.getSettingsElement()
,
getSettings()
,
getSettingsQuery()
public IlvSettingsElement getSettingsElement()
null
if no settings
element could be found.setSettingsElement(ilog.views.appframe.settings.IlvSettingsElement)
,
getSettingsQuery()
public boolean initializedOnUserSettings()
true
if the application has already been launched
for the current application user profile; false
otherwise.public void addPluginListener(PluginListener listener)
listener
- The plug-in listener to add.removePluginListener(ilog.views.appframe.plugin.PluginListener)
public void removePluginListener(PluginListener listener)
listener
- The plug-in listener to remove.addPluginListener(ilog.views.appframe.plugin.PluginListener)
protected void firePluginEvent(PluginEvent event)
event
to the plugin listeners
registered with this plug-in manager.event
- The event to fire.addPluginListener(ilog.views.appframe.plugin.PluginListener)
public static ArrayList<IlvPluginManager> getPluginManagers(IlvApplication application)
IlvPluginManager
objects.
It can return null
if no plugin manager was yet
installed at the application.© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.