1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.struts2.config;
19
20 import javax.servlet.ServletContext;
21
22 /***
23 * This singleton holds an instance of the web servlet context.
24 * <p/>
25 * This is needed for running Struts on Weblogic Server 6.1
26 * because there is no provision to retrieve the servlet context
27 * from the web session object.
28 * <p/>
29 * This class is created to bet that this singleton can be set by
30 * {@link org.apache.struts2.dispatcher.FilterDispatcherCompatWeblogic61}
31 * before the servlet context is needed by
32 * {@link org.apache.struts2.lifecycle.SessionLifecycleListener}
33 * which will use this object to get it.
34 *
35 */
36 public class ServletContextSingleton {
37 /***
38 * The web servlet context. Holding this is the
39 * purpose of this singleton.
40 */
41 private ServletContext servletContext;
42
43 /***
44 * The sole instance of this class.
45 */
46 private static ServletContextSingleton singleton;
47
48 /***
49 * Constructor which cannot be called
50 * publicly.
51 */
52 private ServletContextSingleton() {
53 }
54
55 /***
56 * Answers the singleton.
57 * <p/>
58 * At some point, the caller must populate the web servlet
59 * context.
60 *
61 * @return Answers the singleton instance of this class
62 */
63 public static ServletContextSingleton getInstance() {
64 if (singleton == null) {
65 singleton = new ServletContextSingleton();
66 }
67 return singleton;
68 }
69
70 /***
71 * Gets the servlet context
72 *
73 * @return The web servlet context
74 */
75 public ServletContext getServletContext() {
76 return servletContext;
77 }
78
79 /***
80 * Sets the servlet context
81 *
82 * @param context The web servlet context
83 */
84 public void setServletContext(ServletContext context) {
85 servletContext = context;
86 }
87
88 }