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      private static final String SERVLET_MODULE_MANAGER_KEY = ServletContextServletModuleManagerAccessor.class.getPackage() + ".servletModuleManager";
14  
15      /**
16       * Gets the servlet module manager in the servlet context
17       *
18       * @param servletContext the servlet context to look up the servlet module manager in
19       * @return The servlet module manager instance or null if it is not there
20       */
21      public static ServletModuleManager getServletModuleManager(ServletContext servletContext) throws IllegalStateException {
22          return (ServletModuleManager) servletContext.getAttribute(SERVLET_MODULE_MANAGER_KEY);
23      }
24  
25      /**
26       * Sets the implementation of the servlet module manager
27       *
28       * @param servletContext       the servlet context to set the manager in
29       * @param servletModuleManager the implementation to set
30       */
31      public static void setServletModuleManager(ServletContext servletContext, ServletModuleManager servletModuleManager) {
32          servletContext.setAttribute(SERVLET_MODULE_MANAGER_KEY, servletModuleManager);
33      }
34  }