Last update: 2011-06-23

org.proteios.core
Class PluginDefinition

java.lang.Object
  extended by org.proteios.core.BasicItem<D>
      extended by org.proteios.core.OwnedItem<D>
          extended by org.proteios.core.SharedItem<PluginDefinitionData>
              extended by org.proteios.core.PluginDefinition
All Implemented Interfaces:
AccessControlled, Identifiable, Ownable, Removable, Shareable

public class PluginDefinition
extends SharedItem<PluginDefinitionData>
implements Removable

A plugin definition represents the executable plugin. Ie. the class name of a class implementing the Plugin interface.

Version:
2.0
Author:
Nicklas, Samuel
Last modified
$Date: 2009-04-09 08:48:11 +0200 (Thu, 09 Apr 2009) $

Field Summary
static int MAX_CLASSNAME_LENGTH
          The maximum length of the class name that can be stored in the database.
static int MAX_CONTACT_LENGTH
          The maximum length of the contact information that can be stored in the database.
static int MAX_COPYRIGHT_LENGTH
          The maximum length of the copyright notice that can be stored in the database.
static int MAX_EMAIL_LENGTH
          The maximum length of the email address that can be stored in the database.
static int MAX_JARPATH_LENGTH
          The maximum length of the jar path name that can be stored in the database.
static int MAX_NAME_LENGTH
          The maximum length of the name that can be stored in the database.
static int MAX_PLUGIN_VERSION_LENGTH
          The maximum length of the plugin version that can be stored in the database.
static int MAX_URL_LENGTH
          The maximum length of the url that can be stored in the database.
static Item TYPE
          The type of item represented by this class.
 
Method Summary
static Map<Plugin.MainType,Integer> countPlugins(DbControl dc, GuiContext gc)
          Count the number of plugins that can be used in a given context.
static PluginDefinition getByClassName(DbControl dc, String className)
          Get a PluginDefinition item when you know the class name.
static PluginDefinition getById(DbControl dc, int id)
          Get a PluginDefinition item when you know the ID.
 String getClassName()
          Get the class name of the Java class that implements this plugin.
 String getContact()
          Get contact information for the plugin.
 String getCopyright()
          Get a copyright notice for the plugin.
 String getDescription()
          Get a description of the plugin.
 String getEmail()
          Get an email address that can be used to get more information about the plugin.
 Set<GuiContext> getGuiContexts()
          Get the Item types where it makes sense to use this plugin for a client application.
 String getJarPath()
          Get the path to the JAR file that contains the plugin class file.
 Plugin.MainType getMainType()
          Get the type of plugin.
 String getName()
          Get the name of the plugin.
static PluginDefinition getNew(DbControl dc, String className)
          Create a new PluginDefinition item.
static PluginDefinition getNew(DbControl dc, String className, File jarFile)
           
 ItemQuery<PluginConfiguration> getPluginConfigurations()
          Get a query that returns the configurations for this plugin definition.
 ItemQuery<PluginType> getPluginTypes()
          Get a query that returns the plugin types for this plugin definition.
 String getPluginVersion()
          Get the plugin version.
static ItemQuery<PluginDefinition> getQuery()
          Get a query that returns plugin definitions.
static ItemQuery<PluginDefinition> getQuery(GuiContext gc, String interfaceName)
          Get a query that returns all plugins related to a specified GUI context and implementing a certain interface.
 Item getType()
          Get the type of item represented by the object.
 String getUrl()
          Get a URL with more information about the plugin.
 boolean isInContext(GuiContext context)
          Check if it makes sense to use this plugin in the context of the specified item.
 boolean isInteractive()
          Check if the plugin is interactive or not.
 boolean isRemoved()
          Check if the removed flag is set for this item.
 boolean isUsed()
          Check if a PluginConfiguration is using this definition.
 void loadPluginInformation(String jarPath, String className)
          Load a plugin and copy all information, ie. plugin.about(), to the internal data structure.
<P extends Plugin>
P
newInstance(Class<P> clazz, SessionControl sc, PluginConfiguration configuration, Job job)
           
 PluginConfiguration newPluginConfiguration()
          Create a new PluginConfiguration for this plugin.
protected  void setDescription(String description)
          The description cannot be changed.
 void setRemoved(boolean removed)
          Set the removed flag for this item.
 boolean supports(PluginType pluginType)
          Check if a plugin implements the interface specified by the plugin type.
 boolean supports(String interfaceName)
          Check if a plugin implements the interface specified by the plugin type.
 
Methods inherited from class org.proteios.core.SharedItem
getItemKey, getProjectKey, isShared, setItemKey, setProjectKey
 
Methods inherited from class org.proteios.core.OwnedItem
getOwner, setOwner
 
Methods inherited from class org.proteios.core.BasicItem
checkPermission, equals, getDbControl, getId, getPermissions, getSessionControl, getVersion, hashCode, hasPermission, isDetached, isInDatabase, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.proteios.core.Identifiable
getId, getVersion
 
Methods inherited from interface org.proteios.core.AccessControlled
checkPermission, hasPermission
 
Methods inherited from interface org.proteios.core.Ownable
getOwner, setOwner
 

Field Detail

TYPE

public static final Item TYPE
The type of item represented by this class.

See Also:
Item.PLUGINDEFINITION, getType()

MAX_CLASSNAME_LENGTH

public static final int MAX_CLASSNAME_LENGTH
The maximum length of the class name that can be stored in the database. Check the length against this value before calling the setClassName method to avoid exceptions.

See Also:
Constant Field Values

MAX_JARPATH_LENGTH

public static final int MAX_JARPATH_LENGTH
The maximum length of the jar path name that can be stored in the database.

See Also:
Constant Field Values

MAX_NAME_LENGTH

public static final int MAX_NAME_LENGTH
The maximum length of the name that can be stored in the database.

See Also:
Constant Field Values

MAX_PLUGIN_VERSION_LENGTH

public static final int MAX_PLUGIN_VERSION_LENGTH
The maximum length of the plugin version that can be stored in the database.

See Also:
Constant Field Values

MAX_COPYRIGHT_LENGTH

public static final int MAX_COPYRIGHT_LENGTH
The maximum length of the copyright notice that can be stored in the database.

See Also:
Constant Field Values

MAX_CONTACT_LENGTH

public static final int MAX_CONTACT_LENGTH
The maximum length of the contact information that can be stored in the database.

See Also:
Constant Field Values

MAX_EMAIL_LENGTH

public static final int MAX_EMAIL_LENGTH
The maximum length of the email address that can be stored in the database.

See Also:
Constant Field Values

MAX_URL_LENGTH

public static final int MAX_URL_LENGTH
The maximum length of the url that can be stored in the database.

See Also:
Constant Field Values
Method Detail

getNew

public static PluginDefinition getNew(DbControl dc,
                                      String className)
                               throws BaseException
Create a new PluginDefinition item.

Parameters:
dc - The DbControl which will be used for permission checking and database access.
className - The name of the class that implements the plugin interface
Returns:
The new PluginDefinition item
Throws:
BaseException - If there is an error

getNew

public static PluginDefinition getNew(DbControl dc,
                                      String className,
                                      File jarFile)
                               throws BaseException
Throws:
BaseException

getById

public static PluginDefinition getById(DbControl dc,
                                       int id)
                                throws ItemNotFoundException,
                                       PermissionDeniedException,
                                       BaseException
Get a PluginDefinition item when you know the ID.

Parameters:
dc - The DbControl which will be used for permission checking and database access.
id - The ID of the item to load.
Returns:
The PluginDefinition item.
Throws:
ItemNotFoundException - If an item with the specified ID is not found.
PermissionDeniedException - If the logged in user doesn't have READ permission for the item.
BaseException - If there is another error.

getByClassName

public static PluginDefinition getByClassName(DbControl dc,
                                              String className)
                                       throws ItemNotFoundException,
                                              PermissionDeniedException,
                                              BaseException
Get a PluginDefinition item when you know the class name.

Parameters:
dc - The DbControl which will be used for permission checking and database access.
className - The class name of the item to load.
Returns:
The PluginDefinition item.
Throws:
ItemNotFoundException - If an item with the specified class name is not found.
PermissionDeniedException - If the logged in user doesn't have READ permission for the item.
BaseException - If there is another error.

getQuery

public static ItemQuery<PluginDefinition> getQuery()
Get a query that returns plugin definitions.

Returns:
An ItemQuery object

getQuery

public static ItemQuery<PluginDefinition> getQuery(GuiContext gc,
                                                   String interfaceName)
Get a query that returns all plugins related to a specified GUI context and implementing a certain interface. Ie. The isInContext(GuiContext) returns true for the specified item, and supports(PluginType) returns true for the specified interface.

Parameters:
gc - The context the plugin should be related to, or null if this parameter is irrelevant
interfaceName - The complete name of the interface that the plugin must implement, or null if this parameter is irrelevant

countPlugins

public static Map<Plugin.MainType,Integer> countPlugins(DbControl dc,
                                                        GuiContext gc)
                                                 throws BaseException
Count the number of plugins that can be used in a given context.

Parameters:
dc - An open DbControl object
gc - The context to count plugins for
Returns:
A map with the main type as the key and the number of plugins as the value
Throws:
BaseException

getType

public Item getType()
Description copied from interface: Identifiable
Get the type of item represented by the object. The returned value is one of the values defined in the Item enumeration.

Specified by:
getType in interface Identifiable
Returns:
A value indicating the type of item

isRemoved

public boolean isRemoved()
Description copied from interface: Removable
Check if the removed flag is set for this item.

Specified by:
isRemoved in interface Removable
Returns:
TRUE if the item is flagged as removed, FALSE otherwise

setRemoved

public void setRemoved(boolean removed)
                throws PermissionDeniedException
Description copied from interface: Removable
Set the removed flag for this item.

Specified by:
setRemoved in interface Removable
Parameters:
removed - TRUE if the item should be flagged as removed, FALSE otherwise
Throws:
PermissionDeniedException - If the logged in user doesn't have Permission.DELETE permission for setting the flag to TRUE or Permission.WRITE permission for setting the flag to FALSE

isUsed

public boolean isUsed()
               throws BaseException
Check if a PluginConfiguration is using this definition.

Specified by:
isUsed in class BasicItem<PluginDefinitionData>
Returns:
TRUE if this item is used, FALSE otherwise
Throws:
BaseException

getClassName

public String getClassName()
Get the class name of the Java class that implements this plugin. The specified class must implement the Plugin interface.

Returns:
The class name for this plugin

getJarPath

public String getJarPath()
Get the path to the JAR file that contains the plugin class file. If this value is null, the plugin must be on the classpath.


getName

public String getName()
Get the name of the plugin.

Returns:
A string with the name of the plugin

getPluginVersion

public String getPluginVersion()
Get the plugin version.

Returns:
String A string with the version in the about info for the plugin.

getDescription

public String getDescription()
Get a description of the plugin.

Returns:
A string with a description, or null if not known

setDescription

protected void setDescription(String description)
                       throws InvalidDataException
The description cannot be changed. Used internally only.

Throws:
InvalidDataException - If the description is too long
Developer info
This value is initialised upon installation to: plugin.about().getDescription() See: loadPluginInformation(String, String)

getCopyright

public String getCopyright()
Get a copyright notice for the plugin.

Returns:
A string with a copyright notice, or null if not known

getContact

public String getContact()
Get contact information for the plugin.

Returns:
A string with contact information, or null if not known

getEmail

public String getEmail()
Get an email address that can be used to get more information about the plugin.

Returns:
A string with the email address, or null if not known

getUrl

public String getUrl()
Get a URL with more information about the plugin.

Returns:
A string containing the URL, or null if not known

getMainType

public Plugin.MainType getMainType()
Get the type of plugin.

Returns:
A type code that is defined in the enum Plugin.MainType.

isInteractive

public boolean isInteractive()
Check if the plugin is interactive or not. An interactive plugin implements the InteractivePlugin interface and can be dynamically configured by telling the client application what configuration parameters it needs.


isInContext

public boolean isInContext(GuiContext context)
Check if it makes sense to use this plugin in the context of the specified item. For example, a plugin that imports peaks would return true if passed Item.PROTEIOS_PEAK.

Parameters:
context - The GuiContext type
Returns:
TRUE if the plugin handles the item, FALSE otherwise

getGuiContexts

public Set<GuiContext> getGuiContexts()
Get the Item types where it makes sense to use this plugin for a client application.

Returns:
A Set of Item:s or an empty set if the plugin is not concerned about items

newPluginConfiguration

public PluginConfiguration newPluginConfiguration()
                                           throws PermissionDeniedException,
                                                  BaseException
Create a new PluginConfiguration for this plugin.

Returns:
The new PluginConfiguration item
Throws:
PermissionDeniedException - If the logged in user doesn't have use permission for this plugin definition
BaseException - If there is another error

getPluginConfigurations

public ItemQuery<PluginConfiguration> getPluginConfigurations()
Get a query that returns the configurations for this plugin definition.

Returns:
An ItemQuery object

getPluginTypes

public ItemQuery<PluginType> getPluginTypes()
Get a query that returns the plugin types for this plugin definition.

Returns:
An ItemQuery object

supports

public boolean supports(PluginType pluginType)
Check if a plugin implements the interface specified by the plugin type.

Parameters:
pluginType - The pluginType to check
Returns:
TRUE if the plugin implements the specified interface, FALSE otherwise

supports

public boolean supports(String interfaceName)
Check if a plugin implements the interface specified by the plugin type.

Parameters:
interfaceName - The pluginType to check
Returns:
TRUE if the plugin implements the specified interface, FALSE otherwise

newInstance

public <P extends Plugin> P newInstance(Class<P> clazz,
                                        SessionControl sc,
                                        PluginConfiguration configuration,
                                        Job job)
                             throws PermissionDeniedException,
                                    BaseException
Throws:
PermissionDeniedException
BaseException

loadPluginInformation

public void loadPluginInformation(String jarPath,
                                  String className)
                           throws PermissionDeniedException,
                                  InvalidDataException,
                                  BaseException
Load a plugin and copy all information, ie. plugin.about(), to the internal data structure.

Throws:
PermissionDeniedException
InvalidDataException
BaseException

Last update: 2011-06-23