View Javadoc

1   /*
2   Copyright 2010 James Pether Sörling Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 
3   	$Id
4   */
5   package org.directdemocracyportal.democracy.web;
6   
7   import javax.servlet.ServletContextEvent;
8   
9   import org.springframework.web.context.ContextLoaderListener;
10  import org.springframework.web.context.WebApplicationContext;
11  import org.springframework.web.context.support.WebApplicationContextUtils;
12  
13  /***
14   * The listener interface for receiving staticContextLoader events.
15   * The class that is interested in processing a staticContextLoader
16   * event implements this interface, and the object created
17   * with that class is registered with a component using the
18   * component's <code>addStaticContextLoaderListener<code> method. When
19   * the staticContextLoader event occurs, that object's appropriate
20   * method is invoked.
21   *
22   * @see StaticContextLoaderEvent
23   */
24  public class StaticContextLoaderListener extends ContextLoaderListener
25  {
26  
27      /*** The web app ctx. */
28      private static WebApplicationContext webAppCtx = null;
29  
30      /*
31       * (non-Javadoc)
32       *
33       * @see org.springframework.web.context.ContextLoaderListener#contextInitialized(javax.servlet.ServletContextEvent)
34       */
35      @Override
36      public void contextInitialized(ServletContextEvent event) {
37          super.contextInitialized(event);
38          webAppCtx = WebApplicationContextUtils
39                  .getRequiredWebApplicationContext(event.getServletContext());
40      }
41  
42      /*
43       * (non-Javadoc)
44       *
45       * @see org.springframework.web.context.ContextLoaderListener#contextDestroyed(javax.servlet.ServletContextEvent)
46       */
47      @Override
48      public void contextDestroyed(ServletContextEvent event) {
49          webAppCtx = null;
50          super.contextDestroyed(event);
51      }
52  
53      /***
54       * Gets the web application context.
55       *
56       * @return the web application context
57       */
58      public static WebApplicationContext getWebApplicationContext() {
59          return webAppCtx;
60      }
61  }