1 package com.atlassian.plugin;
2
3 import com.atlassian.util.concurrent.NotNull;
4 import org.dom4j.Element;
5
6 import java.util.Map;
7 import java.util.Set;
8
9 public interface ModuleDescriptor<T> extends Resourced
10 {
11 /**
12 * The complete key for this module, including the plugin key.
13 * <p>
14 * Format is plugin.key:module.key
15 * </p>
16 *
17 * @return The complete key for this module.
18 * @see #getKey()
19 * @see #getPluginKey()
20 */
21 String getCompleteKey();
22
23 /**
24 * The plugin key for this module, derived from the complete key.
25 *
26 * @return The plugin key for this module.
27 * @see #getKey()
28 * @see #getCompleteKey()
29 */
30 String getPluginKey();
31
32 /**
33 * The key for this module, unique within the plugin.
34 *
35 * @return The key for this module.
36 * @see #getCompleteKey()
37 * @see #getPluginKey()
38 */
39 String getKey();
40
41 /**
42 * A simple string name for this descriptor.
43 *
44 * @return The name for this ModuleDescriptor.
45 */
46 String getName();
47
48 /**
49 * A simple description of this descriptor.
50 *
51 * @return The description for this ModuleDescriptor.
52 */
53 String getDescription();
54
55 /**
56 * The class of the module this descriptor creates.
57 *
58 * @return The class of the module this descriptor creates.
59 * @see #getModule()
60 */
61 Class<T> getModuleClass();
62
63 /**
64 * The particular module object created by this plugin.
65 *
66 * @return The module object created by this plugin.
67 * @see #getModuleClass()
68 */
69 T getModule();
70
71 /**
72 * Initialise a module given it's parent plugin and the XML element
73 * representing the module.
74 * <p>
75 * Since atlassian-plugins v2.2, you can no longer load classes from the
76 * plugin in this method, because the OSGi bundle that they will live in is
77 * not built yet. Load classes in the
78 * {@link com.atlassian.plugin.descriptors.AbstractModuleDescriptor#enabled()}
79 * method instead.
80 *
81 * @param plugin The plugin that the module belongs to. Must not be null.
82 * @param element XML element representing the module. Must not be null.
83 * @throws PluginParseException Can be thrown if an error occurs while
84 * parsing the XML element.
85 */
86 void init(@NotNull Plugin plugin, @NotNull Element element) throws PluginParseException;
87
88 /**
89 * Whether or not this plugin module is enabled by default.
90 *
91 * @return {@code true} if this plugin module is enabled by default.
92 */
93 boolean isEnabledByDefault();
94
95 /**
96 * Whether or not this plugin module is a "system" plugin that shouldn't be
97 * made visible/disableable to the user.
98 *
99 * @return {@code true} if this plugin module is a "system" plugin that
100 * shouldn't be made visible/disableable to the user.
101 */
102 boolean isSystemModule();
103
104 /**
105 * Override this if your plugin needs to clean up when it's been removed.
106 *
107 * @param plugin TODO: The plugin parameter is redundant. The
108 * ModuleDescriptor must know its parent plugin in order to
109 * implement getPlugin()
110 */
111 void destroy(Plugin plugin);
112
113 Float getMinJavaVersion();
114
115 /**
116 * If a min java version has been specified this will return true if the
117 * running jvm is >= to the specified version. If this is not set then it is
118 * treated as not having a preference.
119 *
120 * @return true if satisfied, false otherwise.
121 */
122 boolean satisfiesMinJavaVersion();
123
124 Map<String, String> getParams();
125
126 /**
127 * Key used to override {@link #getName()} when using internationalisation.
128 *
129 * @return the i18n key. May be null.
130 */
131 String getI18nNameKey();
132
133 /**
134 * Key used to override {@link #getDescription()} when using
135 * internationalisation.
136 *
137 * @return the i18n key. May be null.
138 */
139 String getDescriptionKey();
140
141 /**
142 * @return The plugin this module descriptor is associated with
143 */
144 Plugin getPlugin();
145
146 /**
147 * <p>Compares the specified object with this module descriptor for equality.</p>
148 *
149 * <p>Returns <tt>true</tt> if the given object is also a module descriptor and the two descriptors have the same
150 * "complete key" as determined by {@link #getCompleteKey()}.</p>
151 *
152 * This ensures that the <tt>equals</tt> method works properly across
153 * different implementations of the <tt>ModuleDescriptor</tt> interface.
154 *
155 * @param obj object to be compared for equality with this module descriptor.
156 * @return <tt>true</tt> if the specified object is equal to this module descriptor.
157 * @since 2.8.0
158 */
159 boolean equals(Object obj);
160
161 /**
162 * Returns the hash code value for this module descriptor. The hash code
163 * of a module descriptor <tt>d</tt> is defined to be: <pre>
164 * getCompleteKey() == null ? 0 : getCompleteKey().hashCode()
165 * </pre>
166 * This ensures that <tt>d1.equals(d2)</tt> implies that
167 * <tt>d1.hashCode()==d2.hashCode()</tt> for any two Module Descriptors
168 * <tt>d1</tt> and <tt>d2</tt>, as required by the general
169 * contract of <tt>Object.hashCode</tt>.
170 *
171 * @return the hash code value for this module descriptor.
172 * @see Object#hashCode()
173 * @see Object#equals(Object)
174 * @see #equals(Object)
175 * @since 2.8.0
176 */
177 int hashCode();
178 }