Package org.scijava.plugin
Class PluginInfo<PT extends SciJavaPlugin>
- java.lang.Object
-
- org.scijava.AbstractBasicDetails
-
- org.scijava.AbstractUIDetails
-
- org.scijava.plugin.PluginInfo<PT>
-
- Type Parameters:
PT- The type of plugin described by this metadata. SeeSciJavaPluginfor a list of common plugin types.
- All Implemented Interfaces:
Comparable<Prioritized>,BasicDetails,Identifiable,Instantiable<PT>,Locatable,Named,Prioritized,UIDetails,Versioned
- Direct Known Subclasses:
CommandInfo
public class PluginInfo<PT extends SciJavaPlugin> extends AbstractUIDetails implements Instantiable<PT>, Identifiable, Locatable, Versioned
A collection of metadata about a particular plugin.For performance reasons, the metadata is populated without actually loading the plugin class, by reading from an efficient binary cache (see
DefaultPluginServicefor details). As such, we can very quickly build a complex structure containing all available plugins without waiting for the Java class loader.- Author:
- Curtis Rueden
- See Also:
Plugin,PluginService
-
-
Field Summary
-
Fields inherited from interface org.scijava.UIDetails
APPLICATION_MENU_ROOT
-
-
Constructor Summary
Constructors Modifier Constructor Description PluginInfo(Class<? extends PT> pluginClass, Class<PT> pluginType)Creates a new plugin metadata object.PluginInfo(Class<? extends PT> pluginClass, Class<PT> pluginType, Plugin annotation)Creates a new plugin metadata object.protectedPluginInfo(String className, Class<? extends PT> pluginClass, Class<PT> pluginType, Plugin annotation, ClassLoader classLoader)PluginInfo(String className, Class<PT> pluginType)Creates a new plugin metadata object.PluginInfo(String className, Class<PT> pluginType, Plugin annotation)Creates a new plugin metadata object.PluginInfo(String className, Class<PT> pluginType, Plugin annotation, ClassLoader classLoader)Creates a new plugin metadata object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static PluginInfo<?>create(Class<? extends SciJavaPlugin> pluginClass)Creates aPluginInfofor the given plugin class.static <P extends PT,PT extends SciJavaPlugin>
PluginInfo<PT>create(Class<P> pluginClass, Class<PT> pluginType)Creates aPluginInfofor the given plugin class of the specified plugin type.PTcreateInstance()Creates an object.static <P extends PT,PT extends SciJavaPlugin>
PluginInfo<PT>get(Class<P> pluginClass, Class<PT> pluginType, PluginIndex pluginIndex)Finds aPluginInfoof the given plugin class and plugin type in the specifiedPluginIndex.static <P extends PT,PT extends SciJavaPlugin>
PluginInfo<PT>get(Class<P> pluginClass, Collection<? extends PluginInfo<PT>> plugins)Finds aPluginInfoof the given plugin class in the specified list of plugins.static <P extends SciJavaPlugin>
PluginInfo<?>get(Class<P> pluginClass, PluginIndex pluginIndex)Finds aPluginInfoof the given plugin class in the specifiedPluginIndex.PlugingetAnnotation()Gets the associated @Pluginannotation.StringgetClassName()Gets the fully qualified name of theClassof the objects that can be created.URLgetIconURL()Gets the URL corresponding to the icon resource path.StringgetIdentifier()Gets a string intended to function as an identifier for the object.StringgetLocation()Gets the URL string defining the object's location.static <P extends PT,PT extends SciJavaPlugin>
PluginInfo<PT>getOrCreate(Class<P> pluginClass, Class<PT> pluginType, PluginIndex pluginIndex)Obtains aPluginInfofor the given plugin class.static <P extends SciJavaPlugin>
PluginInfo<?>getOrCreate(Class<P> pluginClass, PluginIndex pluginIndex)Obtains aPluginInfofor the given plugin class.Class<? extends PT>getPluginClass()Obtains theClassof the item objects, if that class has already been loaded.Class<PT>getPluginType()Gets the type of plugin described by the metadata.StringgetVersion()Gets the version of the object.booleaninject(Object o)Injects the metadata into the given object.Class<? extends PT>loadClass()Loads the class corresponding to the objects that are created byInstantiable.createInstance().voidsetPluginClass(Class<? extends PT> pluginClass)Explicitly sets theClassof the item objects.voidsetPluginType(Class<PT> pluginType)Sets the type of plugin described by the metadata.StringtoString()-
Methods inherited from class org.scijava.AbstractUIDetails
getIconPath, getMenuPath, getMenuRoot, getPriority, getSelectionGroup, isEnabled, isSelectable, isSelected, isVisible, setEnabled, setIconPath, setMenuPath, setMenuRoot, setPriority, setSelectable, setSelected, setSelectionGroup, setVisible
-
Methods inherited from class org.scijava.AbstractBasicDetails
get, getDescription, getLabel, getName, is, set, setDescription, setLabel, setName
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.scijava.BasicDetails
get, getDescription, getLabel, is, set, setDescription, setLabel
-
-
-
-
Constructor Detail
-
PluginInfo
public PluginInfo(String className, Class<PT> pluginType)
Creates a new plugin metadata object.- Parameters:
className- The name of the class, which must implementSciJavaPlugin.pluginType- The type of plugin described by this metadata. SeeSciJavaPluginfor a list of common plugin types.
-
PluginInfo
public PluginInfo(String className, Class<PT> pluginType, Plugin annotation)
Creates a new plugin metadata object.- Parameters:
className- The name of the class, which must implementSciJavaPlugin.pluginType- The type of plugin described by this metadata. SeeSciJavaPluginfor a list of common plugin types.annotation- The @Pluginannotation to associate with this metadata object.
-
PluginInfo
public PluginInfo(String className, Class<PT> pluginType, Plugin annotation, ClassLoader classLoader)
Creates a new plugin metadata object.- Parameters:
className- The name of the class, which must implementSciJavaPlugin.pluginType- The type of plugin described by this metadata. SeeSciJavaPluginfor a list of common plugin types.annotation- The @Pluginannotation to associate with this metadata object.classLoader- TheClassLoaderto use when loading the class vialoadClass(), or null to use the current thread's context class loader by default.
-
PluginInfo
public PluginInfo(Class<? extends PT> pluginClass, Class<PT> pluginType)
Creates a new plugin metadata object.- Parameters:
pluginClass- The plugin class, which must implementSciJavaPlugin.pluginType- The type of plugin described by this metadata. SeeSciJavaPluginfor a list of common plugin types.
-
PluginInfo
public PluginInfo(Class<? extends PT> pluginClass, Class<PT> pluginType, Plugin annotation)
Creates a new plugin metadata object.- Parameters:
pluginClass- The plugin class, which must implementSciJavaPlugin.pluginType- The type of plugin described by this metadata. SeeSciJavaPluginfor a list of common plugin types.annotation- The @Pluginannotation to associate with this metadata object.
-
-
Method Detail
-
setPluginClass
public void setPluginClass(Class<? extends PT> pluginClass)
Explicitly sets theClassof the item objects.This is useful if your class is produced by something other than the system classloader.
-
getPluginClass
public Class<? extends PT> getPluginClass()
Obtains theClassof the item objects, if that class has already been loaded.- Returns:
- The
Class, or null if it has not yet been loaded byloadClass().
-
setPluginType
public void setPluginType(Class<PT> pluginType)
Sets the type of plugin described by the metadata.- See Also:
for a list of common plugin types.
-
getPluginType
public Class<PT> getPluginType()
Gets the type of plugin described by the metadata.- See Also:
for a list of common plugin types.
-
getIconURL
public URL getIconURL() throws InstantiableException
Gets the URL corresponding to the icon resource path.- Throws:
InstantiableException- See Also:
AbstractUIDetails.getIconPath()
-
inject
public boolean inject(Object o)
Injects the metadata into the given object. Note that this is only possible if the given object implements theHasPluginInfointerface.- Parameters:
o- The object to which the metadata should be assigned.- Returns:
- true If the metadata was successfully injected.
-
toString
public String toString()
- Overrides:
toStringin classAbstractUIDetails
-
getClassName
public String getClassName()
Description copied from interface:InstantiableGets the fully qualified name of theClassof the objects that can be created.- Specified by:
getClassNamein interfaceInstantiable<PT extends SciJavaPlugin>
-
loadClass
public Class<? extends PT> loadClass() throws InstantiableException
Description copied from interface:InstantiableLoads the class corresponding to the objects that are created byInstantiable.createInstance().Note that this class may not be precisely
T.classbut instead a subclass thereof.- Specified by:
loadClassin interfaceInstantiable<PT extends SciJavaPlugin>- Throws:
InstantiableException- See Also:
for an example of an type that typically instantiates objects of a subtype of rather than itself.
-
createInstance
public PT createInstance() throws InstantiableException
Description copied from interface:InstantiableCreates an object.- Specified by:
createInstancein interfaceInstantiable<PT extends SciJavaPlugin>- Throws:
InstantiableException
-
getIdentifier
public String getIdentifier()
Description copied from interface:IdentifiableGets a string intended to function as an identifier for the object.- Specified by:
getIdentifierin interfaceIdentifiable
-
getLocation
public String getLocation()
Description copied from interface:LocatableGets the URL string defining the object's location.- Specified by:
getLocationin interfaceLocatable
-
getVersion
public String getVersion()
Description copied from interface:VersionedGets the version of the object.- Specified by:
getVersionin interfaceVersioned
-
get
public static <P extends SciJavaPlugin> PluginInfo<?> get(Class<P> pluginClass, PluginIndex pluginIndex)
Finds aPluginInfoof the given plugin class in the specifiedPluginIndex. Note that to avoid loading plugin classes, class identity is determined by class name equality only.- Parameters:
pluginClass- The concrete class of the plugin whosePluginInfois desired.pluginIndex- ThePluginIndexto search for a matchingPluginInfo.- Returns:
- The matching
PluginInfo, or null if none found.
-
get
public static <P extends PT,PT extends SciJavaPlugin> PluginInfo<PT> get(Class<P> pluginClass, Class<PT> pluginType, PluginIndex pluginIndex)
Finds aPluginInfoof the given plugin class and plugin type in the specifiedPluginIndex. Note that to avoid loading plugin classes, class identity is determined by class name equality only.- Parameters:
pluginClass- The concrete class of the plugin whosePluginInfois desired.pluginType- The type of the plugin; seegetPluginType().pluginIndex- ThePluginIndexto search for a matchingPluginInfo.- Returns:
- The matching
PluginInfo, or null if none found.
-
get
public static <P extends PT,PT extends SciJavaPlugin> PluginInfo<PT> get(Class<P> pluginClass, Collection<? extends PluginInfo<PT>> plugins)
Finds aPluginInfoof the given plugin class in the specified list of plugins. Note that to avoid loading plugin classes, class identity is determined by class name equality only.- Parameters:
pluginClass- The concrete class of the plugin whosePluginInfois desired.plugins- The list of plugins to search for a match.- Returns:
- The matching
PluginInfo, or null if none found.
-
create
public static PluginInfo<?> create(Class<? extends SciJavaPlugin> pluginClass)
Creates aPluginInfofor the given plugin class. The class must be a concrete class annotated with the @Pluginannotation, from which the plugin type will be inferred.- Parameters:
pluginClass- The concrete class of the plugin for which a newPluginInfois desired.- Returns:
- A newly created
PluginInfofor the given plugin class. - Throws:
IllegalArgumentException- if the given class is not annotated with @Plugin, or its annotatedtype()is not a supertype of the plugin class.
-
create
public static <P extends PT,PT extends SciJavaPlugin> PluginInfo<PT> create(Class<P> pluginClass, Class<PT> pluginType)
Creates aPluginInfofor the given plugin class of the specified plugin type.- Parameters:
pluginClass- The concrete class of the plugin for which a newPluginInfois desired.pluginType- The type of the plugin; seegetPluginType().- Returns:
- A newly created
PluginInfofor the given plugin class.
-
getOrCreate
public static <P extends SciJavaPlugin> PluginInfo<?> getOrCreate(Class<P> pluginClass, PluginIndex pluginIndex)
Obtains aPluginInfofor the given plugin class. If one already exists in the specifiedPluginIndex, it is retrieved (seeget(Class, PluginIndex)); otherwise, a new one is created (seecreate(Class)) but not added to the index.- Parameters:
pluginClass- The concrete class of the plugin whosePluginInfois desired.pluginIndex- ThePluginIndexto search for a matchingPluginInfo.- Throws:
IllegalArgumentException- when creating a newPluginInfoif the associated plugin type cannot be inferred; seecreate(Class).
-
getOrCreate
public static <P extends PT,PT extends SciJavaPlugin> PluginInfo<PT> getOrCreate(Class<P> pluginClass, Class<PT> pluginType, PluginIndex pluginIndex)
Obtains aPluginInfofor the given plugin class. If one already exists in the specifiedPluginIndex, it is retrieved (seeget(Class, PluginIndex)); otherwise, a new one is created (seecreate(Class)) but not added to the index.- Parameters:
pluginClass- The concrete class of the plugin whosePluginInfois desired.pluginType- The type of the plugin; seegetPluginType().pluginIndex- ThePluginIndexto search for a matchingPluginInfo.
-
-