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