KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > directwebremoting > WebContextFactory


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;
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 /**
24  * Accessor for the current WebContext.
25  * @author Joe Walker [joe at getahead dot ltd dot uk]
26  */

27 public class WebContextFactory
28 {
29     /**
30      * Accessor for the current WebContext.
31      * @return The current WebContext or null if the current thread was not
32      * started by DWR.
33      */

34     public static WebContext get()
35     {
36         if (builder == null)
37         {
38             return null;
39         }
40
41         return builder.get();
42     }
43
44     /**
45      * Internal method to allow us to get the WebContextBuilder from which we
46      * will get WebContext objects.
47      * Do not call this method from outside of DWR.
48      * @param builder The factory object (from DwrServlet)
49      */

50     public static void setWebContextBuilder(WebContextBuilder builder)
51     {
52         WebContextFactory.builder = builder;
53     }
54
55     /**
56      * The WebContextBuilder from which we will get WebContext objects
57      */

58     private static WebContextBuilder builder;
59
60     /**
61      * Class to enable us to access servlet parameters.
62      */

63     public interface WebContextBuilder
64     {
65         /**
66          * Make the current thread know what the current request is.
67          * This method is only for use internally to DWR.
68          * @param request The incoming http request
69          * @param response The outgoing http reply
70          * @param config The servlet configuration
71          * @param context The servlet context
72          * @param container The IoC container
73          * @see #unset()
74          */

75         void set(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, ServletConfig JavaDoc config, ServletContext JavaDoc context, Container container);
76
77         /**
78          * @return The WebContext that is associated with this thread
79          */

80         WebContext get();
81
82         /**
83          * Unset the current ExecutionContext
84          * This method is only for use internally to DWR.
85          * @see #set(HttpServletRequest, HttpServletResponse, ServletConfig, ServletContext, Container)
86          */

87         void unset();
88     }
89 }
90
Popular Tags