Class Plugins<T>

  • Type Parameters:
    T - Default constructible type or interface all plugins will derive from or implement

    public final class Plugins<T>
    extends java.lang.Object
    This class represents a list of plugins which implement a certain interface or extend a certain class. Many plugins may be registered and created at a later time by recalling their unique name only.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.Class<T> baseClass  
      private FastHashMap<java.lang.String,​java.lang.Class<? extends T>> pluginClasses  
    • Constructor Summary

      Constructors 
      Constructor Description
      Plugins​(java.lang.Class<T> baseClass)
      Create an empty plugin list.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      T createObject​(java.lang.String name)
      Create an object from the specified type name.
      java.lang.String generateUniqueName​(java.lang.String prefix)
      Generate a unique plugin type name which has not yet been registered.
      boolean hasType​(java.lang.String name)
      Check this plugin list for the presence of the specified type name
      boolean registerPlugin​(java.lang.String name, java.lang.Class<? extends T> pluginClass)
      Define a new plugin type from an existing class.
      boolean registerPlugin​(java.lang.String name, java.lang.String sourceCode)
      Define a new plugin type from java source code.
      • Methods inherited from class java.lang.Object

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

      • pluginClasses

        private final FastHashMap<java.lang.String,​java.lang.Class<? extends T>> pluginClasses
      • baseClass

        private final java.lang.Class<T> baseClass
    • Constructor Detail

      • Plugins

        public Plugins​(java.lang.Class<T> baseClass)
        Create an empty plugin list. You must specify T.class as an argument.
        Parameters:
        baseClass -
    • Method Detail

      • createObject

        public T createObject​(java.lang.String name)
        Create an object from the specified type name. If this type name is unknown or invalid, null is returned.
        Parameters:
        name - plugin type name
        Returns:
        an instance of the specified plugin type, or null if not found or invalid
      • hasType

        public boolean hasType​(java.lang.String name)
        Check this plugin list for the presence of the specified type name
        Parameters:
        name - plugin type name
        Returns:
        true if this name has been registered, false otherwise
      • generateUniqueName

        public java.lang.String generateUniqueName​(java.lang.String prefix)
        Generate a unique plugin type name which has not yet been registered. This is meant to be used when the actual type name is not crucial, but succesfully registration is.
        Parameters:
        prefix - a prefix to be used in generating the unique name
        Returns:
        a unique plugin type name not yet in use
      • registerPlugin

        public boolean registerPlugin​(java.lang.String name,
                                      java.lang.String sourceCode)
        Define a new plugin type from java source code. The code string contains import declarations and a class body only. The implemented type is implicitly the one of the plugin list being registered against.If the plugin type name was previously associated with a different class, it will be overriden. This allows the behavior core classes to be modified at runtime.
        Parameters:
        name - plugin type name
        sourceCode - Java source code definition for the plugin
        Returns:
        true if the code compiled and registered successfully, false otherwise
      • registerPlugin

        public boolean registerPlugin​(java.lang.String name,
                                      java.lang.Class<? extends T> pluginClass)
        Define a new plugin type from an existing class. This checks to make sure the provided class is default constructible (ie: has a constructor with no parameters). If the plugin type name was previously associated with a different class, it will be overriden. This allows the behavior core classes to be modified at runtime.
        Parameters:
        name - plugin type name
        pluginClass - class object for the plugin class
        Returns:
        true if the plugin registered successfully, false otherwise