001:
002: /*
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
004: *
005: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
006: *
007: * Portions Copyright Apache Software Foundation.
008: *
009: * The contents of this file are subject to the terms of either the GNU
010: * General Public License Version 2 only ("GPL") or the Common Development
011: * and Distribution License("CDDL") (collectively, the "License"). You
012: * may not use this file except in compliance with the License. You can obtain
013: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
014: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
015: * language governing permissions and limitations under the License.
016: *
017: * When distributing the software, include this License Header Notice in each
018: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
019: * Sun designates this particular file as subject to the "Classpath" exception
020: * as provided by Sun in the GPL Version 2 section of the License file that
021: * accompanied this code. If applicable, add the following below the License
022: * Header, with the fields enclosed by brackets [] replaced by your own
023: * identifying information: "Portions Copyrighted [year]
024: * [name of copyright owner]"
025: *
026: * Contributor(s):
027: *
028: * If you wish your version of this file to be governed by only the CDDL or
029: * only the GPL Version 2, indicate your decision by adding "[Contributor]
030: * elects to include this software in this distribution under the [CDDL or GPL
031: * Version 2] license." If you don't indicate a single choice of license, a
032: * recipient has the option to distribute your version of this file under
033: * either the CDDL, the GPL Version 2 or to extend the choice of license to
034: * its licensees as provided above. However, if you add GPL Version 2 code
035: * and therefore, elected the GPL Version 2 license, then the option applies
036: * only if the new code is made subject to such option by the copyright
037: * holder.
038: */
039:
040: package javax.servlet;
041:
042: import java.io.IOException;
043: import java.io.PrintWriter;
044: import java.util.Locale;
045:
046: /**
047: *
048: * Provides a convenient implementation of the ServletResponse interface that
049: * can be subclassed by developers wishing to adapt the response from a Servlet.
050: * This class implements the Wrapper or Decorator pattern. Methods default to
051: * calling through to the wrapped response object.
052: *
053: * @author Various
054: * @since v 2.3
055: *
056: * @see javax.servlet.ServletResponse
057: *
058: */
059:
060: public class ServletResponseWrapper implements ServletResponse {
061: private ServletResponse response;
062:
063: /**
064: * Creates a ServletResponse adaptor wrapping the given response object.
065: * @throws java.lang.IllegalArgumentException if the response is null.
066: */
067:
068: public ServletResponseWrapper(ServletResponse response) {
069: if (response == null) {
070: throw new IllegalArgumentException(
071: "Response cannot be null");
072: }
073: this .response = response;
074: }
075:
076: /**
077: * Return the wrapped ServletResponse object.
078: */
079:
080: public ServletResponse getResponse() {
081: return this .response;
082: }
083:
084: /**
085: * Sets the response being wrapped.
086: * @throws java.lang.IllegalArgumentException if the response is null.
087: */
088:
089: public void setResponse(ServletResponse response) {
090: if (response == null) {
091: throw new IllegalArgumentException(
092: "Response cannot be null");
093: }
094: this .response = response;
095: }
096:
097: /**
098: * The default behavior of this method is to call setCharacterEncoding(String charset)
099: * on the wrapped response object.
100: *
101: * @since 2.4
102: */
103:
104: public void setCharacterEncoding(String charset) {
105: this .response.setCharacterEncoding(charset);
106: }
107:
108: /**
109: * The default behavior of this method is to return getCharacterEncoding()
110: * on the wrapped response object.
111: */
112:
113: public String getCharacterEncoding() {
114: return this .response.getCharacterEncoding();
115: }
116:
117: /**
118: * The default behavior of this method is to return getOutputStream()
119: * on the wrapped response object.
120: */
121:
122: public ServletOutputStream getOutputStream() throws IOException {
123: return this .response.getOutputStream();
124: }
125:
126: /**
127: * The default behavior of this method is to return getWriter()
128: * on the wrapped response object.
129: */
130:
131: public PrintWriter getWriter() throws IOException {
132: return this .response.getWriter();
133: }
134:
135: /**
136: * The default behavior of this method is to call setContentLength(int len)
137: * on the wrapped response object.
138: */
139:
140: public void setContentLength(int len) {
141: this .response.setContentLength(len);
142: }
143:
144: /**
145: * The default behavior of this method is to call setContentType(String type)
146: * on the wrapped response object.
147: */
148:
149: public void setContentType(String type) {
150: this .response.setContentType(type);
151: }
152:
153: /**
154: * The default behavior of this method is to return getContentType()
155: * on the wrapped response object.
156: *
157: * @since 2.4
158: */
159:
160: public String getContentType() {
161: return this .response.getContentType();
162: }
163:
164: /**
165: * The default behavior of this method is to call setBufferSize(int size)
166: * on the wrapped response object.
167: */
168: public void setBufferSize(int size) {
169: this .response.setBufferSize(size);
170: }
171:
172: /**
173: * The default behavior of this method is to return getBufferSize()
174: * on the wrapped response object.
175: */
176: public int getBufferSize() {
177: return this .response.getBufferSize();
178: }
179:
180: /**
181: * The default behavior of this method is to call flushBuffer()
182: * on the wrapped response object.
183: */
184:
185: public void flushBuffer() throws IOException {
186: this .response.flushBuffer();
187: }
188:
189: /**
190: * The default behavior of this method is to return isCommitted()
191: * on the wrapped response object.
192: */
193: public boolean isCommitted() {
194: return this .response.isCommitted();
195: }
196:
197: /**
198: * The default behavior of this method is to call reset()
199: * on the wrapped response object.
200: */
201:
202: public void reset() {
203: this .response.reset();
204: }
205:
206: /**
207: * The default behavior of this method is to call resetBuffer()
208: * on the wrapped response object.
209: */
210:
211: public void resetBuffer() {
212: this .response.resetBuffer();
213: }
214:
215: /**
216: * The default behavior of this method is to call setLocale(Locale loc)
217: * on the wrapped response object.
218: */
219:
220: public void setLocale(Locale loc) {
221: this .response.setLocale(loc);
222: }
223:
224: /**
225: * The default behavior of this method is to return getLocale()
226: * on the wrapped response object.
227: */
228: public Locale getLocale() {
229: return this.response.getLocale();
230: }
231:
232: }
|