01: /*
02: * $Id: ServletContextSingleton.java 471756 2006-11-06 15:01:43Z husted $
03: *
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
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: }
|