public final class PluginManagerImpl extends java.lang.Object implements PluginManager
PluginManager.PluginManagerListener
CLASS_EXTENSION, FILE_PROTOCOL, JAR_EXTENSION, MCR_EXTENSION
Modifier and Type | Method and Description |
---|---|
void |
addListener(PluginManager.PluginManagerListener listener)
Adds a listener to the plugin manager.
|
java.util.Set<Pair<java.lang.Integer,PluginParameterBinding>> |
find(java.lang.Class<? extends java.lang.annotation.Annotation> annotation,
java.lang.Class<?> resultType,
java.lang.Class<? extends PluginContext> contextType,
boolean totalMatch,
boolean orderedParameters,
boolean mustBeUserVisible,
java.lang.Class<?>... parameters)
This method retuns a collection of
Pair s of
Integer and PluginParameterBinding objects,
such that: |
java.util.Collection<PluginDescriptor> |
find(java.lang.String pluginName) |
protected void |
fireError(java.net.URL url,
java.lang.Throwable t,
java.lang.String className) |
protected void |
firePluginAdded(PluginDescriptor plugin,
java.util.Collection<java.lang.Class<?>> types) |
java.util.SortedSet<PluginDescriptor> |
getAllPlugins()
Returns all plugin descriptors
|
java.util.SortedSet<PluginDescriptor> |
getAllPlugins(boolean mustBeVisible)
Returns all plugin descriptors known to the plugin manager.
|
static PluginManager |
getInstance() |
java.util.Set<java.lang.Class<?>> |
getKnownClassesAnnotatedWith(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Returns all known classes annotated with a certain annotationType.
|
java.util.Set<java.lang.Class<?>> |
getKnownObjectTypes()
Returns the set of types that is known to the plugin manager.
|
PluginDescriptor |
getPlugin(PluginDescriptorID id)
Returns a PluginDescriptor with the given id.
|
PluginDescriptor |
getPlugin(java.lang.String id)
Returns a PluginDescriptor of which the toString() of its id equals the
given id.
|
java.util.Set<PluginParameterBinding> |
getPluginsAcceptingAtLeast(java.lang.Class<? extends PluginContext> contextType,
boolean mustBeUserVisible,
java.lang.Class<?>... parameters)
Returns PluginParameterBindings, which can be invoked in the given
context on the given parameter types.
|
java.util.Set<PluginParameterBinding> |
getPluginsAcceptingInAnyOrder(java.lang.Class<? extends PluginContext> contextType,
boolean mustBeUserVisible,
java.lang.Class<?>... parameters)
Returns executable PluginParameterBindings, which can be invoked in the
given context on the given parameter types.
|
java.util.Set<PluginParameterBinding> |
getPluginsAcceptingOrdered(java.lang.Class<? extends PluginContext> contextType,
boolean mustBeUserVisible,
java.lang.Class<?>... parameters)
Returns executable PluginParameterBindings, which can be invoked in the
given context on the given parameter types.
|
java.util.Set<Pair<java.lang.Integer,PluginDescriptor>> |
getPluginsResultingIn(java.lang.Class<?> resultType,
java.lang.Class<? extends PluginContext> contextType,
boolean mustBeUserVisible)
Find the plugins resulting in the given type.
|
static void |
initialize(java.lang.Class<? extends PluginContext> pluginContextType) |
boolean |
isParameterAssignable(java.lang.Class<?> instanceType,
java.lang.Class<?> requestedType)
Returns true if the instance type can be cast to the requested type, or
if the requested type is an array and the instance type can be cast to
the component type of the requested type.
|
void |
register(java.net.URL url,
PackageDescriptor pack)
registers a URL to this plugin manager.
|
void |
register(java.net.URL url,
PackageDescriptor pack,
java.lang.ClassLoader loader)
registers a URL to this plugin manager.
|
void |
removeListener(PluginManager.PluginManagerListener listener)
Removes the listener from the plugin manager.
|
public void addListener(PluginManager.PluginManagerListener listener)
PluginManager
addListener
in interface PluginManager
listener
- the listener to add.public java.util.Set<java.lang.Class<?>> getKnownClassesAnnotatedWith(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
PluginManager
getKnownClassesAnnotatedWith
in interface PluginManager
annotationType
- the type of annotation to be foundpublic void removeListener(PluginManager.PluginManagerListener listener)
PluginManager
removeListener
in interface PluginManager
listener
- the listener to remove.protected void fireError(java.net.URL url, java.lang.Throwable t, java.lang.String className)
protected void firePluginAdded(PluginDescriptor plugin, java.util.Collection<java.lang.Class<?>> types)
public static void initialize(java.lang.Class<? extends PluginContext> pluginContextType)
public static PluginManager getInstance()
public void register(java.net.URL url, PackageDescriptor pack)
PluginManager
FILE_PROTOCOl
protocol and denotes a directory, then this
folder is recursively scanned for files with the
CLASS_EXTENSION
extension.
Otherwise, the URL is assumed to point to a jar file, of which the
classes are scanned.
Each class file is scanned for classes and/or methods annotated with the
Plugin
annotation. If a class is annotated with this
annotation, then its methods are scanned for the
PluginVariant
annotation.
For each plugin found, a PluginDescriptor
object is
instantiated. These plugin descriptors can later be used to invoke
plugins.register
in interface PluginManager
url
- The URL to registerpack
- The package that corresponds to the URLpublic void register(java.net.URL url, PackageDescriptor pack, java.lang.ClassLoader loader)
PluginManager
FILE_PROTOCOl
protocol and denotes a directory, then this
folder is recursively scanned for files with the
CLASS_EXTENSION
extension.
Otherwise, the URL is assumed to point to a jar file, of which the
classes are scanned.
Each class file is scanned for classes and/or methods annotated with the
Plugin
annotation. If a class is annotated with this
annotation, then its methods are scanned for the
PluginVariant
annotation.
For each plugin found, a PluginDescriptor
object is
instantiated. These plugin descriptors can later be used to invoke
plugins.register
in interface PluginManager
url
- The URL to registerpack
- The package that corresponds to the URLloader
- The class loader used to load the jar files.public java.util.Set<Pair<java.lang.Integer,PluginParameterBinding>> find(java.lang.Class<? extends java.lang.annotation.Annotation> annotation, java.lang.Class<?> resultType, java.lang.Class<? extends PluginContext> contextType, boolean totalMatch, boolean orderedParameters, boolean mustBeUserVisible, java.lang.Class<?>... parameters)
PluginManager
Pair
s of
Integer
and PluginParameterBinding
objects,
such that:
The method belonging to the plugin in the pluginParameterBinding carries
the given annotation. If no specific annotation is required, the method
should be called with Plugin.class
. Note that the annotation
required has to be on the same level as the Plugin
annotation, i.e. either on a method or a class
When invoked, the PluginParameterBinding returns an array of objects, of
which the object at the index given by the integer in the pair is of the
required result type, i.e.
resultType.isAssignableFrom(p.getPlugin().getReturnTypes()[i])
If no specific return type is required, use Object.class
for
this parameter.
The PluginParameterBinding can be executed in a
PluginContext
of the given type.
If totalMatch
is true, then the PluginParameterBinding binds
all parameters of the plugin with all arguments. Otherwise, the
PluginParameterBinding only requires a subset of the given arguments and
is therefore not directly executable on the given set of arguments.
If orderedParameters
is true, then the
PluginParameterBinding binds the given arguments in the given order, i.e.
no arguments are reordered.
If mustBeUserVisible
is true, then the plugin must have the
isUserVisible
flag set to true.
The PluginParameterBinding can be executed on arguments of the given
types. The list of arguments can be empty, in which case no arguments are
required to invoke the PluginParameterBinding. Note that only types of
arguments are required, not the values. For checking whether arguments
can be assigned to parameters of the Plugin, the
isParameterAssignable
method is used. Any
ProMFuture
s should be unwrapped.
find
in interface PluginManager
annotation
- The annotation that should be present on the plugin (use
Plugin.class
if none is required).resultType
- The required result type (use Object.class
if no
specific type is required).contextType
- The context type in which this plugin should be executable.
Note that this type should be the contextType of the context
from which the find is called, or a supertype thereof.totalMatch
- Whether or not all arguments should be used to execute this
plugin.orderedParameters
- Whether or not the arguments are given in the right order.mustBeUserVisible
- Whether or not all returned plugins should be user visible.parameters
- The types of the arguments provided to the plugin. Can be
empty.public java.util.Collection<PluginDescriptor> find(java.lang.String pluginName)
public PluginDescriptor getPlugin(PluginDescriptorID id)
PluginManager
getPlugin
in interface PluginManager
id
- the id of the plugin to getpublic PluginDescriptor getPlugin(java.lang.String id)
PluginManager
getPlugin
in interface PluginManager
id
- the String representation of the id of the plugin to getpublic java.util.Set<PluginParameterBinding> getPluginsAcceptingAtLeast(java.lang.Class<? extends PluginContext> contextType, boolean mustBeUserVisible, java.lang.Class<?>... parameters)
PluginManager
getPluginsAcceptingAtLeast
in interface PluginManager
contextType
- The type of the context in which the binding is to be invoked.mustBeUserVisible
- Whether or not the plugin should be user visible.parameters
- The types of the arguments passed to the plugins. They are
accepted by the returned plugins, but not necessarily in this
order.public java.util.Set<PluginParameterBinding> getPluginsAcceptingInAnyOrder(java.lang.Class<? extends PluginContext> contextType, boolean mustBeUserVisible, java.lang.Class<?>... parameters)
PluginManager
getPluginsAcceptingInAnyOrder
in interface PluginManager
contextType
- The type of the context in which the binding is to be invoked.mustBeUserVisible
- Whether or not the plugin should be user visible.parameters
- The types of the arguments passed to the plugins. They are
accepted by the returned plugins, but not necessarily in this
order.public java.util.Set<PluginParameterBinding> getPluginsAcceptingOrdered(java.lang.Class<? extends PluginContext> contextType, boolean mustBeUserVisible, java.lang.Class<?>... parameters)
PluginManager
getPluginsAcceptingOrdered
in interface PluginManager
contextType
- The type of the context in which the binding is to be invoked.mustBeUserVisible
- Whether or not the plugin should be user visible.parameters
- The types of the arguments passed to the plugins. They are
accepted by the plugin in the order in which they are
provided.public java.util.Set<Pair<java.lang.Integer,PluginDescriptor>> getPluginsResultingIn(java.lang.Class<?> resultType, java.lang.Class<? extends PluginContext> contextType, boolean mustBeUserVisible)
PluginManager
getPluginsResultingIn
in interface PluginManager
resultType
- Can be null. if null, then any type is considered.mustBeUserVisible
- Whether or not all returned plugins should be user visible.public java.util.SortedSet<PluginDescriptor> getAllPlugins()
PluginManager
getAllPlugins
in interface PluginManager
public java.util.SortedSet<PluginDescriptor> getAllPlugins(boolean mustBeVisible)
PluginManager
getAllPlugins
in interface PluginManager
mustBeVisible
- wether or not the returned plugins should be user visible.public boolean isParameterAssignable(java.lang.Class<?> instanceType, java.lang.Class<?> requestedType)
PluginManager
isParameterAssignable
in interface PluginManager
instanceType
- the type that has to be cast to the requested type.requestedType
- the requested typepublic java.util.Set<java.lang.Class<?>> getKnownObjectTypes()
PluginManager
getKnownObjectTypes
in interface PluginManager