KickJava   Java API By Example, From Geeks To Geeks.

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


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
21 import org.directwebremoting.Container;
22 import org.directwebremoting.ServerContext;
23 import org.directwebremoting.ServerContextFactory.ServerContextBuilder;
24 import org.directwebremoting.util.Logger;
25
26 /**
27  * A ServerContextBuilder that creates DefaultServerContexts.
28  * @author Joe Walker [joe at getahead dot ltd dot uk]
29  */

30 public class DefaultServerContextBuilder implements ServerContextBuilder
31 {
32     /* (non-Javadoc)
33      * @see ServerContextBuilder#set(javax.servlet.ServletConfig, javax.servlet.ServletContext, org.directwebremoting.Container)
34      */

35     public void set(ServletConfig JavaDoc config, ServletContext JavaDoc context, Container container)
36     {
37         try
38         {
39             ServerContext ec = new DefaultServerContext(config, context, container);
40             context.setAttribute(ATTRIBUTE_SERVER_CONTEXT, ec);
41         }
42         catch (Exception JavaDoc ex)
43         {
44             log.fatal("Failed to create an ExecutionContext", ex);
45         }
46     }
47
48     /* (non-Javadoc)
49      * @see org.directwebremoting.ServerContextBuilder#get()
50      */

51     public ServerContext get(ServletContext JavaDoc context)
52     {
53         return (ServerContext) context.getAttribute(ATTRIBUTE_SERVER_CONTEXT);
54     }
55
56     /**
57      * The attribute under which we publish the ServerContext
58      */

59     private static final String JavaDoc ATTRIBUTE_SERVER_CONTEXT = "org.directwebremoting.impl.ServerContext";
60
61     /**
62      * The log stream
63      */

64     private static final Logger log = Logger.getLogger(DefaultServerContextBuilder.class);
65 }
66
Popular Tags