Class PluginLoader


  • class PluginLoader
    extends java.lang.Object
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) <PreferredT,​AlternateType>
      java.lang.Object
      loadPlugin​(java.lang.Class<PreferredT> preferredPluginType, java.lang.Class<AlternateType> alternatePluginType)
      Scans the classpath for given preferredPluginType.
      (package private) <T> T loadPlugin​(java.lang.Class<T> pluginType)
      Scans the classpath for given pluginType.
      (package private) <T> java.util.List<T> loadPlugins​(java.lang.Class<T> pluginType)
      Scans the classpath for given pluginType and returns a list of its instances.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PluginLoader

        PluginLoader​(PluginSwitch pluginSwitch,
                     java.lang.String... alias)
        Adds an alias for a class name to this plugin loader. Instead of the fully qualified type name, the alias can be used as a convenience name for a known plugin. This avoids exposing API that is explicitly marked as internal through the package name. Without such aliases, we would need to make internal packages part of the API, not by code but by configuration file.
    • Method Detail

      • loadPlugin

        <T> T loadPlugin​(java.lang.Class<T> pluginType)
        Scans the classpath for given pluginType. If not found, default class is used.
      • loadPlugin

        <PreferredT,​AlternateType> java.lang.Object loadPlugin​(java.lang.Class<PreferredT> preferredPluginType,
                                                                     java.lang.Class<AlternateType> alternatePluginType)
        Scans the classpath for given preferredPluginType. If not found scan for alternatePluginType. If neither a preferred or alternate plugin is found, default to default class of preferredPluginType.
        Returns:
        An object of either preferredPluginType or alternatePluginType
      • loadPlugins

        <T> java.util.List<T> loadPlugins​(java.lang.Class<T> pluginType)
        Scans the classpath for given pluginType and returns a list of its instances.
        Returns:
        An list of pluginType or an empty list if none was found.