01: /*
02: * Copyright 2005 Joe Walker
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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 javax.servlet.ServletConfig;
19: import javax.servlet.ServletContext;
20: import javax.servlet.http.HttpServletRequest;
21: import javax.servlet.http.HttpServletResponse;
22:
23: import org.apache.commons.logging.LogFactory;
24: import org.apache.commons.logging.Log;
25: import org.directwebremoting.Container;
26: import org.directwebremoting.WebContext;
27: import org.directwebremoting.WebContextFactory.WebContextBuilder;
28:
29: /**
30: * A WebContextBuilder that creates DefaultWebContexts.
31: * @author Joe Walker [joe at getahead dot ltd dot uk]
32: */
33: public class DefaultWebContextBuilder implements WebContextBuilder {
34: /* (non-Javadoc)
35: * @see org.directwebremoting.WebContextBuilder#set(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, javax.servlet.ServletConfig, javax.servlet.ServletContext, org.directwebremoting.Container)
36: */
37: public void set(HttpServletRequest request,
38: HttpServletResponse response, ServletConfig config,
39: ServletContext context, Container container) {
40: try {
41: WebContext ec = new DefaultWebContext(request, response,
42: config, context, container);
43: user.set(ec);
44: } catch (Exception ex) {
45: log.fatal("Failed to create an ExecutionContext", ex);
46: }
47: }
48:
49: /* (non-Javadoc)
50: * @see org.directwebremoting.WebContextBuilder#get()
51: */
52: public WebContext get() {
53: return user.get();
54: }
55:
56: /* (non-Javadoc)
57: * @see org.directwebremoting.WebContextBuilder#unset()
58: */
59: public void unset() {
60: user.set(null);
61: }
62:
63: /**
64: * The storage of thread based data
65: */
66: private static ThreadLocal<WebContext> user = new ThreadLocal<WebContext>();
67:
68: /**
69: * The log stream
70: */
71: private static final Log log = LogFactory
72: .getLog(DefaultWebContextBuilder.class);
73: }
|