1 package com.atlassian.plugin.servlet.descriptors;
2
3 import javax.servlet.http.HttpServlet;
4
5 import com.atlassian.plugin.AutowireCapablePlugin;
6 import com.atlassian.plugin.StateAware;
7 import com.atlassian.plugin.servlet.ServletModuleManager;
8
9
10
11
12
13 public abstract class ServletModuleDescriptor extends BaseServletModuleDescriptor<HttpServlet> implements StateAware
14 {
15 public void enabled()
16 {
17 super.enabled();
18 getServletModuleManager().addServletModule(this);
19 }
20
21 public void disabled()
22 {
23 getServletModuleManager().removeServletModule(this);
24 super.disabled();
25 }
26
27 public HttpServlet getModule()
28 {
29 HttpServlet obj = null;
30 try
31 {
32
33 if (plugin instanceof AutowireCapablePlugin)
34 obj = ((AutowireCapablePlugin)plugin).autowire(getModuleClass());
35 else
36 {
37 obj = getModuleClass().newInstance();
38 autowireObject(obj);
39 }
40 }
41 catch (InstantiationException e)
42 {
43 log.error("Error instantiating: " + getModuleClass(), e);
44 }
45 catch (IllegalAccessException e)
46 {
47 log.error("Error accessing: " + getModuleClass(), e);
48 }
49 return obj;
50 }
51
52
53
54
55 public HttpServlet getServlet()
56 {
57 return getModule();
58 }
59
60
61
62
63 protected abstract void autowireObject(Object obj);
64
65
66
67
68 protected abstract ServletModuleManager getServletModuleManager();
69 }