com.atlassian.plugin.osgi.factory
Class OsgiBundlePlugin

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

public class OsgiBundlePlugin
extends AbstractPlugin

Plugin that wraps an OSGi bundle that has no plugin descriptor.


Field Summary
 
Fields inherited from interface com.atlassian.plugin.Plugin
NAME_COMPARATOR
 
Constructor Summary
OsgiBundlePlugin(org.osgi.framework.Bundle bundle, java.lang.String key, PluginEventManager pluginEventManager)
           
 
Method Summary
 void addModuleDescriptor(ModuleDescriptor<?> moduleDescriptor)
           
 boolean containsSystemModule()
           
protected  void disableInternal()
          Perform any internal disabling logic.
protected  PluginState enableInternal()
          Perform any internal enabling logic.
 java.lang.ClassLoader getClassLoader()
          Get the classloader for the plugin.
 java.util.Date getDateLoaded()
          The date this plugin was loaded into the system.
 java.lang.String getKey()
           
 ModuleDescriptor<?> getModuleDescriptor(java.lang.String key)
          Get the ModuleDescriptor for a particular key.
 java.util.Collection<ModuleDescriptor<?>> getModuleDescriptors()
          Returns a copy of the module descriptors for this plugin
<M> java.util.List<ModuleDescriptor<M>>
getModuleDescriptorsByModuleClass(java.lang.Class<M> 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()
           
 int getPluginsVersion()
          Gets the version of the plugins system to handle this plugin
 java.net.URL getResource(java.lang.String name)
          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.
 boolean isDeleteable()
          Should the plugin file be deleted on unistall?
 boolean isDynamicallyLoaded()
          Whether or not this plugin is loaded dynamically at runtime.
 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 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)
           
protected  void uninstallInternal()
          Perform any internal uninstallation logic.
 
Methods inherited from class com.atlassian.plugin.impl.AbstractPlugin
close, compareTo, disable, enable, getI18nNameKey, getLog, getPluginState, getRequiredPlugins, install, installInternal, isBundledPlugin, isEnabled, removeModuleDescriptor, setEnabled, setPluginState, toString, uninstall
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OsgiBundlePlugin

public OsgiBundlePlugin(org.osgi.framework.Bundle bundle,
                        java.lang.String key,
                        PluginEventManager pluginEventManager)
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
Overrides:
getPluginsVersion in class AbstractPlugin
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
Overrides:
setPluginsVersion in class AbstractPlugin
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
Overrides:
getName in class AbstractPlugin
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
Overrides:
setName in class AbstractPlugin
Parameters:
name - the name.
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
Overrides:
setI18nNameKey in class AbstractPlugin
Parameters:
i18nNameKey - the i18n Name Key.
See Also:
Plugin.getI18nNameKey()

getKey

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

setKey

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

addModuleDescriptor

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

getModuleDescriptors

public java.util.Collection<ModuleDescriptor<?>> getModuleDescriptors()
Description copied from class: AbstractPlugin
Returns a copy of the module descriptors for this plugin

Specified by:
getModuleDescriptors in interface Plugin
Overrides:
getModuleDescriptors in class AbstractPlugin
Returns:
A copy of the internal list

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
Overrides:
getModuleDescriptor in class AbstractPlugin
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> 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
Overrides:
getModuleDescriptorsByModuleClass in class AbstractPlugin
Type Parameters:
M - 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.

isEnabledByDefault

public boolean isEnabledByDefault()
Specified by:
isEnabledByDefault in interface Plugin
Overrides:
isEnabledByDefault in class AbstractPlugin

setEnabledByDefault

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

getPluginInformation

public PluginInformation getPluginInformation()
Specified by:
getPluginInformation in interface Plugin
Overrides:
getPluginInformation in class AbstractPlugin

setPluginInformation

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

setResources

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

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
Overrides:
isSystemPlugin in class AbstractPlugin
Returns:
true if this plugin is a "system" plugin.

containsSystemModule

public boolean containsSystemModule()
Specified by:
containsSystemModule in interface Plugin
Overrides:
containsSystemModule in class AbstractPlugin

setSystemPlugin

public void setSystemPlugin(boolean system)
Specified by:
setSystemPlugin in interface Plugin
Overrides:
setSystemPlugin in class AbstractPlugin

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
Overrides:
getDateLoaded in class AbstractPlugin
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'.

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?

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.

Returns:
true if this plugin is loaded dynamically at runtime.

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
Overrides:
getResourceDescriptors in class AbstractPlugin
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
Overrides:
getResourceDescriptors in class AbstractPlugin
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
Overrides:
getResourceLocation in class AbstractPlugin
Returns:
the specified resource location if found, null otherwise.

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
Overrides:
getResourceDescriptor in class AbstractPlugin
Returns:
the specified resource descriptor if found, null otherwise.

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.

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.

getResource

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

Parameters:
name - 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.

Parameters:
name - The name of the resource to be loaded.
Returns:
An InputStream for the resource, or null if the resource is not found.

uninstallInternal

protected void uninstallInternal()
Description copied from class: AbstractPlugin
Perform any internal uninstallation logic. Subclasses should only throw PluginException.

Overrides:
uninstallInternal in class AbstractPlugin

enableInternal

protected PluginState enableInternal()
Description copied from class: AbstractPlugin
Perform any internal enabling logic. Subclasses should only throw PluginException.

Overrides:
enableInternal in class AbstractPlugin
Returns:
Either PluginState.ENABLED or PluginState.ENABLING

disableInternal

protected void disableInternal()
Description copied from class: AbstractPlugin
Perform any internal disabling logic. Subclasses should only throw PluginException.

Overrides:
disableInternal in class AbstractPlugin

getClassLoader

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

Returns:
The classloader used to load classes for this plugin


Copyright © 2009 Atlassian Pty Ltd. All Rights Reserved.