KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > servlet > ServletResponseWrapper


1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. 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 package javax.servlet;
18
19 import java.io.IOException JavaDoc;
20 import java.io.PrintWriter JavaDoc;
21 import java.util.Locale JavaDoc;
22
23 /**
24  *
25  * Provides a convenient implementation of the ServletResponse interface that
26  * can be subclassed by developers wishing to adapt the response from a Servlet.
27  * This class implements the Wrapper or Decorator pattern. Methods default to
28  * calling through to the wrapped response object.
29  *
30  * @author Various
31  * @version $Version$
32  * @since v 2.3
33  *
34  * @see javax.servlet.ServletResponse
35  *
36  */

37
38  
39 public class ServletResponseWrapper implements ServletResponse JavaDoc {
40     private ServletResponse JavaDoc response;
41     /**
42     * Creates a ServletResponse adaptor wrapping the given response object.
43     * @throws java.lang.IllegalArgumentException if the response is null.
44     */

45
46
47     public ServletResponseWrapper(ServletResponse JavaDoc response) {
48         if (response == null) {
49         throw new IllegalArgumentException JavaDoc("Response cannot be null");
50         }
51         this.response = response;
52     }
53
54     /**
55     * Return the wrapped ServletResponse object.
56     */

57
58     public ServletResponse JavaDoc getResponse() {
59         return this.response;
60     }
61     
62     
63     /**
64     * Sets the response being wrapped.
65     * @throws java.lang.IllegalArgumentException if the response is null.
66     */

67     
68     public void setResponse(ServletResponse JavaDoc response) {
69         if (response == null) {
70         throw new IllegalArgumentException JavaDoc("Response cannot be null");
71         }
72         this.response = response;
73     }
74
75     /**
76      * The default behavior of this method is to call setCharacterEncoding(String charset)
77      * on the wrapped response object.
78      *
79      * @since 2.4
80      */

81
82     public void setCharacterEncoding(String JavaDoc charset) {
83     this.response.setCharacterEncoding(charset);
84     }
85
86     /**
87      * The default behavior of this method is to return getCharacterEncoding()
88      * on the wrapped response object.
89      */

90
91     public String JavaDoc getCharacterEncoding() {
92     return this.response.getCharacterEncoding();
93     }
94     
95     
96       /**
97      * The default behavior of this method is to return getOutputStream()
98      * on the wrapped response object.
99      */

100
101     public ServletOutputStream JavaDoc getOutputStream() throws IOException JavaDoc {
102     return this.response.getOutputStream();
103     }
104       
105      /**
106      * The default behavior of this method is to return getWriter()
107      * on the wrapped response object.
108      */

109
110
111     public PrintWriter JavaDoc getWriter() throws IOException JavaDoc {
112     return this.response.getWriter();
113     }
114     
115     /**
116      * The default behavior of this method is to call setContentLength(int len)
117      * on the wrapped response object.
118      */

119
120     public void setContentLength(int len) {
121     this.response.setContentLength(len);
122     }
123     
124     /**
125      * The default behavior of this method is to call setContentType(String type)
126      * on the wrapped response object.
127      */

128
129     public void setContentType(String JavaDoc type) {
130     this.response.setContentType(type);
131     }
132
133     /**
134      * The default behavior of this method is to return getContentType()
135      * on the wrapped response object.
136      *
137      * @since 2.4
138      */

139
140     public String JavaDoc getContentType() {
141     return this.response.getContentType();
142     }
143     
144     /**
145      * The default behavior of this method is to call setBufferSize(int size)
146      * on the wrapped response object.
147      */

148     public void setBufferSize(int size) {
149     this.response.setBufferSize(size);
150     }
151     
152     /**
153      * The default behavior of this method is to return getBufferSize()
154      * on the wrapped response object.
155      */

156     public int getBufferSize() {
157     return this.response.getBufferSize();
158     }
159
160     /**
161      * The default behavior of this method is to call flushBuffer()
162      * on the wrapped response object.
163      */

164
165     public void flushBuffer() throws IOException JavaDoc {
166     this.response.flushBuffer();
167     }
168     
169     /**
170      * The default behavior of this method is to return isCommitted()
171      * on the wrapped response object.
172      */

173     public boolean isCommitted() {
174     return this.response.isCommitted();
175     }
176
177     /**
178      * The default behavior of this method is to call reset()
179      * on the wrapped response object.
180      */

181
182     public void reset() {
183     this.response.reset();
184     }
185     
186     /**
187      * The default behavior of this method is to call resetBuffer()
188      * on the wrapped response object.
189      */

190      
191     public void resetBuffer() {
192     this.response.resetBuffer();
193     }
194     
195     /**
196      * The default behavior of this method is to call setLocale(Locale loc)
197      * on the wrapped response object.
198      */

199
200     public void setLocale(Locale JavaDoc loc) {
201     this.response.setLocale(loc);
202     }
203     
204     /**
205      * The default behavior of this method is to return getLocale()
206      * on the wrapped response object.
207      */

208     public Locale JavaDoc getLocale() {
209     return this.response.getLocale();
210     }
211
212
213 }
214
215
216
217
218
219
Popular Tags