KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > controls > runtime > servlet > HttpResponseService


1 package org.apache.beehive.controls.runtime.servlet;
2 /*
3  * Copyright 2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * $Header:$
18  */

19
20 import javax.servlet.http.HttpServletResponse JavaDoc;
21 import javax.servlet.http.HttpServletResponseWrapper JavaDoc;
22 import javax.servlet.ServletResponse JavaDoc;
23
24 /**
25  * This class is the contextual service implementation for javax.servlet.http.HttpServletResponse.
26  * It acts as an intermediary between the client and the HttpServletResponse instance held by the
27  * associated ServletBeanContext. It validates that attempt to access the HttpServletResponse
28  * only occur during the servlet request processing lifecycle, then delegates to the underlying
29  * HttpServletResponse instance for actual services.
30  */

31 /* package */ class HttpResponseService extends ServletResponseService
32                                         implements HttpServletResponse JavaDoc
33 {
34     /**
35      * This static helper class derives from javax.servlet.HttpServletResponseWrapper and can
36      * be used to wrap a HttpServletResponseService instance in cases where the client expects
37      * to be able to use the standard wrapper interfaces to unwrap responses.
38      */

39     private static class Wrapper extends HttpServletResponseWrapper JavaDoc
40     {
41         Wrapper(HttpResponseService responseService)
42         {
43             super(responseService);
44             _responseService = responseService;
45         }
46
47         /**
48          * Overrides the default HttpServletRequestWrapper.getResponse implementation. Rather
49          * than just returning the request passed into the constructor (i.e. the request
50          * service), it will go unwrap step further and return the current (active) http
51          * response.
52          */

53         public HttpServletResponse JavaDoc getResponse()
54         {
55             return _responseService.getHttpServletResponse();
56         }
57
58         HttpResponseService _responseService;
59     }
60     
61     
62     /* package */ HttpResponseService(ServletBeanContext beanContext)
63     {
64         super(beanContext);
65     }
66
67     final protected HttpServletResponse JavaDoc getHttpServletResponse()
68     {
69         ServletResponse JavaDoc servletRequest = getServletBeanContext().getServletResponse();
70         if (! (servletRequest instanceof HttpServletResponse JavaDoc))
71             throw new IllegalStateException JavaDoc("Current request is not an HttpServletResponse");
72         return (HttpServletResponse JavaDoc)servletRequest;
73     }
74
75     /**
76      * This method returns a ServletRequestWrapper instance that wraps the request service.
77      * This is useful in instances where there is code that uses the wrapper interfaces to
78      * unwrap requests to get to the 'root' request.
79      */

80     /* package */ HttpServletResponse JavaDoc getHttpResponseWrapper()
81     {
82         return new Wrapper JavaDoc(this);
83     }
84
85     public void addCookie(javax.servlet.http.Cookie JavaDoc cookie)
86     {
87         getHttpServletResponse().addCookie(cookie);
88     }
89
90     public boolean containsHeader(java.lang.String JavaDoc name)
91     {
92         return getHttpServletResponse().containsHeader(name);
93     }
94
95     public java.lang.String JavaDoc encodeURL(java.lang.String JavaDoc url)
96     {
97         return getHttpServletResponse().encodeURL(url);
98     }
99
100     public java.lang.String JavaDoc encodeRedirectURL(java.lang.String JavaDoc url)
101     {
102         return getHttpServletResponse().encodeRedirectURL(url);
103     }
104
105     public java.lang.String JavaDoc encodeUrl(java.lang.String JavaDoc url)
106     {
107         return getHttpServletResponse().encodeUrl(url);
108     }
109
110     public java.lang.String JavaDoc encodeRedirectUrl(java.lang.String JavaDoc url)
111     {
112         return getHttpServletResponse().encodeRedirectUrl(url);
113     }
114
115     public void sendError(int sc, java.lang.String JavaDoc msg) throws java.io.IOException JavaDoc
116     {
117         getHttpServletResponse().sendError(sc, msg);
118     }
119
120     public void sendError(int sc) throws java.io.IOException JavaDoc
121     {
122         getHttpServletResponse().sendError(sc);
123     }
124
125     public void sendRedirect(java.lang.String JavaDoc location) throws java.io.IOException JavaDoc
126     {
127         getHttpServletResponse().sendRedirect(location);
128     }
129
130     public void setDateHeader(java.lang.String JavaDoc name, long date)
131     {
132         getHttpServletResponse().setDateHeader(name, date);
133     }
134
135     public void addDateHeader(java.lang.String JavaDoc name, long date)
136     {
137         getHttpServletResponse().addDateHeader(name, date);
138     }
139
140     public void setHeader(java.lang.String JavaDoc name, java.lang.String JavaDoc value)
141     {
142         getHttpServletResponse().setHeader(name, value);
143     }
144
145     public void addHeader(java.lang.String JavaDoc name, java.lang.String JavaDoc value)
146     {
147         getHttpServletResponse().addHeader(name, value);
148     }
149
150     public void setIntHeader(java.lang.String JavaDoc name, int value)
151     {
152         getHttpServletResponse().setIntHeader(name, value);
153     }
154
155     public void addIntHeader(java.lang.String JavaDoc name, int value)
156     {
157         getHttpServletResponse().addIntHeader(name, value);
158     }
159
160     public void setStatus(int sc)
161     {
162         getHttpServletResponse().setStatus(sc);
163     }
164
165     public void setStatus(int sc, java.lang.String JavaDoc sm)
166     {
167         getHttpServletResponse().setStatus(sc, sm);
168     }
169 }
170
Popular Tags