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 public boolean disabled;
16 public boolean enabled;
17
18 private final String type;
19 private final String name;
20
21
22 public MockAnimalModuleDescriptor()
23 {
24 this(null, null);
25 }
26
27 public MockAnimalModuleDescriptor(String type, String name)
28 {
29 super(ModuleFactory.LEGACY_MODULE_FACTORY);
30 this.type = type;
31 this.name = name;
32 }
33
34 @Override
35 public void init(final Plugin plugin, final Element element) throws PluginParseException
36 {
37 super.init(plugin, element);
38 if (type != null && name != null) {
39 Assert.assertNotNull(plugin.getResourceDescriptor(type, name));
40 }
41 }
42
43 @Override
44 public MockAnimal getModule()
45 {
46 if (module == null)
47 {
48 try
49 {
50 module = getModuleClass().newInstance();
51 }
52 catch (final InstantiationException e)
53 {
54 throw new PluginParseException(e);
55 }
56 catch (final IllegalAccessException e)
57 {
58 throw new PluginParseException(e);
59 }
60 }
61 return module;
62 }
63
64 @Override
65 public void enabled()
66 {
67 super.enabled();
68 enabled = true;
69 }
70
71 @Override
72 public void disabled()
73 {
74 disabled = true;
75 super.disabled();
76 }
77
78 public boolean isEnabled()
79 {
80 return enabled && !disabled;
81 }
82 }