com.atlassian.plugin.impl
Class AbstractPlugin

java.lang.Object
  extended by com.atlassian.plugin.impl.AbstractPlugin
All Implemented Interfaces:
Plugin, Resourced, java.lang.Comparable<Plugin>
Direct Known Subclasses:
DefaultDynamicPlugin, StaticPlugin, XmlDynamicPlugin

public abstract class AbstractPlugin
extends java.lang.Object
implements Plugin, java.lang.Comparable<Plugin>


Field Summary
 
Fields inherited from interface com.atlassian.plugin.Plugin
NAME_COMPARATOR
 
Constructor Summary
AbstractPlugin()
           
 
Method Summary
 void addModuleDescriptor(ModuleDescriptor<?> moduleDescriptor)
           
 void close()
          Free any resources held by this plugin.
protected  boolean compareAndSetPluginState(PluginState requiredExistingState, PluginState desiredState)
          Only sets the plugin state if it is in the expected state.
 int compareTo(Plugin otherPlugin)
          Compares this Plugin to another Plugin for order.
 boolean containsSystemModule()
           
 void disable()
          Disables the plugin.
protected  void disableInternal()
          Perform any internal disabling logic.
 void enable()
          Enables the plugin.
protected  PluginState enableInternal()
          Perform any internal enabling logic.
 java.util.Date getDateLoaded()
          The date this plugin was loaded into the system.
 java.lang.String getI18nNameKey()
          Returns the i18nKey used to get an internationalised name for this plugin.
 java.lang.String getKey()
           
protected  org.slf4j.Logger getLog()
           
 ModuleDescriptor<?> getModuleDescriptor(java.lang.String key)
          Get the ModuleDescriptor for a particular key.
 java.util.Collection<ModuleDescriptor<?>> getModuleDescriptors()
          Returns the module descriptors for this plugin
<T> java.util.List<ModuleDescriptor<T>>
getModuleDescriptorsByModuleClass(java.lang.Class<T> aClass)
          Get the descriptors whose module class implements or is assignable from the supplied Class.
 java.lang.String getName()
          Returns the non-localised name of this plugin if defined.
 PluginInformation getPluginInformation()
           
 PluginState getPluginState()
          Returns this plugin's current state.
 int getPluginsVersion()
          Gets the version of the plugins system to handle this plugin
 java.util.Set<java.lang.String> getRequiredPlugins()
           
 ResourceDescriptor getResourceDescriptor(java.lang.String type, java.lang.String name)
          Deprecated.  
 java.util.List<ResourceDescriptor> getResourceDescriptors()
          Get a List of all the descriptors .
 java.util.List<ResourceDescriptor> getResourceDescriptors(java.lang.String type)
          Get a list of all descriptors of a particular type.
 ResourceLocation getResourceLocation(java.lang.String type, java.lang.String name)
          Get a ResourceLocation of a particular type and name.
 void install()
          Installs the plugin into any internal, managing container.
protected  void installInternal()
          Perform any internal installation logic.
 boolean isBundledPlugin()
          Whether the plugin is a "bundled" plugin that can't be removed.
 boolean isEnabled()
          Deprecated. 
 boolean isEnabledByDefault()
           
 boolean isSystemPlugin()
          Whether the plugin is a "system" plugin that shouldn't be made visible to the user.
protected  void removeModuleDescriptor(java.lang.String key)
           
 void setEnabled(boolean enabled)
          Deprecated. 
 void setEnabledByDefault(boolean enabledByDefault)
           
 void setI18nNameKey(java.lang.String i18nNameKey)
          Sets the i18nKey used to get an internationalised name for this plugin.
 void setKey(java.lang.String aPackage)
           
 void setName(java.lang.String name)
          Sets the non-localised name of this plugin.
 void setPluginInformation(PluginInformation pluginInformation)
           
protected  void setPluginState(PluginState state)
           
 void setPluginsVersion(int pluginsVersion)
          Sets the version of the plugins system
 void setResources(Resourced resources)
           
 void setSystemPlugin(boolean system)
           
 java.lang.String toString()
           
 void uninstall()
          Uninstalls the plugin from any internal container.
protected  void uninstallInternal()
          Perform any internal uninstallation logic.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.atlassian.plugin.Plugin
getClassLoader, getResource, getResourceAsStream, isDeleteable, isDynamicallyLoaded, isUninstallable, loadClass
 

Constructor Detail

AbstractPlugin

public AbstractPlugin()
Method Detail

getName

public java.lang.String getName()
Description copied from interface: Plugin
Returns the non-localised name of this plugin if defined.

This corresponds to the value of the name field in the plugin's XML configuration file.

You would expect a plugin developer to fill in one of either name, or i18n-name-key, but the framework does no validation and makes no guarantees that this is the case.

Specified by:
getName in interface Plugin
Returns:
the non-localised name of this plugin if defined, or null.
See Also:
Plugin.getI18nNameKey()

setName

public void setName(java.lang.String name)
Description copied from interface: Plugin
Sets the non-localised name of this plugin.

Specified by:
setName in interface Plugin
Parameters:
name - the name.
See Also:
Plugin.getName()

getLog

protected org.slf4j.Logger getLog()
Returns:
the logger used internally

getI18nNameKey

public java.lang.String getI18nNameKey()
Description copied from interface: Plugin
Returns the i18nKey used to get an internationalised name for this plugin.

This corresponds to the value of the i18n-name-key field in the plugin's XML configuration file.

You would expect a plugin developer to fill in one of either name, or i18n-name-key, but the framework does no validation and makes no guarantees that this is the case.

Specified by:
getI18nNameKey in interface Plugin
Returns:
the i18n Name Key for this plugin if defined, or null.
See Also:
Plugin.getName()

setI18nNameKey

public void setI18nNameKey(java.lang.String i18nNameKey)
Description copied from interface: Plugin
Sets the i18nKey used to get an internationalised name for this plugin.

Specified by:
setI18nNameKey in interface Plugin
Parameters:
i18nNameKey - the i18n Name Key.
See Also:
Plugin.getI18nNameKey()

getKey

public java.lang.String getKey()
Specified by:
getKey in interface Plugin

setKey

public void setKey(java.lang.String aPackage)
Specified by:
setKey in interface Plugin

addModuleDescriptor

public void addModuleDescriptor(ModuleDescriptor<?> moduleDescriptor)
Specified by:
addModuleDescriptor in interface Plugin

removeModuleDescriptor

protected void removeModuleDescriptor(java.lang.String key)

getModuleDescriptors

public java.util.Collection<ModuleDescriptor<?>> getModuleDescriptors()
Returns the module descriptors for this plugin

Specified by:
getModuleDescriptors in interface Plugin
Returns:
An unmodifiable list of the module descriptors.

getModuleDescriptor

public ModuleDescriptor<?> getModuleDescriptor(java.lang.String key)
Description copied from interface: Plugin
Get the ModuleDescriptor for a particular key. Returns null if the plugin does not exist.

Note: The ModuleDescriptor.getModule() may throw ClassCastException if the expected type is incorrect.

Specified by:
getModuleDescriptor in interface Plugin
Parameters:
key - the String complete key of the module, in the form "org.example.plugin:module-key".
Returns:
the ModuleDescriptor of the expected type.

getModuleDescriptorsByModuleClass

public <T> java.util.List<ModuleDescriptor<T>> getModuleDescriptorsByModuleClass(java.lang.Class<T> aClass)
Description copied from interface: Plugin
Get the descriptors whose module class implements or is assignable from the supplied Class.

Note: The ModuleDescriptor.getModule() may throw ClassCastException if the expected type is incorrect. Normally this method would not be supplied with anything other than Object or <?>, unless you are confident in the super type of the module classes this Plugin provides.

Specified by:
getModuleDescriptorsByModuleClass in interface Plugin
Type Parameters:
T - The expected module type of the returned descriptors.
Parameters:
aClass - the super class the descriptors return.
Returns:
the List of descriptors of the expected type.

getPluginState

public PluginState getPluginState()
Description copied from interface: Plugin
Returns this plugin's current state.

Specified by:
getPluginState in interface Plugin
Returns:
the current state of the plugin.

setPluginState

protected void setPluginState(PluginState state)

compareAndSetPluginState

protected boolean compareAndSetPluginState(PluginState requiredExistingState,
                                           PluginState desiredState)
Only sets the plugin state if it is in the expected state.

Parameters:
requiredExistingState - The expected state
desiredState - The desired state
Returns:
True if the set was successful, false if not in the expected state
Since:
2.4

isEnabledByDefault

public boolean isEnabledByDefault()
Specified by:
isEnabledByDefault in interface Plugin

setEnabledByDefault

public void setEnabledByDefault(boolean enabledByDefault)
Specified by:
setEnabledByDefault in interface Plugin

getPluginsVersion

public int getPluginsVersion()
Description copied from interface: Plugin
Gets the version of the plugins system to handle this plugin

Specified by:
getPluginsVersion in interface Plugin
Returns:
The plugins version. If undefined, assumed to be 1.

setPluginsVersion

public void setPluginsVersion(int pluginsVersion)
Description copied from interface: Plugin
Sets the version of the plugins system

Specified by:
setPluginsVersion in interface Plugin
Parameters:
pluginsVersion - The version

getPluginInformation

public PluginInformation getPluginInformation()
Specified by:
getPluginInformation in interface Plugin

setPluginInformation

public void setPluginInformation(PluginInformation pluginInformation)
Specified by:
setPluginInformation in interface Plugin

setResources

public void setResources(Resourced resources)
Specified by:
setResources in interface Plugin

getResourceDescriptors

public java.util.List<ResourceDescriptor> getResourceDescriptors()
Description copied from interface: Resourced
Get a List of all the descriptors .

Note: since 2.2 this list must be immutable, previously modifying this list could modify the underlying list.

Specified by:
getResourceDescriptors in interface Resourced
Returns:
all resource descriptors this object supports.

getResourceDescriptors

public java.util.List<ResourceDescriptor> getResourceDescriptors(java.lang.String type)
Description copied from interface: Resourced
Get a list of all descriptors of a particular type.

Note: since 2.2 this list must be immutable, previously this list was modifiable but modifications would not be reflected in the underlying list.

Specified by:
getResourceDescriptors in interface Resourced
Returns:
all resource descriptors this object supports.

getResourceLocation

public ResourceLocation getResourceLocation(java.lang.String type,
                                            java.lang.String name)
Description copied from interface: Resourced
Get a ResourceLocation of a particular type and name.

Specified by:
getResourceLocation in interface Resourced
Returns:
the specified resource location if found, null otherwise.

getResourceDescriptor

@Deprecated
public ResourceDescriptor getResourceDescriptor(java.lang.String type,
                                                           java.lang.String name)
Deprecated. 

Description copied from interface: Resourced
Get a ResourceDescriptor of a particular type and name.

Specified by:
getResourceDescriptor in interface Resourced
Returns:
the specified resource descriptor if found, null otherwise.

isEnabled

@Deprecated
public boolean isEnabled()
Deprecated. 

Specified by:
isEnabled in interface Plugin
Returns:
true if the plugin has been enabled

enable

public final void enable()
Description copied from interface: Plugin
Enables the plugin. Unless an exception is thrown, the plugin should then be in either the PluginState.ENABLING or PluginState.ENABLED state. If the plugin is already in the PluginState.ENABLING or PluginState.ENABLED state, nothing will happen.

Specified by:
enable in interface Plugin

enableInternal

protected PluginState enableInternal()
                              throws PluginException
Perform any internal enabling logic. Subclasses should only throw PluginException.

Returns:
Either PluginState.ENABLED or PluginState.ENABLING
Throws:
PluginException - If the plugin could not be enabled
Since:
2.2.0

disable

public final void disable()
Description copied from interface: Plugin
Disables the plugin. Unless an exception is thrown, the plugin should be in the PluginState.DISABLED state. If the plugin is already in the PluginState.DISABLED state, nothing will happen.

Specified by:
disable in interface Plugin

disableInternal

protected void disableInternal()
                        throws PluginException
Perform any internal disabling logic. Subclasses should only throw PluginException.

Throws:
PluginException - If the plugin could not be disabled
Since:
2.2.0

getRequiredPlugins

public java.util.Set<java.lang.String> getRequiredPlugins()
Specified by:
getRequiredPlugins in interface Plugin
Returns:
A list of plugin keys that this plugin is dependent upon, or an empty list if none

close

public void close()
Description copied from interface: Plugin
Free any resources held by this plugin. To be called during uninstallation of the Plugin.

Specified by:
close in interface Plugin

install

public final void install()
Description copied from interface: Plugin
Installs the plugin into any internal, managing container. This method will be called on every startup. Unless an exception is thrown, the plugin should be in the PluginState.INSTALLED state. If the plugin is already in the PluginState.INSTALLED state, nothing will happen.

Specified by:
install in interface Plugin

installInternal

protected void installInternal()
                        throws PluginException
Perform any internal installation logic. Subclasses should only throw PluginException.

Throws:
PluginException - If the plugin could not be installed
Since:
2.2.0

uninstall

public final void uninstall()
Description copied from interface: Plugin
Uninstalls the plugin from any internal container. This method will be called on every shutdown. Unless an exception is thrown, the plugin should be in the PluginState.UNINSTALLED state. If the plugin is already in the PluginState.UNINSTALLED state, nothing will happen.

Specified by:
uninstall in interface Plugin

uninstallInternal

protected void uninstallInternal()
                          throws PluginException
Perform any internal uninstallation logic. Subclasses should only throw PluginException.

Throws:
PluginException - If the plugin could not be uninstalled
Since:
2.2.0

setEnabled

@Deprecated
public void setEnabled(boolean enabled)
Deprecated. 

Setter for the enabled state of a plugin. If this is set to false then the plugin will not execute.

Specified by:
setEnabled in interface Plugin
Parameters:
enabled - new enabled state

isSystemPlugin

public boolean isSystemPlugin()
Description copied from interface: Plugin
Whether the plugin is a "system" plugin that shouldn't be made visible to the user.

Specified by:
isSystemPlugin in interface Plugin
Returns:
true if this plugin is a "system" plugin.

containsSystemModule

public boolean containsSystemModule()
Specified by:
containsSystemModule in interface Plugin

setSystemPlugin

public void setSystemPlugin(boolean system)
Specified by:
setSystemPlugin in interface Plugin
Parameters:
system - whether the plugin is a "system" plugin that shouldn't be made visible to the user.

getDateLoaded

public java.util.Date getDateLoaded()
Description copied from interface: Plugin
The date this plugin was loaded into the system.

Specified by:
getDateLoaded in interface Plugin
Returns:
The date this plugin was loaded into the system.

isBundledPlugin

public boolean isBundledPlugin()
Description copied from interface: Plugin
Whether the plugin is a "bundled" plugin that can't be removed.

Specified by:
isBundledPlugin in interface Plugin
Returns:
true if this plugin is a "bundled" plugin.

compareTo

public int compareTo(Plugin otherPlugin)
Compares this Plugin to another Plugin for order. The primary sort field is the key, and the secondary field is the version number.

Specified by:
compareTo in interface java.lang.Comparable<Plugin>
Parameters:
otherPlugin - The plugin to be compared.
Returns:
a negative integer, zero, or a positive integer as this Plugin is less than, equal to, or greater than the specified Plugin.
See Also:
VersionStringComparator, Comparable.compareTo(T)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2010 Atlassian. All Rights Reserved.