Class LegacyPluginServiceImpl

java.lang.Object
org.dspace.core.LegacyPluginServiceImpl
All Implemented Interfaces:
PluginService

public class LegacyPluginServiceImpl extends Object implements 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:

  1. 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.
  2. 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.
  3. 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 Details

  • 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 the PluginConfigurationError is 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:
      getSinglePlugin in interface PluginService
      Parameters:
      interfaceClass - interface Class object
      Returns:
      instance of plugin
      Throws:
      PluginConfigurationError - if no matching singleton plugin is configured.
      PluginInstantiationException
    • getPluginSequence

      public Object[] getPluginSequence(Class interfaceClass) throws PluginInstantiationException
      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:
      getPluginSequence in interface PluginService
      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

      public Object getNamedPlugin(Class interfaceClass, String name) throws PluginInstantiationException
      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:
      getNamedPlugin in interface PluginService
      Parameters:
      interfaceClass - the interface class of the plugin
      name - 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: PluginService
      This method has been created to have a way of clearing the cache kept in the PluginService
      Specified by:
      clearNamedPluginClasses in interface PluginService
    • 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:
      hasNamedPlugin in interface PluginService
      Parameters:
      interfaceClass - the interface class of the plugin
      name - under which the plugin implementation is configured.
      Returns:
      true if plugin was found to be configured, false otherwise
      Throws:
      PluginInstantiationException
    • getAllPluginNames

      public String[] getAllPluginNames(Class interfaceClass)
      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:
      getAllPluginNames in interface PluginService
      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

      public void checkConfiguration() throws IOException
      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

      public void main(String[] argv) throws Exception
      Invoking this class from the command line just runs checkConfiguration and shows the results. There are no command-line options.
      Parameters:
      argv - the command line arguments given
      Throws:
      Exception - if error