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