public abstract class AbstractModuleDescriptor<T> extends Object implements ModuleDescriptor<T>, StateAware
| Modifier and Type | Field and Description |
|---|---|
protected String |
key |
protected Class<T> |
moduleClass |
protected String |
moduleClassName |
protected ModuleFactory |
moduleFactory |
protected String |
name |
protected Plugin |
plugin |
protected Resources |
resources |
| Constructor and Description |
|---|
AbstractModuleDescriptor(ModuleFactory moduleFactory) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
assertModuleClassImplements(Class<T> requiredModuleClazz)
Check that the module class of this descriptor implements a given
interface, or extends a given class.
|
protected void |
checkPermissions()
This is a method that module should call (in their
init method implementation to
check that permissions are correctly set on the plugin. |
void |
destroy()
The default implementation disables the module if it's still enabled, and unreference the plugin.
|
void |
disabled()
Disables the module descriptor.
|
void |
enabled()
Enables the descriptor by loading the module class.
|
boolean |
equals(Object obj)
Compares the specified object with this module descriptor for equality.
|
String |
getCompleteKey()
The complete key for this module, including the plugin key.
|
String |
getDescription()
A simple description of this descriptor.
|
String |
getDescriptionKey()
Key used to override
ModuleDescriptor.getDescription() when using
internationalisation. |
String |
getI18nNameKey()
Key used to override
ModuleDescriptor.getName() when using internationalisation. |
String |
getKey()
The key for this module, unique within the plugin.
|
Float |
getMinJavaVersion() |
abstract T |
getModule()
The particular module object created by this plugin.
|
Class<T> |
getModuleClass()
The class of the module this descriptor creates.
|
protected String |
getModuleClassName() |
String |
getName()
A simple string name for this descriptor.
|
Map<String,String> |
getParams() |
Plugin |
getPlugin() |
String |
getPluginKey()
The plugin key for this module, derived from the complete key.
|
protected Set<String> |
getRequiredPermissions()
The set of additionally required permissions.
|
ResourceDescriptor |
getResourceDescriptor(String type,
String name)
Get a
ResourceDescriptor of a particular type and name. |
List<ResourceDescriptor> |
getResourceDescriptors()
Get a
List of all the descriptors
. |
ResourceLocation |
getResourceLocation(String type,
String name)
Get a
ResourceLocation of a particular type and name. |
Optional<String> |
getScopeKey() |
int |
hashCode()
Returns the hash code value for this module descriptor.
|
void |
init(Plugin plugin,
org.dom4j.Element element)
Initialise a module given it's parent plugin and the XML element
representing the module.
|
boolean |
isBroken()
Returns true if this Module is "broken".
|
boolean |
isEnabled()
Get whether this plugin module is enabled.
|
boolean |
isEnabledByDefault()
Whether or not this plugin module is enabled by default.
|
boolean |
isSystemModule()
Whether or not this plugin module is a "system" module that shouldn't be
made visible/disable-able to the user.
|
protected void |
loadClass(Plugin plugin,
String clazz)
Loads the module class that this descriptor provides, and will not
necessarily be the implementation class.
|
protected void |
provideValidationRules(ValidationPattern pattern)
Provides validation rules for the pattern
|
boolean |
satisfiesMinJavaVersion()
If a min java version has been specified this will return true if the
running jvm is >= to the specified version.
|
void |
setBroken()
Changes state to "broken"
|
void |
setPlugin(Plugin plugin)
Sets the plugin for the ModuleDescriptor
|
String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, waitgetDisplayNameprotected Plugin plugin
protected String key
protected String name
protected String moduleClassName
protected Resources resources
protected final ModuleFactory moduleFactory
public AbstractModuleDescriptor(ModuleFactory moduleFactory)
public void init(@Nonnull Plugin plugin, @Nonnull org.dom4j.Element element) throws PluginParseException
ModuleDescriptor
Since atlassian-plugins v2.2, you can no longer load classes from the
plugin in this method, because the OSGi bundle that they will live in is
not built yet. Load classes in the StateAware.enabled()
method instead.
init in interface ModuleDescriptor<T>plugin - The plugin that the module belongs to. Must not be null.element - XML element representing the module. Must not be null.PluginParseException - Can be thrown if an error occurs while
parsing the XML element.protected final void checkPermissions()
throws ModulePermissionException
init method implementation to
check that permissions are correctly set on the plugin. Use the RequirePermission annotation to add
permissions to a module, and/or getRequiredPermissions() if you need more dynamic permissions.
If either all permissions are allowed or this is a system module, we don't bother to check permissionsModulePermissionException - if the plugin doesn't require the necessary permissions for the module to work.RequirePermission,
getRequiredPermissions()protected Set<String> getRequiredPermissions()
The set of additionally required permissions. This is useful for dynamic permissions depending on module
configuration. One might prefer the RequirePermission annotation otherwise for 'static' permissions.
Default implementation returns an empty set
RequirePermission,
checkPermissions()protected void provideValidationRules(ValidationPattern pattern)
pattern - The validation patternprotected void loadClass(Plugin plugin, String clazz) throws PluginParseException
clazz - The module class name to loadIllegalStateException - If the module class cannot be determined
and the descriptor doesn't define a module type via genericsPluginParseExceptionpublic void destroy()
destroy in interface ModuleDescriptor<T>public boolean isEnabledByDefault()
ModuleDescriptorisEnabledByDefault in interface ModuleDescriptor<T>true if this plugin module is enabled by default.public boolean isSystemModule()
ModuleDescriptorisSystemModule in interface ModuleDescriptor<T>true if this plugin module is a "system" plugin that
shouldn't be made visible/disable-able to the user.protected final void assertModuleClassImplements(Class<T> requiredModuleClazz) throws PluginParseException
requiredModuleClazz - The class this module's class must implement
or extend.PluginParseException - If the module class does not implement or
extend the given class.public String getCompleteKey()
ModuleDescriptorFormat is plugin.key:module.key
getCompleteKey in interface ModuleDescriptor<T>ModuleDescriptor.getKey(),
ModuleDescriptor.getPluginKey()public String getPluginKey()
ModuleDescriptorgetPluginKey in interface ModuleDescriptor<T>ModuleDescriptor.getKey(),
ModuleDescriptor.getCompleteKey()public String getKey()
ModuleDescriptorgetKey in interface ModuleDescriptor<T>ModuleDescriptor.getCompleteKey(),
ModuleDescriptor.getPluginKey()public String getName()
ModuleDescriptorgetName in interface ModuleDescriptor<T>public Class<T> getModuleClass()
ModuleDescriptorgetModuleClass in interface ModuleDescriptor<T>ModuleDescriptor.getModule()public abstract T getModule()
ModuleDescriptorgetModule in interface ModuleDescriptor<T>ModuleDescriptor.getModuleClass()public Optional<String> getScopeKey()
getScopeKey in interface ScopeAwareOptional.empty() if not definedpublic String getDescription()
ModuleDescriptorgetDescription in interface ModuleDescriptor<T>public Map<String,String> getParams()
getParams in interface ModuleDescriptor<T>public String getI18nNameKey()
ModuleDescriptorModuleDescriptor.getName() when using internationalisation.getI18nNameKey in interface ModuleDescriptor<T>public String getDescriptionKey()
ModuleDescriptorModuleDescriptor.getDescription() when using
internationalisation.getDescriptionKey in interface ModuleDescriptor<T>public List<ResourceDescriptor> getResourceDescriptors()
ResourcedList of all the descriptors
.
Note: since 2.2 this list must be immutable, previously modifying this list could modify the underlying list.
getResourceDescriptors in interface Resourcedpublic ResourceLocation getResourceLocation(String type, String name)
ResourcedResourceLocation of a particular type and name.getResourceLocation in interface Resourcedpublic ResourceDescriptor getResourceDescriptor(String type, String name)
ResourcedResourceDescriptor of a particular type and name.getResourceDescriptor in interface Resourcedpublic Float getMinJavaVersion()
getMinJavaVersion in interface ModuleDescriptor<T>public boolean satisfiesMinJavaVersion()
ModuleDescriptorsatisfiesMinJavaVersion in interface ModuleDescriptor<T>public void setPlugin(Plugin plugin)
plugin - The plugin to set for this descriptor.public Plugin getPlugin()
getPlugin in interface ModuleDescriptor<T>public boolean equals(Object obj)
ModuleDescriptor
Returns true if the given object is also a module descriptor and the two descriptors have the same
"complete key" as determined by ModuleDescriptor.getCompleteKey().
This ensures that the equals method works properly across different implementations of the ModuleDescriptor interface.
equals in interface ModuleDescriptor<T>equals in class Objectobj - object to be compared for equality with this module descriptor.public int hashCode()
ModuleDescriptor
getCompleteKey() == null ? 0 : getCompleteKey().hashCode()
This ensures that d1.equals(d2) implies that
d1.hashCode()==d2.hashCode() for any two Module Descriptors
d1 and d2, as required by the general
contract of Object.hashCode.hashCode in interface ModuleDescriptor<T>hashCode in class ObjectObject.hashCode(),
Object.equals(Object),
ModuleDescriptor.equals(Object)public void enabled()
enabled in interface StateAwarepublic void disabled()
disabled in interface StateAwareprotected String getModuleClassName()
public boolean isEnabled()
isEnabled in interface ModuleDescriptor<T>public void setBroken()
ModuleDescriptor
Being breakable is something subclasses can opt in to, therefore by default ModuleDescriptors
are unbreakable, this is a no-op, and ModuleDescriptor.isBroken() returns false
setBroken in interface ModuleDescriptor<T>public boolean isBroken()
ModuleDescriptor
A "broken" module means that even though this ModuleDescriptor is enabled, calling getModule() results
in an error. This typically occurs when the plugin version is not compatible with the version of the host product.
Note that some modules are lazy-loaded, and so this method is optimistic: it will return false until we discover that the Module is not loadable.
isBroken in interface ModuleDescriptor<T>true if broken, false otherwiseCopyright © 2019 Atlassian. All rights reserved.