View Javadoc
1   package com.atlassian.plugin.servlet.descriptors;
2   
3   import com.atlassian.plugin.Permissions;
4   import com.atlassian.plugin.Plugin;
5   import com.atlassian.plugin.PluginParseException;
6   import com.atlassian.plugin.RequirePermission;
7   import com.atlassian.plugin.descriptors.AbstractModuleDescriptor;
8   import com.atlassian.plugin.module.ModuleFactory;
9   import org.dom4j.Element;
10  import org.slf4j.Logger;
11  import org.slf4j.LoggerFactory;
12  
13  import javax.annotation.Nonnull;
14  import javax.servlet.ServletContextListener;
15  
16  /**
17   * Provides a way for plugins to declare {@link ServletContextListener}s so they can be notified when the
18   * {@link javax.servlet.ServletContext} is created for the plugin. Implementors need to extend this class and implement the
19   * {#link autowireObject} method.
20   *
21   * @since 2.1.0
22   */
23  @RequirePermission(Permissions.EXECUTE_JAVA)
24  public class ServletContextListenerModuleDescriptor extends AbstractModuleDescriptor<ServletContextListener> {
25      protected static final Logger log = LoggerFactory.getLogger(ServletContextListenerModuleDescriptor.class);
26  
27      /**
28       * @since 2.5.0
29       */
30      public ServletContextListenerModuleDescriptor(ModuleFactory moduleFactory) {
31          super(moduleFactory);
32      }
33  
34      @Override
35      public void init(@Nonnull Plugin plugin, @Nonnull Element element) throws PluginParseException {
36          super.init(plugin, element);
37          checkPermissions();
38      }
39  
40      @Override
41      public ServletContextListener getModule() {
42          return moduleFactory.createModule(moduleClassName, this);
43      }
44  
45  }