01: /*
02: * Copyright 2005 Joe Walker
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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;
19: import javax.servlet.ServletContext;
20: import javax.servlet.http.HttpServletRequest;
21: import javax.servlet.http.HttpServletResponse;
22: import javax.servlet.http.HttpSession;
23:
24: import org.directwebremoting.WebContext;
25: import org.directwebremoting.WebContextFactory;
26: import org.directwebremoting.extend.Converter;
27: import org.directwebremoting.extend.InboundContext;
28: import org.directwebremoting.extend.InboundVariable;
29: import org.directwebremoting.extend.NonNestedOutboundVariable;
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 getahead dot ltd dot uk]
36: */
37: public class ServletConverter extends BaseV20Converter implements
38: Converter {
39: /* (non-Javadoc)
40: * @see org.directwebremoting.Converter#convertInbound(java.lang.Class, org.directwebremoting.InboundVariable, org.directwebremoting.InboundContext)
41: */
42: public Object convertInbound(Class<?> paramType,
43: InboundVariable data, InboundContext inctx) {
44: WebContext webcx = WebContextFactory.get();
45:
46: if (HttpServletRequest.class.isAssignableFrom(paramType)) {
47: return webcx.getHttpServletRequest();
48: }
49:
50: if (HttpServletResponse.class.isAssignableFrom(paramType)) {
51: return webcx.getHttpServletResponse();
52: }
53:
54: if (ServletConfig.class.isAssignableFrom(paramType)) {
55: return webcx.getServletConfig();
56: }
57:
58: if (ServletContext.class.isAssignableFrom(paramType)) {
59: return webcx.getServletContext();
60: }
61:
62: if (HttpSession.class.isAssignableFrom(paramType)) {
63: return webcx.getSession(true);
64: }
65:
66: return null;
67: }
68:
69: /* (non-Javadoc)
70: * @see org.directwebremoting.Converter#convertOutbound(java.lang.Object, org.directwebremoting.OutboundContext)
71: */
72: public OutboundVariable convertOutbound(Object data,
73: OutboundContext outctx) {
74: return new NonNestedOutboundVariable("null");
75: }
76: }
|