Class AbstractPlugin<S extends PluginFeature>

java.lang.Object
org.itsallcode.whiterabbit.api.AbstractPlugin<S>
Type Parameters:
S - the supported PluginFeature.
All Implemented Interfaces:
Plugin

public abstract class AbstractPlugin<S extends PluginFeature> extends Object implements Plugin
Base class for plugins that support a defined PluginFeature.
  • Field Details

  • Constructor Details

    • AbstractPlugin

      protected AbstractPlugin(String id, Class<S> featureType)
      Constructor.
      Parameters:
      id - the id of the new plugin.
      featureType - the PluginFeature that the new plugin supports.
  • Method Details

    • init

      public void init(PluginConfiguration config)
      Description copied from interface: Plugin
      Called once when loading the plugin.
      Specified by:
      init in interface Plugin
      Parameters:
      config - the configuration of the plugin.
    • getId

      public final String getId()
      Description copied from interface: Plugin
      The ID of this plugin. IDs must be unique for all plugins. The ID is used as prefix for PluginConfiguration.getMandatoryValue(String).
      Specified by:
      getId in interface Plugin
      Returns:
      the ID of this plugin.
    • close

      public void close()
      Description copied from interface: Plugin
      Called before closing the plugin. The plugin should cleanup any resources in this method.
      Specified by:
      close in interface Plugin
    • supports

      public final boolean supports(Class<? extends PluginFeature> featureType)
      Description copied from interface: Plugin
      Check if this plugin supports the given feature.
      Specified by:
      supports in interface Plugin
      Parameters:
      featureType - the feature type.
      Returns:
      true if this plugin supports the given feature, else false.
    • createInstance

      protected abstract S createInstance()
      Plugins must implement this and return a new instance of the PluginFeature type.
      Returns:
      a new PluginFeature instance.
    • getFeature

      public final <T extends PluginFeature> Optional<T> getFeature(Class<T> featureType)
      Description copied from interface: Plugin
      Get an instance of the given feature type.
      Specified by:
      getFeature in interface Plugin
      Type Parameters:
      T - the type of the feature.
      Parameters:
      featureType - the feature type.
      Returns:
      the instance of the given feature or an empty Optional if the feature is not supported.