View Javadoc

1   package com.atlassian.plugin.servlet;
2   
3   import java.util.Collections;
4   import java.util.Enumeration;
5   
6   import javax.servlet.Servlet;
7   import javax.servlet.ServletConfig;
8   import javax.servlet.ServletContext;
9   
10  import com.atlassian.plugin.servlet.descriptors.BaseServletModuleDescriptor;
11  
12  /**
13   * Instances of the PluginServletConfig are passed to plugins servlet {@link Servlet} init() method.  It provides
14   * access to the init parameters defined in the plugin xml as well as the ServletContext shared by other filters and
15   * servlets in the plugin.
16   */
17  public final class PluginServletConfig implements ServletConfig
18  {
19      private final BaseServletModuleDescriptor<?> descriptor;
20      private final ServletContext servletContext;
21  
22      public PluginServletConfig(BaseServletModuleDescriptor<?> descriptor, ServletContext servletContext)
23      {
24          this.descriptor = descriptor;
25          this.servletContext = servletContext;
26      }
27  
28      public String getServletName()
29      {
30          return descriptor.getName();
31      }
32  
33      public ServletContext getServletContext()
34      {
35          return servletContext;
36      }
37  
38      public String getInitParameter(String s)
39      {
40          return (String) descriptor.getInitParams().get(s);
41      }
42  
43      public Enumeration getInitParameterNames()
44      {
45          return Collections.enumeration(descriptor.getInitParams().keySet());
46      }
47  }