com.atlassian.plugin.impl
Class AbstractDelegatingPlugin

java.lang.Object
  extended by com.atlassian.plugin.impl.AbstractDelegatingPlugin
All Implemented Interfaces:
Plugin, Resourced, java.lang.Comparable<Plugin>

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

Delegating plugin that supports easy wrapping

Since:
2.2.0

Field Summary
 
Fields inherited from interface com.atlassian.plugin.Plugin
NAME_COMPARATOR
 
Constructor Summary
AbstractDelegatingPlugin(Plugin delegate)
           
 
Method Summary
 void addModuleDescriptor(ModuleDescriptor<?> moduleDescriptor)
           
 void close()
          Free any resources held by this plugin.
 int compareTo(Plugin o)
           
 boolean containsSystemModule()
           
 void disable()
          Disables the plugin.
 void enable()
          Enables the plugin.
 boolean equals(java.lang.Object obj)
           
 java.lang.ClassLoader getClassLoader()
          Get the classloader for the plugin.
 java.util.Date getDateLoaded()
          The date this plugin was loaded into the system.
 Plugin getDelegate()
           
 java.lang.String getI18nNameKey()
          Returns the i18nKey used to get an internationalised name for this plugin.
 java.lang.String getKey()
           
 ModuleDescriptor<?> getModuleDescriptor(java.lang.String key)
          Get the ModuleDescriptor for a particular key.
 java.util.Collection<ModuleDescriptor<?>> getModuleDescriptors()
          Get the Collection of descriptors.
<M> java.util.List<ModuleDescriptor<M>>
getModuleDescriptorsByModuleClass(java.lang.Class<M> moduleClass)
          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()
           
 java.net.URL getResource(java.lang.String path)
          Retrieve the URL of the resource from the plugin.
 java.io.InputStream getResourceAsStream(java.lang.String name)
          Load a given resource from the plugin.
 ResourceDescriptor getResourceDescriptor(java.lang.String type, java.lang.String name)
          Get a ResourceDescriptor of a particular type and name.
 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.
 int hashCode()
           
 void install()
          Installs the plugin into any internal, managing container.
 boolean isBundledPlugin()
          Whether the plugin is a "bundled" plugin that can't be removed.
 boolean isDeleteable()
          Should the plugin file be deleted on unistall?
 boolean isDynamicallyLoaded()
          Whether or not this plugin is loaded dynamically at runtime.
 boolean isEnabled()
           
 boolean isEnabledByDefault()
           
 boolean isSystemPlugin()
          Whether the plugin is a "system" plugin that shouldn't be made visible to the user.
 boolean isUninstallable()
          Whether or not this plugin can be 'uninstalled'.
<T> java.lang.Class<T>
loadClass(java.lang.String clazz, java.lang.Class<?> callingClass)
          Get the plugin to load a specific class.
 void setEnabled(boolean enabled)
           
 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)
           
 void setPluginsVersion(int version)
          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.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractDelegatingPlugin

public AbstractDelegatingPlugin(Plugin delegate)
Method Detail

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 version)
Description copied from interface: Plugin
Sets the version of the plugins system

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

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()

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

getModuleDescriptors

public java.util.Collection<ModuleDescriptor<?>> getModuleDescriptors()
Description copied from interface: Plugin
Get the Collection of descriptors.

The iteration order of the collection is the order that the modules will be enabled, and should be the same order that the modules appear in the plugin descriptor.

Specified by:
getModuleDescriptors in interface Plugin
Returns:
the modules contained by this plugin in the order they are to be enabled

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 <M> java.util.List<ModuleDescriptor<M>> getModuleDescriptorsByModuleClass(java.lang.Class<M> moduleClass)
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:
M - The expected module type of the returned descriptors.
Parameters:
moduleClass - the super class the descriptors return.
Returns:
the List of descriptors of the expected type.

isEnabledByDefault

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

setEnabledByDefault

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

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

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.

isEnabled

public boolean isEnabled()
Specified by:
isEnabled in interface Plugin
Returns:
true if this plugin is enabled.

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

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.

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.

isUninstallable

public boolean isUninstallable()
Description copied from interface: Plugin
Whether or not this plugin can be 'uninstalled'.

Specified by:
isUninstallable in interface Plugin
Returns:
true if this plugin can be 'uninstalled'.

isDeleteable

public boolean isDeleteable()
Description copied from interface: Plugin
Should the plugin file be deleted on unistall?

Specified by:
isDeleteable in interface Plugin
Returns:
true if this plugin file should be deleted on unistall.

isDynamicallyLoaded

public boolean isDynamicallyLoaded()
Description copied from interface: Plugin
Whether or not this plugin is loaded dynamically at runtime.

Specified by:
isDynamicallyLoaded in interface Plugin
Returns:
true if this plugin is loaded dynamically at runtime.

loadClass

public <T> java.lang.Class<T> loadClass(java.lang.String clazz,
                                        java.lang.Class<?> callingClass)
                             throws java.lang.ClassNotFoundException
Description copied from interface: Plugin
Get the plugin to load a specific class.

Specified by:
loadClass in interface Plugin
Parameters:
clazz - The name of the class to be loaded
callingClass - The class calling the loading (used to help find a classloader)
Returns:
The loaded class.
Throws:
java.lang.ClassNotFoundException - if the class cannot be located.

getClassLoader

public java.lang.ClassLoader getClassLoader()
Description copied from interface: Plugin
Get the classloader for the plugin.

Specified by:
getClassLoader in interface Plugin
Returns:
The classloader used to load classes for this plugin

getResource

public java.net.URL getResource(java.lang.String path)
Description copied from interface: Plugin
Retrieve the URL of the resource from the plugin.

Specified by:
getResource in interface Plugin
Parameters:
path - the name of the resource to be loaded
Returns:
The URL to the resource, or null if the resource is not found

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String name)
Description copied from interface: Plugin
Load a given resource from the plugin. Plugins that are loaded dynamically will need to implement this in a way that loads the resource from the same context as the plugin. Static plugins can just pull them from their own classloader.

Specified by:
getResourceAsStream in interface Plugin
Parameters:
name - The name of the resource to be loaded.
Returns:
An InputStream for the resource, or null if the resource is not found.

setEnabled

public void setEnabled(boolean enabled)
Specified by:
setEnabled in interface Plugin
Parameters:
enabled - new enabled state

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 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

uninstall

public 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

enable

public 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

disable

public 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

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

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.

getResourceDescriptor

public ResourceDescriptor getResourceDescriptor(java.lang.String type,
                                                java.lang.String name)
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.

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.

compareTo

public int compareTo(Plugin o)
Specified by:
compareTo in interface java.lang.Comparable<Plugin>

getDelegate

public Plugin getDelegate()

toString

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

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object


Copyright © 2009 Atlassian Pty Ltd. All Rights Reserved.