001    // Copyright 2009, 2010, 2011 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    
015    package org.apache.tapestry5.services;
016    
017    import java.util.List;
018    import java.util.Locale;
019    
020    /**
021     * Class that wraps an {@linkplain Request}, delegating all its methods.
022     * 
023     * @since 5.1.0.1
024     */
025    public 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 String getContextPath()
066        {
067            return request.getContextPath();
068        }
069    
070        public long getDateHeader(String name)
071        {
072            return request.getDateHeader(name);
073        }
074    
075        public String getHeader(String name)
076        {
077            return request.getHeader(name);
078        }
079    
080        public List<String> getHeaderNames()
081        {
082            return request.getHeaderNames();
083        }
084    
085        public Locale getLocale()
086        {
087            return request.getLocale();
088        }
089    
090        public String getMethod()
091        {
092            return request.getMethod();
093        }
094    
095        public String getParameter(String name)
096        {
097            return request.getParameter(name);
098        }
099    
100        public List<String> getParameterNames()
101        {
102            return request.getParameterNames();
103        }
104    
105        public String[] getParameters(String name)
106        {
107            return request.getParameters(name);
108        }
109    
110        public String getPath()
111        {
112            return request.getPath();
113        }
114    
115        public String getServerName()
116        {
117            return request.getServerName();
118        }
119    
120        public Session getSession(boolean create)
121        {
122            return request.getSession(create);
123        }
124    
125        public boolean isRequestedSessionIdValid()
126        {
127            return request.isRequestedSessionIdValid();
128        }
129    
130        public boolean isSecure()
131        {
132            return request.isSecure();
133        }
134    
135        public boolean isXHR()
136        {
137            return request.isXHR();
138        }
139    
140        public void setAttribute(String name, Object value)
141        {
142            request.setAttribute(name, value);
143        }
144    
145        public int getLocalPort()
146        {
147            return request.getLocalPort();
148        }
149    
150        public int getServerPort()
151        {
152            return request.getServerPort();
153        }
154    
155        public String getRemoteHost()
156        {
157            return request.getRemoteHost();
158        }
159    }