KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > directwebremoting > convert > ServletConverter


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.convert;
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 import javax.servlet.http.HttpSession JavaDoc;
23
24 import org.directwebremoting.WebContext;
25 import org.directwebremoting.WebContextFactory;
26 import org.directwebremoting.dwrp.SimpleOutboundVariable;
27 import org.directwebremoting.extend.Converter;
28 import org.directwebremoting.extend.InboundContext;
29 import org.directwebremoting.extend.InboundVariable;
30 import org.directwebremoting.extend.OutboundContext;
31 import org.directwebremoting.extend.OutboundVariable;
32
33 /**
34  * A converter that magics up HTTP objects
35  * @author Joe Walker [joe at eireneh dot com]
36  * @version $Id: StringConverter.java,v 1.2 2004/11/04 15:54:07 joe_walker Exp $
37  */

38 public class ServletConverter extends BaseV20Converter implements Converter
39 {
40     /* (non-Javadoc)
41      * @see org.directwebremoting.Converter#convertInbound(java.lang.Class, org.directwebremoting.InboundVariable, org.directwebremoting.InboundContext)
42      */

43     public Object JavaDoc convertInbound(Class JavaDoc paramType, InboundVariable iv, InboundContext inctx)
44     {
45         WebContext webcx = WebContextFactory.get();
46
47         if (HttpServletRequest JavaDoc.class.isAssignableFrom(paramType))
48         {
49             return webcx.getHttpServletRequest();
50         }
51
52         if (HttpServletResponse JavaDoc.class.isAssignableFrom(paramType))
53         {
54             return webcx.getHttpServletResponse();
55         }
56
57         if (ServletConfig JavaDoc.class.isAssignableFrom(paramType))
58         {
59             return webcx.getServletConfig();
60         }
61
62         if (ServletContext JavaDoc.class.isAssignableFrom(paramType))
63         {
64             return webcx.getServletContext();
65         }
66
67         if (HttpSession JavaDoc.class.isAssignableFrom(paramType))
68         {
69             return webcx.getSession(true);
70         }
71
72         return null;
73     }
74
75     /* (non-Javadoc)
76      * @see org.directwebremoting.Converter#convertOutbound(java.lang.Object, org.directwebremoting.OutboundContext)
77      */

78     public OutboundVariable convertOutbound(Object JavaDoc data, OutboundContext outctx)
79     {
80         return new SimpleOutboundVariable("null", outctx, true);
81     }
82 }
83
Popular Tags