Package org.sunflow.system
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 java.lang.ObjectThis 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.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TcreateObject(java.lang.String name)Create an object from the specified type name.java.lang.StringgenerateUniqueName(java.lang.String prefix)Generate a unique plugin type name which has not yet been registered.booleanhasType(java.lang.String name)Check this plugin list for the presence of the specified type namebooleanregisterPlugin(java.lang.String name, java.lang.Class<? extends T> pluginClass)Define a new plugin type from an existing class.booleanregisterPlugin(java.lang.String name, java.lang.String sourceCode)Define a new plugin type from java source code.
-
-
-
Constructor Detail
-
Plugins
public Plugins(java.lang.Class<T> baseClass)
Create an empty plugin list. You must specifyT.classas 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,nullis returned.- Parameters:
name- plugin type name- Returns:
- an instance of the specified plugin type, or
nullif 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:
trueif this name has been registered,falseotherwise
-
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 namesourceCode- Java source code definition for the plugin- Returns:
trueif the code compiled and registered successfully,falseotherwise
-
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 namepluginClass- class object for the plugin class- Returns:
trueif the plugin registered successfully,falseotherwise
-
-