KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > directwebremoting > ServerContextFactory


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
21 /**
22  * Accessor for the current ServerContext.
23  * @author Joe Walker [joe at getahead dot ltd dot uk]
24  */

25 public class ServerContextFactory
26 {
27     /**
28      * Accessor for the current ServerContext.
29      * @param ctx The servlet context to allow us to bootstrap
30      * @return The current ServerContext.
31      */

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

48     public static void setServerContextBuilder(ServerContextBuilder builder)
49     {
50         ServerContextFactory.builder = builder;
51     }
52
53     /**
54      * The ServerContextBuilder from which we will get ServerContext objects
55      */

56     private static ServerContextBuilder builder;
57
58     /**
59      * Class to enable us to access servlet parameters.
60      */

61     public interface ServerContextBuilder
62     {
63         /**
64          * Make the current webapp know what the current config/context is.
65          * This method is only for use internally to DWR.
66          * @param config The servlet configuration
67          * @param context The servlet context
68          * @param container The IoC container
69          */

70         void set(ServletConfig JavaDoc config, ServletContext JavaDoc context, Container container);
71
72         /**
73          * Accessor for the current ServerContext
74          * @param context The web application environment
75          * @return The ServerContext that is associated with this web application
76          */

77         ServerContext get(ServletContext JavaDoc context);
78     }
79 }
80
Popular Tags