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