public class DefaultPluginService extends AbstractService implements PluginService
Available plugins are discovered using indexes generated by using scijava-common as annotation processor. Loading of the actual plugin classes can be deferred until a particular plugin is actually needed.
Plugins are added or removed via the plugin service are reported via the
event service. (No events are published for plugins directly added to or
removed from the PluginIndex
.)
SciJavaPlugin
,
Plugin
Constructor and Description |
---|
DefaultPluginService() |
Modifier and Type | Method and Description |
---|---|
void |
addPlugin(PluginInfo<?> plugin)
Manually registers a plugin with the plugin service.
|
<T extends PluginInfo<?>> |
addPlugins(Collection<T> plugins)
Manually registers plugins with the plugin service.
|
<PT extends SciJavaPlugin> |
createInstance(PluginInfo<PT> info)
Creates an instance of the given plugin.
|
<PT extends SciJavaPlugin> |
createInstances(List<PluginInfo<PT>> infos)
Creates an instance of each of the plugins on the given list.
|
<PT extends SciJavaPlugin> |
createInstancesOfType(Class<PT> type)
Creates one instance each of the available plugins of the given type.
|
static <T extends PluginInfo<?>> |
findPluginsOfClass(String className,
List<? extends PluginInfo<?>> srcList,
List<T> destList)
Transfers plugins of the given class from the source list to the
destination list.
|
PluginIndex |
getIndex()
Gets the index of available plugins.
|
<P extends SciJavaPlugin> |
getPlugin(Class<P> pluginClass)
Gets the first available plugin of the given class, or null if none.
|
<PT extends SciJavaPlugin,P extends PT> |
getPlugin(Class<P> pluginClass,
Class<PT> type)
Gets the first available plugin of the given class, or null if none.
|
PluginInfo<SciJavaPlugin> |
getPlugin(String className)
Gets the first available plugin of the given class name, or null if none.
|
List<PluginInfo<?>> |
getPlugins()
Gets the list of known plugins.
|
<P extends SciJavaPlugin> |
getPluginsOfClass(Class<P> pluginClass)
Gets the list of plugins of the given class.
|
<PT extends SciJavaPlugin,P extends PT> |
getPluginsOfClass(Class<P> pluginClass,
Class<PT> type)
Gets the list of plugins of the given class.
|
List<PluginInfo<SciJavaPlugin>> |
getPluginsOfClass(String className)
Gets the list of plugins with the given class name.
|
<PT extends SciJavaPlugin> |
getPluginsOfClass(String className,
Class<PT> type)
Gets the list of plugins with the given class name.
|
<PT extends SciJavaPlugin> |
getPluginsOfType(Class<PT> type)
Gets the list of plugins of the given type (e.g.,
Service ). |
static <PT extends SciJavaPlugin,P extends PT> |
getPluginType(Class<P> pluginClass)
Gets the plugin type of the given plugin class, as declared by its
@Plugin annotation (i.e., Plugin.type() ). |
void |
initialize()
Performs any needed initialization when the service is first loaded.
|
void |
reloadPlugins()
Rediscovers all plugins available on the classpath.
|
void |
removePlugin(PluginInfo<?> plugin)
Manually unregisters a plugin with the plugin service.
|
<T extends PluginInfo<?>> |
removePlugins(Collection<T> plugins)
Manually unregisters plugins with the plugin service.
|
getContext, setContext, toString
getInfo, getPriority, setInfo, setPriority
context
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
sort
registerEventHandlers
getIdentifier, log
context, getContext, setContext
compareTo, getPriority, setPriority
getInfo, setInfo
getLocation
getVersion
dispose
public PluginIndex getIndex()
PluginService
getIndex
in interface PluginService
public void reloadPlugins()
PluginService
reloadPlugins
in interface PluginService
public void addPlugin(PluginInfo<?> plugin)
PluginService
addPlugin
in interface PluginService
public <T extends PluginInfo<?>> void addPlugins(Collection<T> plugins)
PluginService
addPlugins
in interface PluginService
public void removePlugin(PluginInfo<?> plugin)
PluginService
removePlugin
in interface PluginService
public <T extends PluginInfo<?>> void removePlugins(Collection<T> plugins)
PluginService
removePlugins
in interface PluginService
public List<PluginInfo<?>> getPlugins()
PluginService
getPlugins
in interface PluginService
public <P extends SciJavaPlugin> PluginInfo<SciJavaPlugin> getPlugin(Class<P> pluginClass)
PluginService
getPlugin
in interface PluginService
P
- The class of the plugin to look up.public <PT extends SciJavaPlugin,P extends PT> PluginInfo<PT> getPlugin(Class<P> pluginClass, Class<PT> type)
PluginService
getPlugin
in interface PluginService
PT
- The type of the plugin to look up; e.g.,
Service.class
.P
- The class of the plugin to look up.public PluginInfo<SciJavaPlugin> getPlugin(String className)
PluginService
getPlugin
in interface PluginService
public <PT extends SciJavaPlugin> List<PluginInfo<PT>> getPluginsOfType(Class<PT> type)
PluginService
Service
).getPluginsOfType
in interface PluginService
PT
- The type of plugins to look up; e.g.,
Service.class
.public <P extends SciJavaPlugin> List<PluginInfo<SciJavaPlugin>> getPluginsOfClass(Class<P> pluginClass)
PluginService
Most classes will have only a single match, but some special classes (such
as ImageJ's LegacyCommand
) may match many entries.
Note that this method will result in PluginInfo
s with matching
class names to load their plugin Class
es so that they can
be compared with the given one.
NB: Classes are matched by strict equality, not assignability; subtypes of
the specified class will not match. For this behavior, use
PluginService.getPluginsOfType(Class)
on a common parent interface.
getPluginsOfClass
in interface PluginService
P
- The class of plugins to look up.pluginClass
- The class for which to obtain the list of matching
plugins.public <PT extends SciJavaPlugin,P extends PT> List<PluginInfo<PT>> getPluginsOfClass(Class<P> pluginClass, Class<PT> type)
PluginService
Most classes will have only a single match, but some special classes (such
as ImageJ's LegacyCommand
) may match many entries.
Note that this method will result in PluginInfo
s with matching
class names and types to load their plugin Class
es so that
they can be compared with the given one.
NB: Classes are matched by strict equality, not assignability; subtypes of
the specified class will not match. For this behavior, use
PluginService.getPluginsOfType(Class)
on a common parent interface.
getPluginsOfClass
in interface PluginService
PT
- The type of plugins to look up; e.g.,
Service.class
.P
- The class of plugins to look up.pluginClass
- The class for which to obtain the list of matching
plugins.type
- The type of plugins to which the search should be
limited.public List<PluginInfo<SciJavaPlugin>> getPluginsOfClass(String className)
PluginService
Most classes will have only a single match, but some special classes (such
as ImageJ's LegacyCommand
) may match many entries.
NB: Classes are matched by strict equality, not assignability; subtypes of
the specified class will not match. For this behavior, use
PluginService.getPluginsOfType(Class)
on a common parent interface.
getPluginsOfClass
in interface PluginService
className
- The class name for which to obtain the list of matching
plugins.public <PT extends SciJavaPlugin> List<PluginInfo<SciJavaPlugin>> getPluginsOfClass(String className, Class<PT> type)
PluginService
Most classes will have only a single match, but some special classes (such
as ImageJ's LegacyCommand
) may match many entries.
NB: Classes are matched by strict equality, not assignability; subtypes of
the specified class will not match. For this behavior, use
PluginService.getPluginsOfType(Class)
on a common parent interface.
getPluginsOfClass
in interface PluginService
PT
- The type of plugins to look up; e.g.,
Service.class
.className
- The class name for which to obtain the list of matching
plugins.type
- The type of plugins to which the search should be
limited.public <PT extends SciJavaPlugin> List<PT> createInstancesOfType(Class<PT> type)
PluginService
Note that in the case of commands, this method does not do any preprocessing on the command instances, so parameters will not be auto-populated, initializers will not be executed, etc.
createInstancesOfType
in interface PluginService
PT
- The type of plugins to instantiate; e.g.,
Service.class
.public <PT extends SciJavaPlugin> List<PT> createInstances(List<PluginInfo<PT>> infos)
PluginService
If the plugin implements the Contextual
interface, the
appropriate context is injected. Similarly, if the plugin implements the
Prioritized
interface, the appropriate priority is
injected.
Note that in the case of commands, this method does not do any preprocessing on the command instances, so parameters will not be auto-populated, initializers will not be executed, etc.
createInstances
in interface PluginService
PT
- The type of plugins to instantiate; e.g.,
Service.class
.public <PT extends SciJavaPlugin> PT createInstance(PluginInfo<PT> info)
PluginService
If the plugin implements the Contextual
interface, the
appropriate context is injected. Similarly, if the plugin implements the
Prioritized
interface, the appropriate priority is
injected.
Note that in the case of commands, this method does not do any preprocessing on the command instances, so parameters will not be auto-populated, initializers will not be executed, etc.
createInstance
in interface PluginService
PT
- The type of plugin to instantiate; e.g.,
Service.class
.public void initialize()
Service
NB: This method is not intended to be called directly. It is called by
the service framework itself (specifically by the ServiceHelper
)
when initializing the service. It should not be called a second time.
initialize
in interface Initializable
initialize
in interface Service
public static <T extends PluginInfo<?>> void findPluginsOfClass(String className, List<? extends PluginInfo<?>> srcList, List<T> destList)
className
- The class name of the desired plugins.srcList
- The list to scan for matching plugins.destList
- The list to which matching plugins are added.public static <PT extends SciJavaPlugin,P extends PT> Class<PT> getPluginType(Class<P> pluginClass)
@Plugin
annotation (i.e., Plugin.type()
).pluginClass
- The plugin class whose plugin type is needed.Plugin
annotation exists for
the given class.Copyright © 2015–2022 SciJava. All rights reserved.