Class DefaultPluginService
- java.lang.Object
-
- org.scijava.AbstractContextual
-
- org.scijava.plugin.AbstractRichPlugin
-
- org.scijava.service.AbstractService
-
- org.scijava.plugin.DefaultPluginService
-
- All Implemented Interfaces:
Comparable<Prioritized>,Contextual,Disposable,Identifiable,Initializable,Locatable,Logged,HasPluginInfo,PluginService,RichPlugin,SciJavaPlugin,Prioritized,SciJavaService,Service,Versioned
public class DefaultPluginService extends AbstractService implements PluginService
Default service for keeping track of available plugins.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.)- Author:
- Curtis Rueden, Johannes Schindelin
- See Also:
SciJavaPlugin,Plugin
-
-
Constructor Summary
Constructors Constructor Description DefaultPluginService()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddPlugin(PluginInfo<?> plugin)Manually registers a plugin with the plugin service.<T extends PluginInfo<?>>
voidaddPlugins(Collection<T> plugins)Manually registers plugins with the plugin service.<PT extends SciJavaPlugin>
PTcreateInstance(PluginInfo<PT> info)Creates an instance of the given plugin.<PT extends SciJavaPlugin>
List<PT>createInstances(List<PluginInfo<PT>> infos)Creates an instance of each of the plugins on the given list.<PT extends SciJavaPlugin>
List<PT>createInstancesOfType(Class<PT> type)Creates one instance each of the available plugins of the given type.static <T extends PluginInfo<?>>
voidfindPluginsOfClass(String className, List<? extends PluginInfo<?>> srcList, List<T> destList)Transfers plugins of the given class from the source list to the destination list.PluginIndexgetIndex()Gets the index of available plugins.<P extends SciJavaPlugin>
PluginInfo<SciJavaPlugin>getPlugin(Class<P> pluginClass)Gets the first available plugin of the given class, or null if none.<PT extends SciJavaPlugin,P extends PT>
PluginInfo<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>
List<PluginInfo<SciJavaPlugin>>getPluginsOfClass(Class<P> pluginClass)Gets the list of plugins of the given class.<PT extends SciJavaPlugin,P extends PT>
List<PluginInfo<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>
List<PluginInfo<SciJavaPlugin>>getPluginsOfClass(String className, Class<PT> type)Gets the list of plugins with the given class name.<PT extends SciJavaPlugin>
List<PluginInfo<PT>>getPluginsOfType(Class<PT> type)Gets the list of plugins of the given type (e.g.,Service).static <PT extends SciJavaPlugin,P extends PT>
Class<PT>getPluginType(Class<P> pluginClass)Gets the plugin type of the given plugin class, as declared by its@Pluginannotation (i.e.,Plugin.type()).voidinitialize()Performs any needed initialization when the service is first loaded.voidreloadPlugins()Rediscovers all plugins available on the classpath.voidremovePlugin(PluginInfo<?> plugin)Manually unregisters a plugin with the plugin service.<T extends PluginInfo<?>>
voidremovePlugins(Collection<T> plugins)Manually unregisters plugins with the plugin service.-
Methods inherited from class org.scijava.service.AbstractService
getContext, setContext, toString
-
Methods inherited from class org.scijava.plugin.AbstractRichPlugin
getInfo, getPriority, setInfo, setPriority
-
Methods inherited from class org.scijava.AbstractContextual
context
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.scijava.Contextual
context, getContext, setContext
-
Methods inherited from interface org.scijava.Disposable
dispose
-
Methods inherited from interface org.scijava.plugin.HasPluginInfo
getInfo, setInfo
-
Methods inherited from interface org.scijava.Locatable
getLocation
-
Methods inherited from interface org.scijava.plugin.PluginService
sort
-
Methods inherited from interface org.scijava.Prioritized
compareTo, getPriority, setPriority
-
Methods inherited from interface org.scijava.plugin.RichPlugin
getIdentifier, log
-
Methods inherited from interface org.scijava.service.Service
registerEventHandlers
-
Methods inherited from interface org.scijava.Versioned
getVersion
-
-
-
-
Method Detail
-
getIndex
public PluginIndex getIndex()
Description copied from interface:PluginServiceGets the index of available plugins.- Specified by:
getIndexin interfacePluginService
-
reloadPlugins
public void reloadPlugins()
Description copied from interface:PluginServiceRediscovers all plugins available on the classpath. Note that this will clear any individual plugins added programmatically.- Specified by:
reloadPluginsin interfacePluginService
-
addPlugin
public void addPlugin(PluginInfo<?> plugin)
Description copied from interface:PluginServiceManually registers a plugin with the plugin service.- Specified by:
addPluginin interfacePluginService
-
addPlugins
public <T extends PluginInfo<?>> void addPlugins(Collection<T> plugins)
Description copied from interface:PluginServiceManually registers plugins with the plugin service.- Specified by:
addPluginsin interfacePluginService
-
removePlugin
public void removePlugin(PluginInfo<?> plugin)
Description copied from interface:PluginServiceManually unregisters a plugin with the plugin service.- Specified by:
removePluginin interfacePluginService
-
removePlugins
public <T extends PluginInfo<?>> void removePlugins(Collection<T> plugins)
Description copied from interface:PluginServiceManually unregisters plugins with the plugin service.- Specified by:
removePluginsin interfacePluginService
-
getPlugins
public List<PluginInfo<?>> getPlugins()
Description copied from interface:PluginServiceGets the list of known plugins.- Specified by:
getPluginsin interfacePluginService
-
getPlugin
public <P extends SciJavaPlugin> PluginInfo<SciJavaPlugin> getPlugin(Class<P> pluginClass)
Description copied from interface:PluginServiceGets the first available plugin of the given class, or null if none.- Specified by:
getPluginin interfacePluginService- Type Parameters:
P- The class of the plugin to look up.
-
getPlugin
public <PT extends SciJavaPlugin,P extends PT> PluginInfo<PT> getPlugin(Class<P> pluginClass, Class<PT> type)
Description copied from interface:PluginServiceGets the first available plugin of the given class, or null if none.- Specified by:
getPluginin interfacePluginService- Type Parameters:
PT- The type of the plugin to look up; e.g.,Service.class.P- The class of the plugin to look up.
-
getPlugin
public PluginInfo<SciJavaPlugin> getPlugin(String className)
Description copied from interface:PluginServiceGets the first available plugin of the given class name, or null if none.- Specified by:
getPluginin interfacePluginService
-
getPluginsOfType
public <PT extends SciJavaPlugin> List<PluginInfo<PT>> getPluginsOfType(Class<PT> type)
Description copied from interface:PluginServiceGets the list of plugins of the given type (e.g.,Service).- Specified by:
getPluginsOfTypein interfacePluginService- Type Parameters:
PT- The type of plugins to look up; e.g.,Service.class.
-
getPluginsOfClass
public <P extends SciJavaPlugin> List<PluginInfo<SciJavaPlugin>> getPluginsOfClass(Class<P> pluginClass)
Description copied from interface:PluginServiceGets the list of plugins of the given class.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
PluginInfos with matching class names to load their pluginClasses 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.- Specified by:
getPluginsOfClassin interfacePluginService- Type Parameters:
P- The class of plugins to look up.- Parameters:
pluginClass- The class for which to obtain the list of matching plugins.
-
getPluginsOfClass
public <PT extends SciJavaPlugin,P extends PT> List<PluginInfo<PT>> getPluginsOfClass(Class<P> pluginClass, Class<PT> type)
Description copied from interface:PluginServiceGets the list of plugins of the given class.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
PluginInfos with matching class names and types to load their pluginClasses 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.- Specified by:
getPluginsOfClassin interfacePluginService- Type Parameters:
PT- The type of plugins to look up; e.g.,Service.class.P- The class of plugins to look up.- Parameters:
pluginClass- The class for which to obtain the list of matching plugins.type- The type of plugins to which the search should be limited.
-
getPluginsOfClass
public List<PluginInfo<SciJavaPlugin>> getPluginsOfClass(String className)
Description copied from interface:PluginServiceGets the list of plugins with the given class name.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.- Specified by:
getPluginsOfClassin interfacePluginService- Parameters:
className- The class name for which to obtain the list of matching plugins.
-
getPluginsOfClass
public <PT extends SciJavaPlugin> List<PluginInfo<SciJavaPlugin>> getPluginsOfClass(String className, Class<PT> type)
Description copied from interface:PluginServiceGets the list of plugins with the given class name.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.- Specified by:
getPluginsOfClassin interfacePluginService- Type Parameters:
PT- The type of plugins to look up; e.g.,Service.class.- Parameters:
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.
-
createInstancesOfType
public <PT extends SciJavaPlugin> List<PT> createInstancesOfType(Class<PT> type)
Description copied from interface:PluginServiceCreates one instance each of the available plugins of the given type.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.
- Specified by:
createInstancesOfTypein interfacePluginService- Type Parameters:
PT- The type of plugins to instantiate; e.g.,Service.class.
-
createInstances
public <PT extends SciJavaPlugin> List<PT> createInstances(List<PluginInfo<PT>> infos)
Description copied from interface:PluginServiceCreates an instance of each of the plugins on the given list.If the plugin implements the
Contextualinterface, the appropriate context is injected. Similarly, if the plugin implements thePrioritizedinterface, 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.
- Specified by:
createInstancesin interfacePluginService- Type Parameters:
PT- The type of plugins to instantiate; e.g.,Service.class.
-
createInstance
public <PT extends SciJavaPlugin> PT createInstance(PluginInfo<PT> info)
Description copied from interface:PluginServiceCreates an instance of the given plugin.If the plugin implements the
Contextualinterface, the appropriate context is injected. Similarly, if the plugin implements thePrioritizedinterface, 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.
- Specified by:
createInstancein interfacePluginService- Type Parameters:
PT- The type of plugin to instantiate; e.g.,Service.class.
-
initialize
public void initialize()
Description copied from interface:ServicePerforms any needed initialization when the service is first loaded.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.- Specified by:
initializein interfaceInitializable- Specified by:
initializein interfaceService
-
findPluginsOfClass
public static <T extends PluginInfo<?>> void findPluginsOfClass(String className, List<? extends PluginInfo<?>> srcList, List<T> destList)
Transfers plugins of the given class from the source list to the destination list. Note that because this method compares class name strings, it does not need to actually load the class in question.- Parameters:
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.
-
getPluginType
public static <PT extends SciJavaPlugin,P extends PT> Class<PT> getPluginType(Class<P> pluginClass)
Gets the plugin type of the given plugin class, as declared by its@Pluginannotation (i.e.,Plugin.type()).- Parameters:
pluginClass- The plugin class whose plugin type is needed.- Returns:
- The plugin type, or null if no
Pluginannotation exists for the given class.
-
-