View Javadoc
1   package com.atlassian.plugin.mock;
2   
3   import com.atlassian.plugin.ModuleDescriptor;
4   import com.atlassian.plugin.Plugin;
5   import com.atlassian.plugin.PluginParseException;
6   import com.atlassian.plugin.StateAware;
7   import com.atlassian.plugin.descriptors.AbstractModuleDescriptor;
8   import com.atlassian.plugin.module.ModuleFactory;
9   import junit.framework.Assert;
10  import org.dom4j.Element;
11  
12  public class MockAnimalModuleDescriptor extends AbstractModuleDescriptor<MockAnimal> implements StateAware, ModuleDescriptor<MockAnimal> {
13      MockAnimal module;
14  
15      private final String type;
16      private final String name;
17  
18  
19      public MockAnimalModuleDescriptor() {
20          this(null, null);
21      }
22  
23      public MockAnimalModuleDescriptor(String type, String name) {
24          super(ModuleFactory.LEGACY_MODULE_FACTORY);
25          this.type = type;
26          this.name = name;
27      }
28  
29      @Override
30      public void init(final Plugin plugin, final Element element) throws PluginParseException {
31          super.init(plugin, element);
32          if (type != null && name != null) {
33              Assert.assertNotNull(plugin.getResourceDescriptor(type, name));
34          }
35      }
36  
37      @Override
38      public MockAnimal getModule() {
39          if (module == null) {
40              try {
41                  module = getModuleClass().newInstance();
42              } catch (final InstantiationException e) {
43                  throw new PluginParseException(e);
44              } catch (final IllegalAccessException e) {
45                  throw new PluginParseException(e);
46              }
47          }
48          return module;
49      }
50  }