Class PluginManager


  • public final class PluginManager
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void clear()
      Removes all registered classes.
      static void initialize()
      Registers all classes in the current jar file.
      static java.lang.Object instantiateClass​(java.lang.String className)
      Instantiates a class from its name or XML name.
      static void loadPlugin​(java.lang.String pathToPlugin)
      Load a jar file and register all its classes.
      static void registerClass​(java.lang.Class<?> c)
      Registers a single class to the respective manager class.
      static void registerClass​(java.lang.String classname, java.lang.String xmlAlias, java.lang.Class<?> aClass)
      Registers a single class to the respective manager class.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • initialize

        public static void initialize()
                               throws java.lang.Exception
        Registers all classes in the current jar file. Requires that the program is running from a jar file.
        Throws:
        java.lang.Exception - Throws if there are duplicate XML names or if a class does not satisfy the requirements imposed by the manager class (for example, it is an export class without an "export" method).
      • instantiateClass

        public static java.lang.Object instantiateClass​(java.lang.String className)
                                                 throws java.lang.Exception
        Instantiates a class from its name or XML name. Only considers classes that have been registered before with one of the other methods.
        Parameters:
        className - The name or the XML name of the class to instantiate.
        Returns:
        A new instance of the requested class.
        Throws:
        java.lang.Exception - Throws if the class has not been registered.
      • registerClass

        public static void registerClass​(java.lang.Class<?> c)
                                  throws java.lang.Exception
        Registers a single class to the respective manager class. Ignores abstract classes. Determines the XML name from the XmlName annotation.
        Parameters:
        c - The class to register.
        Throws:
        java.lang.Exception - Throws if the class name or the XML name has already been registered or if the class does not satisfy the requirements imposed by the manager class (for example, it is an export class without an "export" method).
      • registerClass

        public static void registerClass​(java.lang.String classname,
                                         java.lang.String xmlAlias,
                                         java.lang.Class<?> aClass)
                                  throws java.lang.Exception
        Registers a single class to the respective manager class. Ignores abstract classes.
        Parameters:
        classname - The name of the class to register.
        xmlAlias - The XML name of the class to register.
        aClass - The class to register.
        Throws:
        java.lang.Exception - Throws if the class name or the XML name has already been registered or if the class does not satisfy the requirements imposed by the manager class (for example, it is an export class without an "export" method).
      • loadPlugin

        public static void loadPlugin​(java.lang.String pathToPlugin)
                               throws java.lang.Exception
        Load a jar file and register all its classes.
        Parameters:
        pathToPlugin - The path to the jar file.
        Throws:
        java.lang.Exception - Throws if the jar file cannot be loaded.
      • clear

        public static void clear()
        Removes all registered classes. After calling this method, the static state of this class will be nearly the same as when you started the program.

        However, jar files loaded with loadPlugin() will not be unloaded, although all their classes will become unknown to PluginManager. It will also not clear the state of ExportFilterManager etc., even though PluginManager changes their state when registering classes.

        When you call this method, you most likely also want to call the clear() methods of the resource managing classes like ExportFilterManager.