1 package com.atlassian.plugin.web.descriptors;
2
3 import com.atlassian.plugin.Plugin;
4 import com.atlassian.plugin.PluginParseException;
5 import com.atlassian.plugin.descriptors.AbstractModuleDescriptor;
6 import com.atlassian.plugin.module.ModuleFactory;
7 import com.atlassian.plugin.util.validation.ValidationPattern;
8 import com.atlassian.plugin.web.renderer.WebPanelRenderer;
9 import org.dom4j.Element;
10
11 import static com.atlassian.plugin.util.validation.ValidationPattern.test;
12
13
14
15
16
17
18
19 public class WebPanelRendererModuleDescriptor extends AbstractModuleDescriptor<WebPanelRenderer> {
20
21
22
23
24 public static final String XML_ELEMENT_NAME = "web-panel-renderer";
25 private WebPanelRenderer rendererModule;
26
27 public WebPanelRendererModuleDescriptor(ModuleFactory moduleClassFactory) {
28 super(moduleClassFactory);
29 }
30
31 @Override
32 public void init(Plugin plugin, Element element) throws PluginParseException {
33 super.init(plugin, element);
34 }
35
36 @Override
37 protected void provideValidationRules(ValidationPattern pattern) {
38 super.provideValidationRules(pattern);
39 pattern.
40 rule(
41 test("@class").withError("The class is required"));
42 }
43
44 @Override
45 public void enabled() {
46 super.enabled();
47 if (!(WebPanelRenderer.class.isAssignableFrom(getModuleClass()))) {
48 throw new PluginParseException(String.format(
49 "Supplied module class (%s) is not a %s", getModuleClass().getName(), WebPanelRenderer.class.getName()));
50 }
51 }
52
53 @Override
54 public WebPanelRenderer getModule() {
55 if (rendererModule == null) {
56 rendererModule = moduleFactory.createModule(moduleClassName, this);
57 }
58 return rendererModule;
59 }
60 }