View Javadoc

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   * The web panel renderer module is used to add web panel renderers to the
15   * plugin system.
16   *
17   * @since   2.5.0
18   */
19  public class WebPanelRendererModuleDescriptor extends AbstractModuleDescriptor<WebPanelRenderer>
20  {
21      /**
22       * Host applications should use this string when registering the
23       * {@link WebPanelRendererModuleDescriptor}.
24       */
25      public static final String XML_ELEMENT_NAME = "web-panel-renderer";
26      private WebPanelRenderer rendererModule;
27  
28      public WebPanelRendererModuleDescriptor(ModuleFactory moduleClassFactory)
29      {
30          super(moduleClassFactory);
31      }
32  
33      @Override
34      public void init(Plugin plugin, Element element) throws PluginParseException
35      {
36          super.init(plugin, element);
37      }
38  
39      @Override
40      protected void provideValidationRules(ValidationPattern pattern)
41      {
42          super.provideValidationRules(pattern);
43          pattern.
44                  rule(
45                      test("@class").withError("The class is required"));
46      }
47  
48      @Override
49      public void enabled()
50      {
51          super.enabled();
52          if (!(WebPanelRenderer.class.isAssignableFrom(getModuleClass())))
53          {
54              throw new PluginParseException(String.format(
55                      "Supplied module class (%s) is not a %s", getModuleClass().getName(), WebPanelRenderer.class.getName()));
56          }
57      }
58  
59      @Override
60      public WebPanelRenderer getModule()
61      {
62          if (rendererModule == null) {
63              rendererModule = moduleFactory.createModule(moduleClassName, this);
64          }
65          return rendererModule;
66      }
67  }