public class PluginRegistry
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected static boolean |
DEBUG |
protected static java.lang.String |
DEBUG_PREFIX |
protected static java.lang.String |
OPTIONS_END |
protected static java.lang.String |
OPTIONS_START |
protected static java.lang.String |
PLUGIN_DEF_SEPARATOR |
protected static StringPattern |
PLUGIN_OPTIONS_PATTERN |
Constructor and Description |
---|
PluginRegistry()
Initialize the new instance with default values (i.e.
|
Modifier and Type | Method and Description |
---|---|
protected int |
addDefinitionsToRegistry(OrderedProperties<?> definitions) |
void |
clear()
Remove all registered plugins.
|
protected CollectionUtil |
coll() |
protected void |
debug(java.lang.String text) |
protected FileUtil |
fileUtil() |
protected java.lang.reflect.Method |
find_getPluginId_Method(java.lang.Object object) |
protected java.lang.String |
getIdOfPlugin(java.lang.Object plugin,
java.lang.String defaultId) |
java.lang.Object |
getPlugin(java.lang.String pluginId)
Returns the plug-in with the specified ID or null
if no such plug-in can be found in the registry.
|
<T> T |
getPlugin(java.lang.String pluginId,
java.lang.Class<T> pluginType)
Returns the plug-in with the specified ID and the given type or null
if no such plug-in can be found in the registry.
|
protected Classpath |
getPluginClasspath()
Returns the classpath that is used to lookup any plug-in information files.
|
java.lang.String[] |
getPluginIDsOfType(java.lang.Class<?> pluginType)
Returns the IDs of all plug-ins that are of the specified type.
|
<T> T[] |
getPluginsOfType(java.lang.Class<T> pluginType)
Returns all plug-ins that are of the specified type.
|
protected NamedValueList<org.pfsw.plugin.PluginHolder> |
getRegistry() |
<T> int |
loadPluginsByServiceLoader(java.lang.Class<T> pluginType,
java.lang.ClassLoader... classLoaders)
Utilizes the Java
ServiceLoader mechanism to load all plugins
implementing the given type into this registry. |
int |
loadPluginsFrom(java.lang.String filename)
Load all plug-ins that are defined in any library in the specified file.
|
protected boolean |
parseAndAddToRegistry(java.lang.String id,
java.lang.String pluginDefinition) |
protected PluginUtil |
plugUtil() |
protected int |
readPlugins(java.lang.String filename,
Classpath classpath)
Read all classes specified in the given file, if it exists in the specified
classpath element.
|
protected int |
readPluginsFrom(ClasspathElement element,
java.lang.String filename) |
protected <T> void |
registerPlugin(java.lang.Class<T> pluginType,
T plugin) |
protected boolean |
registerPlugin(org.pfsw.plugin.PluginHolder pluginHolder) |
protected void |
setRegistry(NamedValueList<org.pfsw.plugin.PluginHolder> newValue) |
protected StringUtil |
str() |
protected boolean |
validateClass(ClassInfo<?> classInfo) |
protected boolean |
validateClassFound(ClassInfo<?> classInfo) |
protected boolean |
validateInstanceCreation(ClassInfo<?> classInfo) |
protected static final boolean DEBUG
protected static final java.lang.String DEBUG_PREFIX
protected static final java.lang.String PLUGIN_DEF_SEPARATOR
protected static final java.lang.String OPTIONS_START
protected static final java.lang.String OPTIONS_END
protected static final StringPattern PLUGIN_OPTIONS_PATTERN
public PluginRegistry()
public int loadPluginsFrom(java.lang.String filename)
filename
- The name of the file where the plug-in definition is looked-up.public <T> int loadPluginsByServiceLoader(java.lang.Class<T> pluginType, java.lang.ClassLoader... classLoaders)
ServiceLoader
mechanism to load all plugins
implementing the given type into this registry.pluginType
- The type (i.e. interface) of the plug-in (must not be null).classLoaders
- An optional array of class loaders. The first non-null classloader
will be used for the lookup. If none is provided the thread context classloader and
the class loader of this class will be tried.public java.lang.Object getPlugin(java.lang.String pluginId)
pluginId
- The identifier of the plug-in (must not be null)public <T> T getPlugin(java.lang.String pluginId, java.lang.Class<T> pluginType)
pluginId
- The identifier of the plug-in (must not be null).pluginType
- The type of the plug-in (must not be null).public <T> T[] getPluginsOfType(java.lang.Class<T> pluginType)
pluginType
- The type the plug-ins to look for must comply with.public java.lang.String[] getPluginIDsOfType(java.lang.Class<?> pluginType)
pluginType
- The type the plug-ins to look for must comply with.public void clear()
protected boolean registerPlugin(org.pfsw.plugin.PluginHolder pluginHolder)
protected <T> void registerPlugin(java.lang.Class<T> pluginType, T plugin)
protected java.lang.String getIdOfPlugin(java.lang.Object plugin, java.lang.String defaultId)
protected int readPlugins(java.lang.String filename, Classpath classpath)
filename
- The name of the properties file that contains the class definitionsclasspath
- The classpath the specified filename to be looked up inprotected int readPluginsFrom(ClasspathElement element, java.lang.String filename)
protected int addDefinitionsToRegistry(OrderedProperties<?> definitions)
protected boolean parseAndAddToRegistry(java.lang.String id, java.lang.String pluginDefinition)
protected boolean validateClass(ClassInfo<?> classInfo)
protected boolean validateClassFound(ClassInfo<?> classInfo)
protected boolean validateInstanceCreation(ClassInfo<?> classInfo)
protected java.lang.reflect.Method find_getPluginId_Method(java.lang.Object object)
protected Classpath getPluginClasspath()
protected NamedValueList<org.pfsw.plugin.PluginHolder> getRegistry()
protected void setRegistry(NamedValueList<org.pfsw.plugin.PluginHolder> newValue)
protected FileUtil fileUtil()
protected StringUtil str()
protected CollectionUtil coll()
protected PluginUtil plugUtil()
protected void debug(java.lang.String text)