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  {
14      MockAnimal module;
15  
16      private final String type;
17      private final String name;
18      
19  
20      public MockAnimalModuleDescriptor()
21      {
22        this(null, null);
23      }
24      
25      public MockAnimalModuleDescriptor(String type, String name)
26      {
27        super(ModuleFactory.LEGACY_MODULE_FACTORY);
28        this.type = type;
29        this.name = name;
30      }
31  
32      @Override
33      public void init(final Plugin plugin, final Element element) throws PluginParseException
34      {
35          super.init(plugin, element);
36          if (type != null && name != null) {
37            Assert.assertNotNull(plugin.getResourceDescriptor(type, name));
38          }
39      }
40  
41      @Override
42      public MockAnimal getModule()
43      {
44          if (module == null)
45          {
46              try
47              {
48                  module = getModuleClass().newInstance();
49              }
50              catch (final InstantiationException e)
51              {
52                  throw new PluginParseException(e);
53              }
54              catch (final IllegalAccessException e)
55              {
56                  throw new PluginParseException(e);
57              }
58          }
59          return module;
60      }
61  }