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.booleanCheck this plugin list for the presence of the specified type namebooleanregisterPlugin(String name, Class<? extends T> pluginClass) Define a new plugin type from an existing class.booleanregisterPlugin(String name, String sourceCode) Define a new plugin type from java source code.
-
Constructor Details
-
Plugins
Create an empty plugin list. You must specifyT.classas an argument.- Parameters:
baseClass-
-
-
Method Details
-
createObject
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
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
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:
trueif the code compiled and registered successfully,falseotherwise
-
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:
trueif the plugin registered successfully,falseotherwise
-