Class Plugins<T>

java.lang.Object
org.sunflow.system.Plugins<T>
Type Parameters:
T - Default constructible type or interface all plugins will derive from or implement

public final class Plugins<T> extends 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.
  • Constructor Details

    • Plugins

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

    • createObject

      public T createObject(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(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 String generateUniqueName(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(String name, 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(String name, 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