001: /*
002: * Copyright 2005 Joe Walker
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.directwebremoting.impl;
017:
018: import java.util.Collection;
019:
020: import javax.servlet.ServletConfig;
021: import javax.servlet.ServletContext;
022:
023: import org.directwebremoting.Container;
024: import org.directwebremoting.ServerContext;
025: import org.directwebremoting.ScriptSession;
026: import org.directwebremoting.extend.ConverterManager;
027: import org.directwebremoting.extend.ScriptSessionManager;
028: import org.directwebremoting.servlet.UrlProcessor;
029: import org.directwebremoting.util.VersionUtil;
030:
031: /**
032: * The Default implementation of ServerContext
033: * @author Joe Walker [joe at getahead dot ltd dot uk]
034: */
035: public class DefaultServerContext implements ServerContext {
036: /**
037: * Build a new DefaultServerContext
038: * @param config The servlet configuration
039: * @param context The servlet context
040: * @param container The IoC container
041: */
042: public DefaultServerContext(ServletConfig config,
043: ServletContext context, Container container) {
044: this .config = config;
045: this .context = context;
046: this .container = container;
047: }
048:
049: /* (non-Javadoc)
050: * @see org.directwebremoting.ServerContext#getAllScriptSessions()
051: */
052: public Collection<ScriptSession> getAllScriptSessions() {
053: return getScriptSessionManager().getAllScriptSessions();
054: }
055:
056: /* (non-Javadoc)
057: * @see org.directwebremoting.ServerContext#getScriptSessionsByPage(java.lang.String)
058: */
059: public Collection<ScriptSession> getScriptSessionsByPage(String url) {
060: return getScriptSessionManager().getScriptSessionsByPage(url);
061: }
062:
063: /* (non-Javadoc)
064: * @see org.directwebremoting.ServerContext#getScriptSessionById(java.lang.String)
065: */
066: public ScriptSession getScriptSessionById(String sessionId) {
067: // ScriptSessionManager().getScriptSession() can take a page and
068: // httpSessionId so it can associate them, but we will have already done
069: // that if we can as a result of work done creating a WebContext. For
070: // use in a ServerContext we won't know, so we can pass in null
071: return getScriptSessionManager().getScriptSession(sessionId,
072: null, null);
073: }
074:
075: /* (non-Javadoc)
076: * @see org.directwebremoting.ServerContext#getContainer()
077: */
078: public Container getContainer() {
079: return container;
080: }
081:
082: /* (non-Javadoc)
083: * @see org.directwebremoting.ServerContext#getServletConfig()
084: */
085: public ServletConfig getServletConfig() {
086: return config;
087: }
088:
089: /* (non-Javadoc)
090: * @see org.directwebremoting.ServerContext#getServletContext()
091: */
092: public ServletContext getServletContext() {
093: return context;
094: }
095:
096: /* (non-Javadoc)
097: * @see org.directwebremoting.WebContext#getVersion()
098: */
099: public String getVersion() {
100: return VersionUtil.getLabel();
101: }
102:
103: /* (non-Javadoc)
104: * @see org.directwebremoting.ServerContext#getContextPath()
105: */
106: public String getContextPath() {
107: UrlProcessor urlProcessor = container
108: .getBean(UrlProcessor.class);
109: return urlProcessor.getContextPath();
110: }
111:
112: /**
113: * Internal helper for getting at a ScriptSessionManager
114: * @return Our ScriptSessionManager
115: */
116: protected ScriptSessionManager getScriptSessionManager() {
117: if (sessionManager == null) {
118: sessionManager = container
119: .getBean(ScriptSessionManager.class);
120: }
121:
122: return sessionManager;
123: }
124:
125: /**
126: * Internal helper for getting at a ConverterManager
127: * @return Our ConverterManager
128: */
129: protected ConverterManager getConverterManager() {
130: if (converterManager == null) {
131: converterManager = container
132: .getBean(ConverterManager.class);
133: }
134:
135: return converterManager;
136: }
137:
138: /**
139: * The ServletConfig associated with the current request
140: */
141: private ServletConfig config = null;
142:
143: /**
144: * The ServletContext associated with the current request
145: */
146: private ServletContext context = null;
147:
148: /**
149: * The IOC container implementation
150: */
151: private Container container = null;
152:
153: /**
154: * The session manager for sessions keyed off script ids
155: */
156: private ScriptSessionManager sessionManager = null;
157:
158: /**
159: * How we convert to Javascript objects
160: */
161: private ConverterManager converterManager = null;
162: }
|