View Javadoc

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   * A module descriptor that allows plugin developers to define servlets. Developers can define what urls the 
11   * servlet should be serve by defining one or more <url-pattern> elements.
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              // Give the plugin a go first
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       * @deprecated Since 2.0.0, use {@link #getModule}
54       */
55      public HttpServlet getServlet()
56      {
57          return getModule();
58      }
59  
60      /**
61       * Autowire an object. Implement this in your IoC framework or simply do nothing.
62       */
63      protected abstract void autowireObject(Object obj);
64  
65      /**
66       * Retrieve the DefaultServletModuleManager class from your container framework.
67       */
68      protected abstract ServletModuleManager getServletModuleManager();
69  }