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
020import org.apache.tapestry5.http.services.Request;
021import org.apache.tapestry5.http.services.Session;
022
023/**
024 * Class that wraps an {@linkplain Request}, delegating all its methods.
025 * 
026 * @since 5.1.0.1
027 */
028public class DelegatingRequest implements Request
029{
030
031    private Request request;
032
033    /**
034     * No-arg constructor. It should only be used for testing purposes.
035     */
036    public DelegatingRequest()
037    {
038    }
039
040    /**
041     * Constructor that receives a {@linkplain Request}.
042     * 
043     * @param request
044     *            a {@link Request}. It cannot be null.
045     */
046    public DelegatingRequest(Request request)
047    {
048        setRequest(request);
049    }
050
051    /**
052     * Sets the delegate request.
053     * 
054     * @param request
055     *            a {@link Request}. It cannot be null.
056     */
057    public void setRequest(Request request)
058    {
059        assert request != null;
060        this.request = request;
061    }
062
063    public Object getAttribute(String name)
064    {
065        return request.getAttribute(name);
066    }
067
068    public List<String> getAttributeNames()
069    {
070        return request.getAttributeNames();
071    }
072
073    public String getContextPath()
074    {
075        return request.getContextPath();
076    }
077
078    public long getDateHeader(String name)
079    {
080        return request.getDateHeader(name);
081    }
082
083    public String getHeader(String name)
084    {
085        return request.getHeader(name);
086    }
087
088    public List<String> getHeaderNames()
089    {
090        return request.getHeaderNames();
091    }
092
093    public Locale getLocale()
094    {
095        return request.getLocale();
096    }
097
098    public String getMethod()
099    {
100        return request.getMethod();
101    }
102
103    public String getParameter(String name)
104    {
105        return request.getParameter(name);
106    }
107
108    public List<String> getParameterNames()
109    {
110        return request.getParameterNames();
111    }
112
113    public String[] getParameters(String name)
114    {
115        return request.getParameters(name);
116    }
117
118    public String getPath()
119    {
120        return request.getPath();
121    }
122
123    public String getServerName()
124    {
125        return request.getServerName();
126    }
127
128    public Session getSession(boolean create)
129    {
130        return request.getSession(create);
131    }
132
133    public boolean isRequestedSessionIdValid()
134    {
135        return request.isRequestedSessionIdValid();
136    }
137
138    public boolean isSecure()
139    {
140        return request.isSecure();
141    }
142
143    public boolean isXHR()
144    {
145        return request.isXHR();
146    }
147
148    public void setAttribute(String name, Object value)
149    {
150        request.setAttribute(name, value);
151    }
152
153    public int getLocalPort()
154    {
155        return request.getLocalPort();
156    }
157
158    public int getServerPort()
159    {
160        return request.getServerPort();
161    }
162
163    public String getRemoteHost()
164    {
165        return request.getRemoteHost();
166    }
167
168    public boolean isSessionInvalidated()
169    {
170        return request.isSessionInvalidated();
171    }
172}