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
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateObject
(String name) Create an object from the specified type name.generateUniqueName
(String prefix) Generate a unique plugin type name which has not yet been registered.boolean
Check this plugin list for the presence of the specified type nameboolean
registerPlugin
(String name, Class<? extends T> pluginClass) Define a new plugin type from an existing class.boolean
registerPlugin
(String name, String sourceCode) Define a new plugin type from java source code.
-
Constructor Details
-
Plugins
Create an empty plugin list. You must specifyT.class
as an argument.- Parameters:
baseClass
-
-
-
Method Details
-
createObject
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
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
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
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:
true
if the code compiled and registered successfully,false
otherwise
-
registerPlugin
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:
true
if the plugin registered successfully,false
otherwise
-