View Javadoc

1   package com.atlassian.plugin.servlet.util;
2   
3   import com.atlassian.plugin.servlet.ServletModuleManager;
4   
5   import javax.servlet.ServletContext;
6   
7   /**
8    * Provides static access to a {@link com.atlassian.plugin.hostcontainer.HostContainer} instance.  Requires initialisation before first use.
9    *
10   * @since 2.2.0
11   */
12  public class ServletContextServletModuleManagerAccessor
13  {
14      private static final String SERVLET_MODULE_MANAGER_KEY = ServletContextServletModuleManagerAccessor.class.getPackage()+".servletModuleManager";
15  
16      /**
17       * Gets the servlet module manager in the servlet context
18       *
19       * @param servletContext the servlet context to look up the servlet module manager in
20       * @return The servlet module manager instance or null if it is not there
21       */
22      public static ServletModuleManager getServletModuleManager(ServletContext servletContext) throws IllegalStateException
23      {
24          return  (ServletModuleManager) servletContext.getAttribute(SERVLET_MODULE_MANAGER_KEY);
25      }
26  
27      /**
28       * Sets the implementation of the servlet module manager
29       *
30       * @param servletContext the servlet context to set the manager in
31       * @param servletModuleManager the implementation to set
32       */
33      public static void setServletModuleManager(ServletContext servletContext, ServletModuleManager servletModuleManager)
34      {
35          servletContext.setAttribute(SERVLET_MODULE_MANAGER_KEY, servletModuleManager);
36      }
37  
38  }