KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.servlet.ServletConfig JavaDoc;
19 import javax.servlet.ServletContext JavaDoc;
20 import javax.servlet.http.HttpServletRequest JavaDoc;
21 import javax.servlet.http.HttpServletResponse JavaDoc;
22
23 import org.directwebremoting.Container;
24 import org.directwebremoting.WebContext;
25 import org.directwebremoting.WebContextFactory.WebContextBuilder;
26 import org.directwebremoting.util.Logger;
27
28 /**
29  * A WebContextBuilder that creates DefaultWebContexts.
30  * @author Joe Walker [joe at getahead dot ltd dot uk]
31  */

32 public class DefaultWebContextBuilder implements WebContextBuilder
33 {
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 JavaDoc request, HttpServletResponse JavaDoc response, ServletConfig JavaDoc config, ServletContext JavaDoc context, Container container)
38     {
39         try
40         {
41             WebContext ec = new DefaultWebContext(request, response, config, context, container);
42             user.set(ec);
43         }
44         catch (Exception JavaDoc ex)
45         {
46             log.fatal("Failed to create an ExecutionContext", ex);
47         }
48     }
49
50     /* (non-Javadoc)
51      * @see org.directwebremoting.WebContextBuilder#get()
52      */

53     public WebContext get()
54     {
55         return (WebContext) user.get();
56     }
57
58     /* (non-Javadoc)
59      * @see org.directwebremoting.WebContextBuilder#unset()
60      */

61     public void unset()
62     {
63         user.set(null);
64     }
65
66     /**
67      * The storage of thread based data
68      */

69     private static ThreadLocal JavaDoc user = new ThreadLocal JavaDoc();
70
71     /**
72      * The log stream
73      */

74     private static final Logger log = Logger.getLogger(DefaultWebContextBuilder.class);
75 }
76
Popular Tags