1 package com.atlassian.plugin.servlet.descriptors;
2
3 import javax.servlet.ServletContextListener;
4
5 import org.apache.commons.logging.Log;
6 import org.apache.commons.logging.LogFactory;
7
8 import com.atlassian.plugin.AutowireCapablePlugin;
9 import com.atlassian.plugin.hostcontainer.HostContainer;
10 import com.atlassian.plugin.descriptors.AbstractModuleDescriptor;
11
12
13
14
15
16
17
18
19 public class ServletContextListenerModuleDescriptor extends AbstractModuleDescriptor<ServletContextListener>
20 {
21 protected static final Log log = LogFactory.getLog(ServletContextListenerModuleDescriptor.class);
22
23 protected final HostContainer hostContainer;
24
25
26
27
28 @Deprecated
29 public ServletContextListenerModuleDescriptor()
30 {
31 this(null);
32 }
33
34
35
36
37
38
39
40 public ServletContextListenerModuleDescriptor(HostContainer hostContainer)
41 {
42 this.hostContainer = hostContainer;
43 }
44
45 @Override
46 public ServletContextListener getModule()
47 {
48 ServletContextListener obj = null;
49 try
50 {
51
52 if (plugin instanceof AutowireCapablePlugin)
53 obj = ((AutowireCapablePlugin)plugin).autowire(getModuleClass());
54 else
55 {
56 if (hostContainer != null)
57 {
58 obj = hostContainer.create(getModuleClass());
59 }
60 else
61 {
62 obj = getModuleClass().newInstance();
63 autowireObject(obj);
64 }
65 }
66 }
67 catch (InstantiationException e)
68 {
69 log.error("Error instantiating: " + getModuleClass(), e);
70 }
71 catch (IllegalAccessException e)
72 {
73 log.error("Error accessing: " + getModuleClass(), e);
74 }
75 return obj;
76 }
77
78
79
80
81 @Deprecated
82 protected void autowireObject(Object obj)
83 {
84 throw new UnsupportedOperationException("This method must be overridden if a HostContainer is not used");
85 }
86
87 }