public class PluginCollector<TType>
extends java.lang.Object
Since version 1.3 it is possible to specify a system property named "org.pf.plugin.path" to define the path on which the plugin collector must search for plug-ins.
Since version 1.4 it is also possible to load all plugin definitions from a single file that is looked-up via the standard classloader mechanism getResourceStream().
Since version 1.5 it is also possible to load plugin definitions
from classes that implement the PluginRegistration
interface. These
classes are found by the Java service loader mechanism on the whole classpath
(based on classloader hierarchy).
Modifier and Type | Field and Description |
---|---|
static boolean |
DEBUG |
protected static java.lang.String |
DEBUG_PREFIX |
Constructor and Description |
---|
PluginCollector()
Initialize the new instance with default values.
|
PluginCollector(java.lang.Class<TType> pluginType)
Initialize the new instance the type the plugins to collect must
be compliant with.
|
PluginCollector(ClassRegistry<TType> registry)
Initialize the new instance with a class registry.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addMappings(java.util.Map<java.lang.String,java.lang.Class<?>> classesToRegister) |
protected void |
addMappings(java.util.Properties properties) |
protected void |
debug(java.lang.String text) |
protected FileUtil |
fileUtil() |
ClassRegistry<TType> |
getClassRegistry()
Returns the class registry that contains all loaded plugins.
|
protected Classpath |
getPluginClasspath()
Returns the classpath that is used to lookup any plug-in information files.
|
ClassRegistry<TType> |
loadPlugins(java.lang.String filename)
Load the class definitions from all files with the given name that can
be found in the system classpath.
|
ClassRegistry<TType> |
loadPlugins(java.lang.String filename,
Classpath classpath)
Load the class definitions from all files with the given name that can
be found in the specified classpath.
|
ClassRegistry<TType> |
loadPlugins(java.lang.String filename,
java.lang.String classpath)
Load the class definitions from all files with the given name that can
be found in the specified classpath.
|
ClassRegistry<TType> |
loadPluginsViaClassLoader(java.lang.String filename)
Load the class definitions from the file with the given name.
|
ClassRegistry<TType> |
loadPluginsViaPluginRegistration()
Load the class definitions from all PluginRegistration implementing classes
that can be found via Java service loader mechanism using the classloader of
this class.
|
ClassRegistry<TType> |
loadPluginsViaPluginRegistration(java.lang.ClassLoader classLoader)
Load the class definitions from all PluginRegistration implementing classes
that can be found via Java service loader mechanism in the given classloader's
hierarchy.
|
protected PluginUtil |
pluginUtil() |
protected void |
readMapping(ClasspathElement element,
java.lang.String filename) |
protected void |
readMapping(java.io.InputStream stream,
java.lang.String filename)
Reads all plugin definitions from the given stream into the underlying registry.
|
protected void |
readPlugins(java.lang.String filename,
Classpath classpath)
Read all classes specified in the given file, if it exists in the specified
classpath element.
|
protected void |
readPlugins(java.lang.String filename,
java.lang.String strClasspath)
Read all classes specified in the given file, if it exists in the specified
classpath element.
|
protected void |
setClassRegistry(ClassRegistry<TType> newValue) |
protected static final java.lang.String DEBUG_PREFIX
public static boolean DEBUG
public PluginCollector()
public PluginCollector(java.lang.Class<TType> pluginType)
public PluginCollector(ClassRegistry<TType> registry)
public ClassRegistry<TType> getClassRegistry()
public ClassRegistry<TType> loadPluginsViaClassLoader(java.lang.String filename)
filename
- The name of the properties file that contains the class definitionspublic ClassRegistry<TType> loadPlugins(java.lang.String filename)
filename
- The name of the properties file that contains the class definitionspublic ClassRegistry<TType> loadPlugins(java.lang.String filename, java.lang.String classpath)
filename
- The name of the properties file that contains the class definitionsclasspath
- The classpath the specified filename to be looked up inpublic ClassRegistry<TType> loadPlugins(java.lang.String filename, Classpath classpath)
filename
- The name of the properties file that contains the class definitionsclasspath
- The classpath on which to lookup the the specified filenamepublic ClassRegistry<TType> loadPluginsViaPluginRegistration(java.lang.ClassLoader classLoader)
classLoader
- The class loader from which to start looking for services
that implement interface PluginRegistration
.public ClassRegistry<TType> loadPluginsViaPluginRegistration()
protected void readPlugins(java.lang.String filename, java.lang.String strClasspath)
filename
- The name of the properties file that contains the class definitionsstrClasspath
- The classpath the specified filename to be looked up inprotected void 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 void readMapping(ClasspathElement element, java.lang.String filename)
protected void readMapping(java.io.InputStream stream, java.lang.String filename)
stream
- The stream from which to read the definitions.filename
- The filename that corresponds to the stream (just for debugging).protected void addMappings(java.util.Properties properties)
protected void addMappings(java.util.Map<java.lang.String,java.lang.Class<?>> classesToRegister)
protected Classpath getPluginClasspath()
protected void setClassRegistry(ClassRegistry<TType> newValue)
protected FileUtil fileUtil()
protected PluginUtil pluginUtil()
protected void debug(java.lang.String text)