    001// Copyright 2009, 2010, 2011, 2012 The Apache Software Foundation
    002//
    003// Licensed under the Apache License, Version 2.0 (the "License");
    004// you may not use this file except in compliance with the License.
    005// You may obtain a copy of the License at
    006//
    007// http://www.apache.org/licenses/LICENSE-2.0
    008//
    009// Unless required by applicable law or agreed to in writing, software
    010// distributed under the License is distributed on an "AS IS" BASIS,
    011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    012// See the License for the specific language governing permissions and
    013// limitations under the License.
    014
    015package org.apache.tapestry5.services;
    016
    017import java.util.List;
    018import java.util.Locale;
    019
    020/**
    021 * Class that wraps an {@linkplain Request}, delegating all its methods.
    022 *
    023 * @since 5.1.0.1
    024 */
    025public class DelegatingRequest implements Request
    026{
    027
    028    private Request request;
    029
    030    /**
    031     * No-arg constructor. It should only be used for testing purposes.
    032     */
    033    public DelegatingRequest()
    034    {
    035    }
    036
    037    /**
    038     * Constructor that receives a {@linkplain Request}.
    039     *
    040     * @param request
    041     *            a {@link Request}. It cannot be null.
    042     */
    043    public DelegatingRequest(Request request)
    044    {
    045        setRequest(request);
    046    }
    047
    048    /**
    049     * Sets the delegate request.
    050     *
    051     * @param request
    052     *            a {@link Request}. It cannot be null.
    053     */
    054    public void setRequest(Request request)
    055    {
    056        assert request != null;
    057        this.request = request;
    058    }
    059
    060    public Object getAttribute(String name)
    061    {
    062        return request.getAttribute(name);
    063    }
    064
    065    public List<String> getAttributeNames()
    066    {
    067        return request.getAttributeNames();
    068    }
    069
    070    public String getContextPath()
    071    {
    072        return request.getContextPath();
    073    }
    074
    075    public long getDateHeader(String name)
    076    {
    077        return request.getDateHeader(name);
    078    }
    079
    080    public String getHeader(String name)
    081    {
    082        return request.getHeader(name);
    083    }
    084
    085    public List<String> getHeaderNames()
    086    {
    087        return request.getHeaderNames();
    088    }
    089
    090    public Locale getLocale()
    091    {
    092        return request.getLocale();
    093    }
    094
    095    public String getMethod()
    096    {
    097        return request.getMethod();
    098    }
    099
    100    public String getParameter(String name)
    101    {
    102        return request.getParameter(name);
    103    }
    104
    105    public List<String> getParameterNames()
    106    {
    107        return request.getParameterNames();
    108    }
    109
    110    public String[] getParameters(String name)
    111    {
    112        return request.getParameters(name);
    113    }
    114
    115    public String getPath()
    116    {
    117        return request.getPath();
    118    }
    119
    120    public String getServerName()
    121    {
    122        return request.getServerName();
    123    }
    124
    125    public Session getSession(boolean create)
    126    {
    127        return request.getSession(create);
    128    }
    129
    130    public boolean isRequestedSessionIdValid()
    131    {
    132        return request.isRequestedSessionIdValid();
    133    }
    134
    135    public boolean isSecure()
    136    {
    137        return request.isSecure();
    138    }
    139
    140    public boolean isXHR()
    141    {
    142        return request.isXHR();
    143    }
    144
    145    public void setAttribute(String name, Object value)
    146    {
    147        request.setAttribute(name, value);
    148    }
    149
    150    public int getLocalPort()
    151    {
    152        return request.getLocalPort();
    153    }
    154
    155    public int getServerPort()
    156    {
    157        return request.getServerPort();
    158    }
    159
    160    public String getRemoteHost()
    161    {
    162        return request.getRemoteHost();
    163    }
    164
    165    public boolean isSessionInvalidated()
    166    {
    167        return request.isSessionInvalidated();
    168    }
    169}