KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > config > ServletContextSingleton


1 package com.opensymphony.webwork.config;
2
3 import javax.servlet.ServletContext JavaDoc;
4
5 /**
6  * This singleton holds an instance of the web servlet context.
7  * <p/>
8  * This is needed for running WebWork on Weblogic Server 6.1
9  * because there is no provision to retrieve the servlet context
10  * from the web session object.
11  * <p/>
12  * This class is created to bet that this singleton can be set by
13  * {@link com.opensymphony.webwork.dispatcher.FilterDispatcherCompatWeblogic61}
14  * before the servlet context is needed by
15  * {@link com.opensymphony.webwork.lifecycle.SessionLifecycleListener}
16  * which will use this object to get it.
17  *
18  * @author Scott N. Smith scottnelsonsmith@yahoo.com
19  * @version $Id: ServletContextSingleton.java,v 1.2 2005/06/25 16:15:15 plightbo Exp $
20  */

21 public class ServletContextSingleton {
22     /**
23      * The web servlet context. Holding this is the
24      * purpose of this singleton.
25      */

26     private ServletContext JavaDoc servletContext;
27
28     /**
29      * The sole instance of this class.
30      */

31     private static ServletContextSingleton singleton;
32
33     /**
34      * Constructor which cannot be called
35      * publicly.
36      */

37     private ServletContextSingleton() {
38     }
39
40     /**
41      * answers the singleton.
42      * <p/>
43      * At some point, the caller must populate the web servlet
44      * context.
45      *
46      * @return answers the singleton instance of this class
47      */

48     public static ServletContextSingleton getInstance() {
49         if (singleton == null) {
50             singleton = new ServletContextSingleton();
51         }
52         return singleton;
53     }
54
55     /**
56      * @return the web servlet context
57      */

58     public ServletContext JavaDoc getServletContext() {
59         return servletContext;
60     }
61
62     /**
63      * @param context the web servlet context
64      */

65     public void setServletContext(ServletContext JavaDoc context) {
66         servletContext = context;
67     }
68
69 }
70
Popular Tags