KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > directwebremoting > impl > DefaultServerContext


1 /*
2  * Copyright 2005 Joe Walker
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.directwebremoting.impl;
17
18 import java.util.Collection JavaDoc;
19
20 import javax.servlet.ServletConfig JavaDoc;
21 import javax.servlet.ServletContext JavaDoc;
22
23 import org.directwebremoting.Container;
24 import org.directwebremoting.ServerContext;
25 import org.directwebremoting.extend.ConverterManager;
26 import org.directwebremoting.extend.ScriptSessionManager;
27 import org.directwebremoting.util.VersionUtil;
28
29 /**
30  * The Default implementation of ServerContext
31  * @author Joe Walker [joe at getahead dot ltd dot uk]
32  */

33 public class DefaultServerContext implements ServerContext
34 {
35     /**
36      * Build a new DefaultServerContext
37      * @param config The servlet configuration
38      * @param context The servlet context
39      * @param container The IoC container
40      */

41     public DefaultServerContext(ServletConfig JavaDoc config, ServletContext JavaDoc context, Container container)
42     {
43         this.config = config;
44         this.context = context;
45         this.container = container;
46     }
47
48     /* (non-Javadoc)
49      * @see org.directwebremoting.ServerContext#getAllScriptSessions()
50      */

51     public Collection JavaDoc getAllScriptSessions()
52     {
53         return getScriptSessionManager().getAllScriptSessions();
54     }
55
56     /* (non-Javadoc)
57      * @see org.directwebremoting.ServerContext#getContainer()
58      */

59     public Container getContainer()
60     {
61         return container;
62     }
63
64     /* (non-Javadoc)
65      * @see org.directwebremoting.ServerContext#getScriptSessionsByPage(java.lang.String)
66      */

67     public Collection JavaDoc getScriptSessionsByPage(String JavaDoc otherPage)
68     {
69         return getScriptSessionManager().getScriptSessionsByPage(otherPage);
70     }
71
72     /* (non-Javadoc)
73      * @see org.directwebremoting.ServerContext#getServletConfig()
74      */

75     public ServletConfig JavaDoc getServletConfig()
76     {
77         return config;
78     }
79
80     /* (non-Javadoc)
81      * @see org.directwebremoting.ServerContext#getServletContext()
82      */

83     public ServletContext JavaDoc getServletContext()
84     {
85         return context;
86     }
87
88     /* (non-Javadoc)
89      * @see org.directwebremoting.WebContext#getVersion()
90      */

91     public String JavaDoc getVersion()
92     {
93         return VersionUtil.getVersion();
94     }
95
96     /**
97      * Internal helper for getting at a ScriptSessionManager
98      * @return Our ScriptSessionManager
99      */

100     protected ScriptSessionManager getScriptSessionManager()
101     {
102         if (sessionManager == null)
103         {
104             sessionManager = (ScriptSessionManager) container.getBean(ScriptSessionManager.class.getName());
105         }
106
107         return sessionManager;
108     }
109
110     /**
111      * Internal helper for getting at a ConverterManager
112      * @return Our ConverterManager
113      */

114     protected ConverterManager getConverterManager()
115     {
116         if (converterManager == null)
117         {
118             converterManager = (ConverterManager) container.getBean(ConverterManager.class.getName());
119         }
120
121         return converterManager;
122     }
123
124     /**
125      * The ServletConfig associated with the current request
126      */

127     private ServletConfig JavaDoc config = null;
128
129     /**
130      * The ServletContext associated with the current request
131      */

132     private ServletContext JavaDoc context = null;
133
134     /**
135      * The Ioc container implementation
136      */

137     private Container container = null;
138
139     /**
140      * The session manager for sessions keyed off script ids
141      */

142     private ScriptSessionManager sessionManager = null;
143
144     /**
145      * How we convert to Javascript objects
146      */

147     private ConverterManager converterManager = null;
148 }
149
Popular Tags