Package org.java.plugin.standard
Class StandardPluginManager
- java.lang.Object
-
- org.java.plugin.PluginManager
-
- org.java.plugin.standard.StandardPluginManager
-
public final class StandardPluginManager extends PluginManager
Standard implementation of plug-in manager.- Version:
- $Id: StandardPluginManager.java,v 1.8 2007/04/07 12:41:01 ddimon Exp $
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.java.plugin.PluginManager
PluginManager.EventListener, PluginManager.EventListenerAdapter, PluginManager.PluginLocation
-
-
Field Summary
-
Fields inherited from class org.java.plugin.PluginManager
VERSION, VERSION_PROPERTY
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
StandardPluginManager(PluginRegistry aRegistry, PathResolver aPathResolver, PluginLifecycleHandler aLifecycleHandler)
Creates instance of plug-in manager for given registry, path resolver and life cycle handler.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
activatePlugin(java.lang.String id)
Activates plug-in with given ID if it is not activated yet.void
deactivatePlugin(java.lang.String id)
Deactivates plug-in with given ID if it has been successfully activated before.PluginDescriptor[]
disablePlugin(PluginDescriptor descr)
Disables plug-in (with dependencies) in this manager instance.PluginDescriptor[]
enablePlugin(PluginDescriptor descr, boolean includeDependings)
Enables plug-in (or plug-ins) in this manager instance.PathResolver
getPathResolver()
Plugin
getPlugin(java.lang.String id)
Looks for plug-in with given ID and activates it if it is not activated yet.PluginClassLoader
getPluginClassLoader(PluginDescriptor descr)
Returns instance of plug-in's class loader and not tries to activate plug-in.Plugin
getPluginFor(java.lang.Object obj)
Looks for plug-in, given object belongs to.PluginRegistry
getRegistry()
boolean
isBadPlugin(PluginDescriptor descr)
boolean
isPluginActivated(PluginDescriptor descr)
boolean
isPluginActivating(PluginDescriptor descr)
boolean
isPluginEnabled(PluginDescriptor descr)
java.util.Map<java.lang.String,Identity>
publishPlugins(PluginManager.PluginLocation[] locations)
Registers plug-ins and their locations with this plug-in manager.void
registerListener(PluginManager.EventListener listener)
Registers plug-in manager event listener.void
shutdown()
Shuts down the framework.void
unregisterListener(PluginManager.EventListener listener)
Unregisters manager event listener.-
Methods inherited from class org.java.plugin.PluginManager
disposeClassLoader, initPlugin, lookup, notifyClassLoader, startPlugin, stopPlugin
-
-
-
-
Constructor Detail
-
StandardPluginManager
protected StandardPluginManager(PluginRegistry aRegistry, PathResolver aPathResolver, PluginLifecycleHandler aLifecycleHandler)
Creates instance of plug-in manager for given registry, path resolver and life cycle handler.- Parameters:
aRegistry
- some implementation of plug-in registry interfaceaPathResolver
- some implementation of path resolver interfaceaLifecycleHandler
- an implementation of plug-in life cycle handler- See Also:
StandardObjectFactory
-
-
Method Detail
-
getRegistry
public PluginRegistry getRegistry()
- Specified by:
getRegistry
in classPluginManager
- Returns:
- registry, used by this manager
- See Also:
PluginManager.getRegistry()
-
getPathResolver
public PathResolver getPathResolver()
- Specified by:
getPathResolver
in classPluginManager
- Returns:
- path resolver
- See Also:
PluginManager.getPathResolver()
-
publishPlugins
public java.util.Map<java.lang.String,Identity> publishPlugins(PluginManager.PluginLocation[] locations) throws JpfException
Registers plug-ins and their locations with this plug-in manager. You should use this method to register new plug-ins to make them available for activation with this manager instance (compare this toPluginRegistry.register(URL[])
method that just makes plug-in's meta-data available for reading and doesn't "know" where are things actually located).- Specified by:
publishPlugins
in classPluginManager
- Parameters:
locations
- plug-in locations data- Returns:
- map where keys are manifest URL's and values are registered plug-ins or plug-in fragments, URL's for unprocessed manifests are not included
- Throws:
JpfException
- if given plug-ins can't be registered or published (optional behavior)- See Also:
PluginDescriptor
,PluginFragment
-
getPlugin
public Plugin getPlugin(java.lang.String id) throws PluginLifecycleException
Looks for plug-in with given ID and activates it if it is not activated yet. Note that this method will never returnnull
.- Specified by:
getPlugin
in classPluginManager
- Parameters:
id
- plug-in ID- Returns:
- found plug-in
- Throws:
PluginLifecycleException
- if plug-in can't be found or activated
-
activatePlugin
public void activatePlugin(java.lang.String id) throws PluginLifecycleException
Activates plug-in with given ID if it is not activated yet.- Specified by:
activatePlugin
in classPluginManager
- Parameters:
id
- plug-in ID- Throws:
PluginLifecycleException
- if plug-in can't be found or activated
-
getPluginFor
public Plugin getPluginFor(java.lang.Object obj)
Looks for plug-in, given object belongs to.- Specified by:
getPluginFor
in classPluginManager
- Parameters:
obj
- any object that maybe belongs to some plug-in- Returns:
- plug-in or
null
if given object doesn't belong to any plug-in (possibly it is part of "host" application) and thus doesn't managed by the Framework directly or indirectly
-
isPluginActivated
public boolean isPluginActivated(PluginDescriptor descr)
- Specified by:
isPluginActivated
in classPluginManager
- Parameters:
descr
- plug-in descriptor- Returns:
true
if plug-in with given descriptor is activated
-
isBadPlugin
public boolean isBadPlugin(PluginDescriptor descr)
- Specified by:
isBadPlugin
in classPluginManager
- Parameters:
descr
- plug-in descriptor- Returns:
true
if plug-in disabled as it's activation fails
-
isPluginActivating
public boolean isPluginActivating(PluginDescriptor descr)
- Specified by:
isPluginActivating
in classPluginManager
- Parameters:
descr
- plug-in descriptor- Returns:
true
if plug-in is currently activating
-
getPluginClassLoader
public PluginClassLoader getPluginClassLoader(PluginDescriptor descr)
Returns instance of plug-in's class loader and not tries to activate plug-in. Use this method if you need to get access to plug-in resources and don't want to cause plug-in activation.- Specified by:
getPluginClassLoader
in classPluginManager
- Parameters:
descr
- plug-in descriptor- Returns:
- class loader instance for plug-in with given descriptor
-
shutdown
public void shutdown()
Shuts down the framework.
Calling this method will deactivate all active plug-ins in order, reverse to the order they was activated. It also releases all resources allocated by this manager (class loaders, plug-in descriptors etc.). All disabled plug-ins will be marked as "enabled", all registered event listeners will be unregistered.- Specified by:
shutdown
in classPluginManager
-
deactivatePlugin
public void deactivatePlugin(java.lang.String id)
Deactivates plug-in with given ID if it has been successfully activated before. Note that this method will effectively deactivate all plug-ins that depend on the given plug-in.- Specified by:
deactivatePlugin
in classPluginManager
- Parameters:
id
- plug-in ID
-
disablePlugin
public PluginDescriptor[] disablePlugin(PluginDescriptor descr)
Disables plug-in (with dependencies) in this manager instance. Disabled plug-in can't be activated although it may be valid and successfully registered with plug-in registry. Before disabling, plug-in will be deactivated if it was successfully activated.
Be careful with this method as it can effectively disable large set of inter-depending plug-ins and your application may become unstable or even disabled as whole.- Specified by:
disablePlugin
in classPluginManager
- Parameters:
descr
- descriptor of plug-in to be disabled- Returns:
- descriptors of plug-ins that was actually disabled
-
enablePlugin
public PluginDescriptor[] enablePlugin(PluginDescriptor descr, boolean includeDependings)
Enables plug-in (or plug-ins) in this manager instance.- Specified by:
enablePlugin
in classPluginManager
- Parameters:
descr
- descriptor of plug-in to be enabledincludeDependings
- iftrue
, depending plug-ins will be also enabled- Returns:
- descriptors of plug-ins that was actually enabled
- See Also:
disablePlugin(PluginDescriptor)
-
isPluginEnabled
public boolean isPluginEnabled(PluginDescriptor descr)
- Specified by:
isPluginEnabled
in classPluginManager
- Parameters:
descr
- plug-in descriptor- Returns:
true
if given plug-in is disabled in this manager
-
registerListener
public void registerListener(PluginManager.EventListener listener)
Registers plug-in manager event listener. If given listener has been registered before, this method will throw anIllegalArgumentException
.- Specified by:
registerListener
in classPluginManager
- Parameters:
listener
- new manager event listener
-
unregisterListener
public void unregisterListener(PluginManager.EventListener listener)
Unregisters manager event listener. If given listener hasn't been registered before, this method will throw anIllegalArgumentException
.- Specified by:
unregisterListener
in classPluginManager
- Parameters:
listener
- registered listener
-
-