Clover coverage report - Code Coverage for tapestry release 4.0-beta-2
Coverage timestamp: Sat Jul 9 2005 22:02:17 EDT
file stats: LOC: 150   Methods: 9
NCLOC: 55   Classes: 1
30 day Evaluation License registered to hlship@comcast.net Your 30 day evaluation period has expired. Please visit http://www.cenqua.com to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
RequestContext.java 100% 100% 100% 100%
coverage
 1    // Copyright 2004, 2005 The Apache Software Foundation
 2    //
 3    // Licensed under the Apache License, Version 2.0 (the "License");
 4    // you may not use this file except in compliance with the License.
 5    // You may obtain a copy of the License at
 6    //
 7    // http://www.apache.org/licenses/LICENSE-2.0
 8    //
 9    // Unless required by applicable law or agreed to in writing, software
 10    // distributed under the License is distributed on an "AS IS" BASIS,
 11    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12    // See the License for the specific language governing permissions and
 13    // limitations under the License.
 14   
 15    package org.apache.tapestry.request;
 16   
 17    import java.util.ArrayList;
 18    import java.util.Enumeration;
 19    import java.util.List;
 20   
 21    import javax.servlet.http.HttpServletRequest;
 22    import javax.servlet.http.HttpServletResponse;
 23    import javax.servlet.http.HttpSession;
 24   
 25    import org.apache.tapestry.ApplicationServlet;
 26   
 27    /**
 28    * This class encapsulates all the relevant data for one request cycle of an
 29    * {@link ApplicationServlet}. This includes:
 30    * <ul>
 31    * <li>{@link HttpServletRequest}
 32    * <li>{@link HttpServletResponse}
 33    * <li>{@link HttpSession}
 34    * </ul>
 35    * <p>
 36    * This is a limited and crippled version of the RequestContext as it was available in release 3.0,
 37    * that exists as a bridge for compatibility only. This saves developers from having to modify their
 38    * classes to have the {@link javax.servlet.http.HttpServletRequest}&nbsp;or
 39    * {@link org.apache.tapestry.web.WebRequest}injected into their pages, components, or services. It
 40    * will be removed in the next release of Tapestry.
 41    * <p>
 42    * Interestingly, with the Tapestry 4.0 architecture, a single instance of RequestContext can be
 43    * shared by all request cycles (that's because the request and response are, in fact, threaded
 44    * proxies).
 45    *
 46    * @author Howard Lewis Ship
 47    * @deprecated To be removed in 4.1. Use injection to gain access to the necessary objects.
 48    */
 49   
 50    public class RequestContext
 51    {
 52    private final HttpServletRequest _request;
 53   
 54    private final HttpServletResponse _response;
 55   
 56  50 public RequestContext(HttpServletRequest request, HttpServletResponse response)
 57    {
 58   
 59  50 _request = request;
 60  50 _response = response;
 61    }
 62   
 63    /**
 64    * Returns the named parameter from the {@link HttpServletRequest}.
 65    * <p>
 66    * Use {@link #getParameters(String)}for parameters that may include multiple values.
 67    */
 68   
 69  1 public String getParameter(String name)
 70    {
 71  1 return _request.getParameter(name);
 72    }
 73   
 74    /**
 75    * Convienience method for getting a {@link HttpServletRequest}attribute.
 76    *
 77    * @since 2.3
 78    */
 79   
 80  1 public Object getAttribute(String name)
 81    {
 82  1 return _request.getAttribute(name);
 83    }
 84   
 85    /**
 86    * For parameters that are, or are possibly, multi-valued, this method returns all the values as
 87    * an array of Strings.
 88    *
 89    * @see #getParameter(String)
 90    */
 91   
 92  1 public String[] getParameters(String name)
 93    {
 94  1 return _request.getParameterValues(name);
 95    }
 96   
 97  1 public String[] getParameterNames()
 98    {
 99  1 Enumeration e = _request.getParameterNames();
 100  1 List names = new ArrayList();
 101   
 102  1 while (e.hasMoreElements())
 103  2 names.add(e.nextElement());
 104   
 105  1 int count = names.size();
 106   
 107  1 String[] result = new String[count];
 108   
 109  1 return (String[]) names.toArray(result);
 110    }
 111   
 112    /**
 113    * Returns the request which initiated the current request cycle. Note that the methods
 114    * {@link #getParameter(String)}and {@link #getParameters(String)}should be used, rather than
 115    * obtaining parameters directly from the request (since the RequestContext handles the
 116    * differences between normal and multipart/form requests).
 117    */
 118   
 119  1 public HttpServletRequest getRequest()
 120    {
 121  1 return _request;
 122    }
 123   
 124  1 public HttpServletResponse getResponse()
 125    {
 126  1 return _response;
 127    }
 128   
 129    /**
 130    * Returns the {@link HttpSession}, if necessary, invoking
 131    * {@link HttpServletRequest#getSession(boolean)}. However, this method will <em>not</em>
 132    * create a session.
 133    */
 134   
 135  1 public HttpSession getSession()
 136    {
 137  1 return _request.getSession(false);
 138    }
 139   
 140    /**
 141    * Like {@link #getSession()}, but forces the creation of the {@link HttpSession}, if
 142    * necessary.
 143    */
 144   
 145  1 public HttpSession createSession()
 146    {
 147  1 return _request.getSession(true);
 148    }
 149   
 150    }