KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > servlet > ServletRequestWrapper


1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */

17 package javax.servlet;
18
19 import java.io.BufferedReader JavaDoc;
20 import java.io.IOException JavaDoc;
21 import java.util.Enumeration JavaDoc;
22 import java.util.Locale JavaDoc;
23 import java.util.Map JavaDoc;
24
25
26
27 /**
28  *
29  * Provides a convenient implementation of the ServletRequest interface that
30  * can be subclassed by developers wishing to adapt the request to a Servlet.
31  * This class implements the Wrapper or Decorator pattern. Methods default to
32  * calling through to the wrapped request object.
33   * @since v 2.3
34  *
35  *
36  *
37  * @see javax.servlet.ServletRequest
38  *
39  */

40
41 public class ServletRequestWrapper implements ServletRequest JavaDoc {
42     private ServletRequest JavaDoc request;
43
44     /**
45     * Creates a ServletRequest adaptor wrapping the given request object.
46     * @throws java.lang.IllegalArgumentException if the request is null
47     */

48
49     public ServletRequestWrapper(ServletRequest JavaDoc request) {
50     if (request == null) {
51         throw new IllegalArgumentException JavaDoc("Request cannot be null");
52     }
53     this.request = request;
54     }
55
56     /**
57     * Return the wrapped request object.
58     */

59     public ServletRequest JavaDoc getRequest() {
60         return this.request;
61     }
62     
63     /**
64     * Sets the request object being wrapped.
65     * @throws java.lang.IllegalArgumentException if the request is null.
66     */

67     
68     public void setRequest(ServletRequest JavaDoc request) {
69         if (request == null) {
70         throw new IllegalArgumentException JavaDoc("Request cannot be null");
71         }
72         this.request = request;
73     }
74
75     /**
76      *
77      * The default behavior of this method is to call getAttribute(String name)
78      * on the wrapped request object.
79      */

80
81     public Object JavaDoc getAttribute(String JavaDoc name) {
82     return this.request.getAttribute(name);
83     }
84     
85     
86
87     /**
88      * The default behavior of this method is to return getAttributeNames()
89      * on the wrapped request object.
90      */

91
92     public Enumeration JavaDoc getAttributeNames() {
93     return this.request.getAttributeNames();
94     }
95     
96     
97     
98     /**
99       * The default behavior of this method is to return getCharacterEncoding()
100      * on the wrapped request object.
101      */

102
103     public String JavaDoc getCharacterEncoding() {
104     return this.request.getCharacterEncoding();
105     }
106     
107     /**
108       * The default behavior of this method is to set the character encoding
109      * on the wrapped request object.
110      */

111
112     public void setCharacterEncoding(String JavaDoc enc) throws java.io.UnsupportedEncodingException JavaDoc {
113     this.request.setCharacterEncoding(enc);
114     }
115     
116     
117     /**
118       * The default behavior of this method is to return getContentLength()
119      * on the wrapped request object.
120      */

121
122     public int getContentLength() {
123     return this.request.getContentLength();
124     }
125     
126     
127     
128
129        /**
130       * The default behavior of this method is to return getContentType()
131      * on the wrapped request object.
132      */

133     public String JavaDoc getContentType() {
134     return this.request.getContentType();
135     }
136     
137     
138     
139
140      /**
141       * The default behavior of this method is to return getInputStream()
142      * on the wrapped request object.
143      */

144
145     public ServletInputStream JavaDoc getInputStream() throws IOException JavaDoc {
146     return this.request.getInputStream();
147     }
148      
149     
150     
151
152     /**
153       * The default behavior of this method is to return getParameter(String name)
154      * on the wrapped request object.
155      */

156
157     public String JavaDoc getParameter(String JavaDoc name) {
158     return this.request.getParameter(name);
159     }
160     
161     /**
162       * The default behavior of this method is to return getParameterMap()
163      * on the wrapped request object.
164      */

165     public Map JavaDoc getParameterMap() {
166     return this.request.getParameterMap();
167     }
168     
169     
170     
171
172     /**
173       * The default behavior of this method is to return getParameterNames()
174      * on the wrapped request object.
175      */

176      
177     public Enumeration JavaDoc getParameterNames() {
178     return this.request.getParameterNames();
179     }
180     
181     
182     
183
184        /**
185       * The default behavior of this method is to return getParameterValues(String name)
186      * on the wrapped request object.
187      */

188     public String JavaDoc[] getParameterValues(String JavaDoc name) {
189     return this.request.getParameterValues(name);
190     }
191     
192     
193     
194
195      /**
196       * The default behavior of this method is to return getProtocol()
197      * on the wrapped request object.
198      */

199     
200     public String JavaDoc getProtocol() {
201     return this.request.getProtocol();
202     }
203     
204     
205     
206
207     /**
208       * The default behavior of this method is to return getScheme()
209      * on the wrapped request object.
210      */

211     
212
213     public String JavaDoc getScheme() {
214     return this.request.getScheme();
215     }
216     
217     
218     
219
220     /**
221       * The default behavior of this method is to return getServerName()
222      * on the wrapped request object.
223      */

224     public String JavaDoc getServerName() {
225     return this.request.getServerName();
226     }
227     
228     
229     
230
231    /**
232       * The default behavior of this method is to return getServerPort()
233      * on the wrapped request object.
234      */

235
236     public int getServerPort() {
237     return this.request.getServerPort();
238     }
239     
240     
241     
242   /**
243       * The default behavior of this method is to return getReader()
244      * on the wrapped request object.
245      */

246
247     public BufferedReader JavaDoc getReader() throws IOException JavaDoc {
248     return this.request.getReader();
249     }
250     
251     
252     
253
254     /**
255       * The default behavior of this method is to return getRemoteAddr()
256      * on the wrapped request object.
257      */

258     
259     public String JavaDoc getRemoteAddr() {
260     return this.request.getRemoteAddr();
261     }
262     
263     
264     
265
266       /**
267       * The default behavior of this method is to return getRemoteHost()
268      * on the wrapped request object.
269      */

270
271     public String JavaDoc getRemoteHost() {
272     return this.request.getRemoteHost();
273     }
274     
275     
276     
277
278     /**
279       * The default behavior of this method is to return setAttribute(String name, Object o)
280      * on the wrapped request object.
281      */

282
283     public void setAttribute(String JavaDoc name, Object JavaDoc o) {
284     this.request.setAttribute(name, o);
285     }
286     
287     
288     
289
290     /**
291       * The default behavior of this method is to call removeAttribute(String name)
292      * on the wrapped request object.
293      */

294     public void removeAttribute(String JavaDoc name) {
295     this.request.removeAttribute(name);
296     }
297     
298     
299     
300
301    /**
302       * The default behavior of this method is to return getLocale()
303      * on the wrapped request object.
304      */

305
306     public Locale JavaDoc getLocale() {
307     return this.request.getLocale();
308     }
309     
310     
311     
312
313      /**
314       * The default behavior of this method is to return getLocales()
315      * on the wrapped request object.
316      */

317
318     public Enumeration JavaDoc getLocales() {
319     return this.request.getLocales();
320     }
321     
322     
323     
324
325     /**
326       * The default behavior of this method is to return isSecure()
327      * on the wrapped request object.
328      */

329
330     public boolean isSecure() {
331     return this.request.isSecure();
332     }
333     
334     
335     
336
337     /**
338       * The default behavior of this method is to return getRequestDispatcher(String path)
339      * on the wrapped request object.
340      */

341
342     public RequestDispatcher JavaDoc getRequestDispatcher(String JavaDoc path) {
343     return this.request.getRequestDispatcher(path);
344     }
345     
346     
347     
348
349     /**
350       * The default behavior of this method is to return getRealPath(String path)
351      * on the wrapped request object.
352      */

353
354     public String JavaDoc getRealPath(String JavaDoc path) {
355     return this.request.getRealPath(path);
356     }
357     
358     /**
359      * The default behavior of this method is to return
360      * getRemotePort() on the wrapped request object.
361      *
362      * @since 2.4
363      */

364     public int getRemotePort(){
365         return this.request.getRemotePort();
366     }
367
368
369     /**
370      * The default behavior of this method is to return
371      * getLocalName() on the wrapped request object.
372      *
373      * @since 2.4
374      */

375     public String JavaDoc getLocalName(){
376         return this.request.getLocalName();
377     }
378
379     /**
380      * The default behavior of this method is to return
381      * getLocalAddr() on the wrapped request object.
382      *
383      * @since 2.4
384      */

385     public String JavaDoc getLocalAddr(){
386         return this.request.getLocalAddr();
387     }
388
389
390     /**
391      * The default behavior of this method is to return
392      * getLocalPort() on the wrapped request object.
393      *
394      * @since 2.4
395      */

396     public int getLocalPort(){
397         return this.request.getLocalPort();
398     }
399     
400 }
401
402
Popular Tags