Save This Page
Home » glassfish-v2ur2-b04-src » javax » servlet » [javadoc | source]
    1   
    2   
    3   /*
    4    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    5    * 
    6    * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
    7    * 
    8    * Portions Copyright Apache Software Foundation.
    9    * 
   10    * The contents of this file are subject to the terms of either the GNU
   11    * General Public License Version 2 only ("GPL") or the Common Development
   12    * and Distribution License("CDDL") (collectively, the "License").  You
   13    * may not use this file except in compliance with the License. You can obtain
   14    * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
   15    * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
   16    * language governing permissions and limitations under the License.
   17    * 
   18    * When distributing the software, include this License Header Notice in each
   19    * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
   20    * Sun designates this particular file as subject to the "Classpath" exception
   21    * as provided by Sun in the GPL Version 2 section of the License file that
   22    * accompanied this code.  If applicable, add the following below the License
   23    * Header, with the fields enclosed by brackets [] replaced by your own
   24    * identifying information: "Portions Copyrighted [year]
   25    * [name of copyright owner]"
   26    * 
   27    * Contributor(s):
   28    * 
   29    * If you wish your version of this file to be governed by only the CDDL or
   30    * only the GPL Version 2, indicate your decision by adding "[Contributor]
   31    * elects to include this software in this distribution under the [CDDL or GPL
   32    * Version 2] license."  If you don't indicate a single choice of license, a
   33    * recipient has the option to distribute your version of this file under
   34    * either the CDDL, the GPL Version 2 or to extend the choice of license to
   35    * its licensees as provided above.  However, if you add GPL Version 2 code
   36    * and therefore, elected the GPL Version 2 license, then the option applies
   37    * only if the new code is made subject to such option by the copyright
   38    * holder.
   39    */
   40   
   41   package javax.servlet;
   42   
   43   import java.io.IOException;
   44   import java.io.PrintWriter;
   45   import java.util.Locale;
   46   
   47   /**
   48    * 
   49    * Provides a convenient implementation of the ServletResponse interface that
   50    * can be subclassed by developers wishing to adapt the response from a Servlet.
   51    * This class implements the Wrapper or Decorator pattern. Methods default to
   52    * calling through to the wrapped response object.
   53    * 
   54    * @author 	Various
   55    * @since	v 2.3
   56    *
   57    * @see 	javax.servlet.ServletResponse
   58    *
   59    */
   60   
   61    
   62   public class ServletResponseWrapper implements ServletResponse {
   63   	private ServletResponse response;
   64   	/**
   65   	* Creates a ServletResponse adaptor wrapping the given response object.
   66   	* @throws java.lang.IllegalArgumentException if the response is null.
   67   	*/
   68   
   69   
   70   	public ServletResponseWrapper(ServletResponse response) {
   71   	    if (response == null) {
   72   		throw new IllegalArgumentException("Response cannot be null");
   73   	    }
   74   	    this.response = response;
   75   	}
   76   
   77   	/**
   78   	* Return the wrapped ServletResponse object.
   79   	*/
   80   
   81   	public ServletResponse getResponse() {
   82   		return this.response;
   83   	}	
   84   	
   85   	
   86   	/**
   87   	* Sets the response being wrapped. 
   88   	* @throws java.lang.IllegalArgumentException if the response is null.
   89   	*/
   90   	
   91   	public void setResponse(ServletResponse response) {
   92   	    if (response == null) {
   93   		throw new IllegalArgumentException("Response cannot be null");
   94   	    }
   95   	    this.response = response;
   96   	}
   97   
   98       /**
   99        * The default behavior of this method is to call setCharacterEncoding(String charset)
  100        * on the wrapped response object.
  101        *
  102        * @since 2.4
  103        */
  104   
  105       public void setCharacterEncoding(String charset) {
  106   	this.response.setCharacterEncoding(charset);
  107       }
  108   
  109       /**
  110        * The default behavior of this method is to return getCharacterEncoding()
  111        * on the wrapped response object.
  112        */
  113   
  114       public String getCharacterEncoding() {
  115   	return this.response.getCharacterEncoding();
  116   	}
  117       
  118       
  119   	  /**
  120        * The default behavior of this method is to return getOutputStream()
  121        * on the wrapped response object.
  122        */
  123   
  124       public ServletOutputStream getOutputStream() throws IOException {
  125   	return this.response.getOutputStream();
  126       }  
  127         
  128        /**
  129        * The default behavior of this method is to return getWriter()
  130        * on the wrapped response object.
  131        */
  132   
  133   
  134       public PrintWriter getWriter() throws IOException {
  135   	return this.response.getWriter();
  136   	}
  137       
  138       /**
  139        * The default behavior of this method is to call setContentLength(int len)
  140        * on the wrapped response object.
  141        */
  142   
  143       public void setContentLength(int len) {
  144   	this.response.setContentLength(len);
  145       }
  146       
  147       /**
  148        * The default behavior of this method is to call setContentType(String type)
  149        * on the wrapped response object.
  150        */
  151   
  152       public void setContentType(String type) {
  153   	this.response.setContentType(type);
  154       }
  155   
  156       /**
  157        * The default behavior of this method is to return getContentType()
  158        * on the wrapped response object.
  159        *
  160        * @since 2.4
  161        */
  162   
  163       public String getContentType() {
  164   	return this.response.getContentType();
  165       }
  166       
  167       /**
  168        * The default behavior of this method is to call setBufferSize(int size)
  169        * on the wrapped response object.
  170        */
  171       public void setBufferSize(int size) {
  172   	this.response.setBufferSize(size);
  173       }
  174       
  175       /**
  176        * The default behavior of this method is to return getBufferSize()
  177        * on the wrapped response object.
  178        */
  179       public int getBufferSize() {
  180   	return this.response.getBufferSize();
  181       }
  182   
  183       /**
  184        * The default behavior of this method is to call flushBuffer()
  185        * on the wrapped response object.
  186        */
  187   
  188       public void flushBuffer() throws IOException {
  189   	this.response.flushBuffer();
  190       }
  191       
  192       /**
  193        * The default behavior of this method is to return isCommitted()
  194        * on the wrapped response object.
  195        */
  196       public boolean isCommitted() {
  197   	return this.response.isCommitted();
  198       }
  199   
  200       /**
  201        * The default behavior of this method is to call reset()
  202        * on the wrapped response object.
  203        */
  204   
  205       public void reset() {
  206   	this.response.reset();
  207       }
  208       
  209       /**
  210        * The default behavior of this method is to call resetBuffer()
  211        * on the wrapped response object.
  212        */
  213        
  214       public void resetBuffer() {
  215   	this.response.resetBuffer();
  216       }
  217       
  218       /**
  219        * The default behavior of this method is to call setLocale(Locale loc)
  220        * on the wrapped response object.
  221        */
  222   
  223       public void setLocale(Locale loc) {
  224   	this.response.setLocale(loc);
  225       }
  226       
  227       /**
  228        * The default behavior of this method is to return getLocale()
  229        * on the wrapped response object.
  230        */
  231       public Locale getLocale() {
  232   	return this.response.getLocale();
  233       }
  234   
  235   
  236   }
  237   
  238   
  239   
  240   
  241   

Save This Page
Home » glassfish-v2ur2-b04-src » javax » servlet » [javadoc | source]