1
2
3
4
5
6 package com.hack23.cia.web.common;
7
8 import javax.servlet.ServletContextEvent;
9
10 import org.springframework.web.context.ContextLoaderListener;
11 import org.springframework.web.context.WebApplicationContext;
12 import org.springframework.web.context.support.WebApplicationContextUtils;
13
14 /***
15 * The listener interface for receiving staticContextLoader events.
16 * The class that is interested in processing a staticContextLoader
17 * event implements this interface, and the object created
18 * with that class is registered with a component using the
19 * component's <code>addStaticContextLoaderListener<code> method. When
20 * the staticContextLoader event occurs, that object's appropriate
21 * method is invoked.
22 *
23 * @see StaticContextLoaderEvent
24 */
25 public class StaticContextLoaderListener extends ContextLoaderListener {
26
27 /*** The web app ctx. */
28 private static WebApplicationContext webAppCtx = null;
29
30 /***
31 * Gets the web application context.
32 *
33 * @return the web application context
34 */
35 protected static WebApplicationContext getWebApplicationContext() {
36 return webAppCtx;
37 }
38
39 /***
40 * Instantiates a new static context loader listener.
41 */
42 public StaticContextLoaderListener() {
43 super();
44 }
45
46
47
48
49
50
51
52
53 @Override
54 public final void contextDestroyed(final ServletContextEvent event) {
55 super.contextDestroyed(event);
56 StaticContextLoaderListener.webAppCtx = null;
57 }
58
59
60
61
62
63
64
65
66 @Override
67 public final void contextInitialized(final ServletContextEvent event) {
68 super.contextInitialized(event);
69 StaticContextLoaderListener.webAppCtx = WebApplicationContextUtils
70 .getRequiredWebApplicationContext(event.getServletContext());
71 }
72 }