Class LegacyPluginServiceImpl
- All Implemented Interfaces:
PluginService
The Legacy Plugin Service is a very simple component container (based on the legacy PluginManager class from 5.x or below). It reads defined "plugins" (interfaces) from config file(s) and makes them available to the API. (TODO: Someday, this entire "plugin" framework needs to be replaced by Spring Beans.)
It creates and organizes components (plugins), and helps select a plugin in the cases where there are many possible choices. It also gives some limited control over the lifecycle of a plugin. It manages three different types (usage patterns) of plugins:
- Singleton Plugin
There is only one implementation class for the plugin. It is indicated in the configuration. This type of plugin chooses an implementations of a service, for the entire system, at configuration time. Your application just fetches the plugin for that interface and gets the configured-in choice. - Sequence Plugins
You need a sequence or series of plugins, to implement a mechanism like StackableAuthenticationMethods or a pipeline, where each plugin is called in order to contribute its implementation of a process to the whole. - Named Plugins
Use a named plugin when the application has to choose one plugin implementation out of many available ones. Each implementation is bound to one or more names (symbolic identifiers) in the configuration.
The name is just a String to be associated with the
combination of implementation class and interface. It may contain
any characters except for comma (,) and equals (=). It may contain
embedded spaces. Comma is a special character used to separate
names in the configuration entry.
- Author:
- Larry Stone, Tim Donohue (turned old PluginManager into a PluginService)
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidValidate the entries in the DSpace Configuration relevant to LegacyPluginServiceImpl.voidThis method has been created to have a way of clearing the cache kept in the PluginServiceString[]getAllPluginNames(Class interfaceClass) Returns all of the names under which a named plugin implementing the interface can be requested (with getNamedPlugin()).getNamedPlugin(Class interfaceClass, String name) Returns an instance of a plugin that implements the interface and is bound to a name matching name.Object[]getPluginSequence(Class interfaceClass) Returns instances of all plugins that implement the interface, in an Array.getSinglePlugin(Class interfaceClass) Returns an instance of the singleton (single) plugin implementing the given interface.booleanhasNamedPlugin(Class interfaceClass, String name) Returns whether a plugin exists which implements the specified interface and has a specified name.voidInvoking this class from the command line just runscheckConfigurationand shows the results.
-
Field Details
-
configurationService
-
-
Constructor Details
-
LegacyPluginServiceImpl
protected LegacyPluginServiceImpl()
-
-
Method Details
-
getSinglePlugin
public Object getSinglePlugin(Class interfaceClass) throws PluginConfigurationError, PluginInstantiationException Returns an instance of the singleton (single) plugin implementing the given interface. There must be exactly one single plugin configured for this interface, otherwise thePluginConfigurationErroris thrown.Note that this is the only "get plugin" method which throws an exception. It is typically used at initialization time to set up a permanent part of the system so any failure is fatal.
- Specified by:
getSinglePluginin interfacePluginService- Parameters:
interfaceClass- interface Class object- Returns:
- instance of plugin
- Throws:
PluginConfigurationError- if no matching singleton plugin is configured.PluginInstantiationException
-
getPluginSequence
Returns instances of all plugins that implement the interface, in an Array. Returns an empty array if no there are no matching plugins.The order of the plugins in the array is the same as their class names in the configuration's value field.
- Specified by:
getPluginSequencein interfacePluginService- Parameters:
interfaceClass- interface for which to find plugins.- Returns:
- an array of plugin instances; if none are available an empty array is returned.
- Throws:
PluginInstantiationException
-
getNamedPlugin
Returns an instance of a plugin that implements the interface and is bound to a name matching name. If there is no matching plugin, it returns null. The names are matched by String.equals().- Specified by:
getNamedPluginin interfacePluginService- Parameters:
interfaceClass- the interface class of the pluginname- under which the plugin implementation is configured.- Returns:
- instance of plugin implementation, or null if there is no match or an error.
- Throws:
PluginInstantiationException
-
clearNamedPluginClasses
public void clearNamedPluginClasses()Description copied from interface:PluginServiceThis method has been created to have a way of clearing the cache kept in the PluginService- Specified by:
clearNamedPluginClassesin interfacePluginService
-
hasNamedPlugin
public boolean hasNamedPlugin(Class interfaceClass, String name) throws PluginInstantiationException Returns whether a plugin exists which implements the specified interface and has a specified name. If a matching plugin is found to be configured, return true. If there is no matching plugin, return false.- Specified by:
hasNamedPluginin interfacePluginService- Parameters:
interfaceClass- the interface class of the pluginname- under which the plugin implementation is configured.- Returns:
- true if plugin was found to be configured, false otherwise
- Throws:
PluginInstantiationException
-
getAllPluginNames
Returns all of the names under which a named plugin implementing the interface can be requested (with getNamedPlugin()). The array is empty if there are no matches. Use this to populate a menu of plugins for interactive selection, or to document what the possible choices are.NOTE: The names are NOT returned in any deterministic order.
- Specified by:
getAllPluginNamesin interfacePluginService- Parameters:
interfaceClass- plugin interface for which to return names.- Returns:
- an array of strings with every name; if none are available an empty array is returned.
-
checkConfiguration
Validate the entries in the DSpace Configuration relevant to LegacyPluginServiceImpl. Look for inconsistencies, illegal syntax, etc. Announce violations with "log.error" so they appear in the log or in the standard error stream if this is run interactively.- Look for duplicate keys (by parsing the config file)
- Interface in plugin.single, plugin.sequence, plugin.named, plugin.selfnamed is valid.
- Classname in plugin.reusable exists and matches a plugin config.
- Classnames in config values exist.
- Classnames in plugin.selfnamed loads and is subclass of
SelfNamedPlugin - Implementations of named plugin have no name collisions.
- Named plugin entries lacking names.
- Throws:
IOException- if IO error
-
main
Invoking this class from the command line just runscheckConfigurationand shows the results. There are no command-line options.- Parameters:
argv- the command line arguments given- Throws:
Exception- if error
-