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.BufferedReader;
   44   import java.io.IOException;
   45   import java.util.Enumeration;
   46   import java.util.Locale;
   47   import java.util.Map;
   48   
   49   
   50   
   51   /**
   52    * 
   53    * Provides a convenient implementation of the ServletRequest interface that
   54    * can be subclassed by developers wishing to adapt the request to a Servlet.
   55    * This class implements the Wrapper or Decorator pattern. Methods default to
   56    * calling through to the wrapped request object.
   57     * @since	v 2.3
   58    * 
   59    * 
   60    *
   61    * @see 	javax.servlet.ServletRequest
   62    *
   63    */
   64   
   65   public class ServletRequestWrapper implements ServletRequest {
   66       private ServletRequest request;
   67   
   68   	/**
   69   	* Creates a ServletRequest adaptor wrapping the given request object. 
   70   	* @throws java.lang.IllegalArgumentException if the request is null
   71   	*/
   72   
   73       public ServletRequestWrapper(ServletRequest request) {
   74   	if (request == null) {
   75   	    throw new IllegalArgumentException("Request cannot be null");   
   76   	}
   77   	this.request = request;
   78       }
   79   
   80   	/**
   81   	* Return the wrapped request object.
   82   	*/
   83   	public ServletRequest getRequest() {
   84   		return this.request;
   85   	}
   86   	
   87   	/**
   88   	* Sets the request object being wrapped. 
   89   	* @throws java.lang.IllegalArgumentException if the request is null.
   90   	*/
   91   	
   92   	public void setRequest(ServletRequest request) {
   93   	    if (request == null) {
   94   		throw new IllegalArgumentException("Request cannot be null");
   95   	    }
   96   	    this.request = request;
   97   	}
   98   
   99       /**
  100        *
  101        * The default behavior of this method is to call getAttribute(String name)
  102        * on the wrapped request object.
  103        */
  104   
  105       public Object getAttribute(String name) {
  106   	return this.request.getAttribute(name);
  107   	}
  108       
  109       
  110   
  111       /**
  112        * The default behavior of this method is to return getAttributeNames()
  113        * on the wrapped request object.
  114        */
  115   
  116       public Enumeration getAttributeNames() {
  117   	return this.request.getAttributeNames();
  118   	}    
  119       
  120       
  121       
  122       /**
  123         * The default behavior of this method is to return getCharacterEncoding()
  124        * on the wrapped request object.
  125        */
  126   
  127       public String getCharacterEncoding() {
  128   	return this.request.getCharacterEncoding();
  129   	}
  130   	
  131       /**
  132         * The default behavior of this method is to set the character encoding
  133        * on the wrapped request object.
  134        */
  135   
  136       public void setCharacterEncoding(String enc) throws java.io.UnsupportedEncodingException {
  137   	this.request.setCharacterEncoding(enc);
  138   	}
  139       
  140       
  141       /**
  142         * The default behavior of this method is to return getContentLength()
  143        * on the wrapped request object.
  144        */
  145   
  146       public int getContentLength() {
  147   	return this.request.getContentLength();
  148       }
  149       
  150       
  151       
  152   
  153          /**
  154         * The default behavior of this method is to return getContentType()
  155        * on the wrapped request object.
  156        */
  157       public String getContentType() {
  158   	return this.request.getContentType();
  159       }
  160       
  161       
  162       
  163   
  164        /**
  165         * The default behavior of this method is to return getInputStream()
  166        * on the wrapped request object.
  167        */
  168   
  169       public ServletInputStream getInputStream() throws IOException {
  170   	return this.request.getInputStream();
  171   	}
  172        
  173       
  174       
  175   
  176       /**
  177         * The default behavior of this method is to return getParameter(String name)
  178        * on the wrapped request object.
  179        */
  180   
  181       public String getParameter(String name) {
  182   	return this.request.getParameter(name);
  183       }
  184       
  185       /**
  186         * The default behavior of this method is to return getParameterMap()
  187        * on the wrapped request object.
  188        */
  189       public Map getParameterMap() {
  190   	return this.request.getParameterMap();
  191       }
  192       
  193       
  194       
  195   
  196       /**
  197         * The default behavior of this method is to return getParameterNames()
  198        * on the wrapped request object.
  199        */
  200        
  201       public Enumeration getParameterNames() {
  202   	return this.request.getParameterNames();
  203       }
  204       
  205       
  206       
  207   
  208          /**
  209         * The default behavior of this method is to return getParameterValues(String name)
  210        * on the wrapped request object.
  211        */
  212       public String[] getParameterValues(String name) {
  213   	return this.request.getParameterValues(name);
  214   	}
  215       
  216       
  217       
  218   
  219        /**
  220         * The default behavior of this method is to return getProtocol()
  221        * on the wrapped request object.
  222        */
  223       
  224       public String getProtocol() {
  225   	return this.request.getProtocol();
  226   	}
  227       
  228       
  229       
  230   
  231       /**
  232         * The default behavior of this method is to return getScheme()
  233        * on the wrapped request object.
  234        */
  235       
  236   
  237       public String getScheme() {
  238   	return this.request.getScheme();
  239   	}
  240       
  241       
  242       
  243   
  244       /**
  245         * The default behavior of this method is to return getServerName()
  246        * on the wrapped request object.
  247        */
  248       public String getServerName() {
  249   	return this.request.getServerName();
  250   	}
  251       
  252       
  253       
  254   
  255      /**
  256         * The default behavior of this method is to return getServerPort()
  257        * on the wrapped request object.
  258        */
  259   
  260       public int getServerPort() {
  261   	return this.request.getServerPort();
  262   	}
  263       
  264       
  265       
  266     /**
  267         * The default behavior of this method is to return getReader()
  268        * on the wrapped request object.
  269        */
  270   
  271       public BufferedReader getReader() throws IOException {
  272   	return this.request.getReader();
  273   	}
  274       
  275       
  276       
  277   
  278       /**
  279         * The default behavior of this method is to return getRemoteAddr()
  280        * on the wrapped request object.
  281        */
  282       
  283       public String getRemoteAddr() {
  284   	return this.request.getRemoteAddr();
  285       }
  286       
  287       
  288       
  289   
  290         /**
  291         * The default behavior of this method is to return getRemoteHost()
  292        * on the wrapped request object.
  293        */
  294   
  295       public String getRemoteHost() {
  296   	return this.request.getRemoteHost();
  297       }
  298       
  299       
  300       
  301   
  302       /**
  303         * The default behavior of this method is to return setAttribute(String name, Object o)
  304        * on the wrapped request object.
  305        */
  306   
  307       public void setAttribute(String name, Object o) {
  308   	this.request.setAttribute(name, o);
  309       }
  310       
  311       
  312       
  313   
  314       /**
  315         * The default behavior of this method is to call removeAttribute(String name)
  316        * on the wrapped request object.
  317        */
  318       public void removeAttribute(String name) {
  319   	this.request.removeAttribute(name);
  320       }
  321       
  322       
  323       
  324   
  325      /**
  326         * The default behavior of this method is to return getLocale()
  327        * on the wrapped request object.
  328        */
  329   
  330       public Locale getLocale() {
  331   	return this.request.getLocale();
  332       }
  333       
  334       
  335       
  336   
  337        /**
  338         * The default behavior of this method is to return getLocales()
  339        * on the wrapped request object.
  340        */
  341   
  342       public Enumeration getLocales() {
  343   	return this.request.getLocales();
  344       }
  345       
  346       
  347       
  348   
  349       /**
  350         * The default behavior of this method is to return isSecure()
  351        * on the wrapped request object.
  352        */
  353   
  354       public boolean isSecure() {
  355   	return this.request.isSecure();
  356       }
  357       
  358       
  359       
  360   
  361       /**
  362         * The default behavior of this method is to return getRequestDispatcher(String path)
  363        * on the wrapped request object.
  364        */
  365   
  366       public RequestDispatcher getRequestDispatcher(String path) {
  367   	return this.request.getRequestDispatcher(path);
  368       }
  369       
  370       
  371       
  372   
  373       /**
  374         * The default behavior of this method is to return getRealPath(String path)
  375        * on the wrapped request object.
  376        */
  377   
  378       public String getRealPath(String path) {
  379   	return this.request.getRealPath(path);
  380       }
  381       
  382       /**
  383        * The default behavior of this method is to return
  384        * getRemotePort() on the wrapped request object.
  385        *
  386        * @since 2.4
  387        */    
  388       public int getRemotePort(){
  389           return this.request.getRemotePort();
  390       }
  391   
  392   
  393       /**
  394        * The default behavior of this method is to return
  395        * getLocalName() on the wrapped request object.
  396        *
  397        * @since 2.4
  398        */
  399       public String getLocalName(){
  400           return this.request.getLocalName();
  401       }
  402   
  403       /**
  404        * The default behavior of this method is to return
  405        * getLocalAddr() on the wrapped request object.
  406        *
  407        * @since 2.4
  408        */       
  409       public String getLocalAddr(){
  410           return this.request.getLocalAddr();
  411       }
  412   
  413   
  414       /**
  415        * The default behavior of this method is to return
  416        * getLocalPort() on the wrapped request object.
  417        *
  418        * @since 2.4
  419        */
  420       public int getLocalPort(){
  421           return this.request.getLocalPort();
  422       }
  423       
  424   }
  425   

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