001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package javax.servlet;
018:
019: import java.io.BufferedReader;
020: import java.io.IOException;
021: import java.util.Enumeration;
022: import java.util.Locale;
023: import java.util.Map;
024:
025: /**
026: *
027: * Provides a convenient implementation of the ServletRequest interface that
028: * can be subclassed by developers wishing to adapt the request to a Servlet.
029: * This class implements the Wrapper or Decorator pattern. Methods default to
030: * calling through to the wrapped request object.
031: * @since v 2.3
032: *
033: *
034: *
035: * @see javax.servlet.ServletRequest
036: *
037: */
038:
039: public class ServletRequestWrapper implements ServletRequest {
040: private ServletRequest request;
041:
042: /**
043: * Creates a ServletRequest adaptor wrapping the given request object.
044: * @throws java.lang.IllegalArgumentException if the request is null
045: */
046:
047: public ServletRequestWrapper(ServletRequest request) {
048: if (request == null) {
049: throw new IllegalArgumentException("Request cannot be null");
050: }
051: this .request = request;
052: }
053:
054: /**
055: * Return the wrapped request object.
056: */
057: public ServletRequest getRequest() {
058: return this .request;
059: }
060:
061: /**
062: * Sets the request object being wrapped.
063: * @throws java.lang.IllegalArgumentException if the request is null.
064: */
065:
066: public void setRequest(ServletRequest request) {
067: if (request == null) {
068: throw new IllegalArgumentException("Request cannot be null");
069: }
070: this .request = request;
071: }
072:
073: /**
074: *
075: * The default behavior of this method is to call getAttribute(String name)
076: * on the wrapped request object.
077: */
078:
079: public Object getAttribute(String name) {
080: return this .request.getAttribute(name);
081: }
082:
083: /**
084: * The default behavior of this method is to return getAttributeNames()
085: * on the wrapped request object.
086: */
087:
088: public Enumeration getAttributeNames() {
089: return this .request.getAttributeNames();
090: }
091:
092: /**
093: * The default behavior of this method is to return getCharacterEncoding()
094: * on the wrapped request object.
095: */
096:
097: public String getCharacterEncoding() {
098: return this .request.getCharacterEncoding();
099: }
100:
101: /**
102: * The default behavior of this method is to set the character encoding
103: * on the wrapped request object.
104: */
105:
106: public void setCharacterEncoding(String enc)
107: throws java.io.UnsupportedEncodingException {
108: this .request.setCharacterEncoding(enc);
109: }
110:
111: /**
112: * The default behavior of this method is to return getContentLength()
113: * on the wrapped request object.
114: */
115:
116: public int getContentLength() {
117: return this .request.getContentLength();
118: }
119:
120: /**
121: * The default behavior of this method is to return getContentType()
122: * on the wrapped request object.
123: */
124: public String getContentType() {
125: return this .request.getContentType();
126: }
127:
128: /**
129: * The default behavior of this method is to return getInputStream()
130: * on the wrapped request object.
131: */
132:
133: public ServletInputStream getInputStream() throws IOException {
134: return this .request.getInputStream();
135: }
136:
137: /**
138: * The default behavior of this method is to return getParameter(String name)
139: * on the wrapped request object.
140: */
141:
142: public String getParameter(String name) {
143: return this .request.getParameter(name);
144: }
145:
146: /**
147: * The default behavior of this method is to return getParameterMap()
148: * on the wrapped request object.
149: */
150: public Map getParameterMap() {
151: return this .request.getParameterMap();
152: }
153:
154: /**
155: * The default behavior of this method is to return getParameterNames()
156: * on the wrapped request object.
157: */
158:
159: public Enumeration getParameterNames() {
160: return this .request.getParameterNames();
161: }
162:
163: /**
164: * The default behavior of this method is to return getParameterValues(String name)
165: * on the wrapped request object.
166: */
167: public String[] getParameterValues(String name) {
168: return this .request.getParameterValues(name);
169: }
170:
171: /**
172: * The default behavior of this method is to return getProtocol()
173: * on the wrapped request object.
174: */
175:
176: public String getProtocol() {
177: return this .request.getProtocol();
178: }
179:
180: /**
181: * The default behavior of this method is to return getScheme()
182: * on the wrapped request object.
183: */
184:
185: public String getScheme() {
186: return this .request.getScheme();
187: }
188:
189: /**
190: * The default behavior of this method is to return getServerName()
191: * on the wrapped request object.
192: */
193: public String getServerName() {
194: return this .request.getServerName();
195: }
196:
197: /**
198: * The default behavior of this method is to return getServerPort()
199: * on the wrapped request object.
200: */
201:
202: public int getServerPort() {
203: return this .request.getServerPort();
204: }
205:
206: /**
207: * The default behavior of this method is to return getReader()
208: * on the wrapped request object.
209: */
210:
211: public BufferedReader getReader() throws IOException {
212: return this .request.getReader();
213: }
214:
215: /**
216: * The default behavior of this method is to return getRemoteAddr()
217: * on the wrapped request object.
218: */
219:
220: public String getRemoteAddr() {
221: return this .request.getRemoteAddr();
222: }
223:
224: /**
225: * The default behavior of this method is to return getRemoteHost()
226: * on the wrapped request object.
227: */
228:
229: public String getRemoteHost() {
230: return this .request.getRemoteHost();
231: }
232:
233: /**
234: * The default behavior of this method is to return setAttribute(String name, Object o)
235: * on the wrapped request object.
236: */
237:
238: public void setAttribute(String name, Object o) {
239: this .request.setAttribute(name, o);
240: }
241:
242: /**
243: * The default behavior of this method is to call removeAttribute(String name)
244: * on the wrapped request object.
245: */
246: public void removeAttribute(String name) {
247: this .request.removeAttribute(name);
248: }
249:
250: /**
251: * The default behavior of this method is to return getLocale()
252: * on the wrapped request object.
253: */
254:
255: public Locale getLocale() {
256: return this .request.getLocale();
257: }
258:
259: /**
260: * The default behavior of this method is to return getLocales()
261: * on the wrapped request object.
262: */
263:
264: public Enumeration getLocales() {
265: return this .request.getLocales();
266: }
267:
268: /**
269: * The default behavior of this method is to return isSecure()
270: * on the wrapped request object.
271: */
272:
273: public boolean isSecure() {
274: return this .request.isSecure();
275: }
276:
277: /**
278: * The default behavior of this method is to return getRequestDispatcher(String path)
279: * on the wrapped request object.
280: */
281:
282: public RequestDispatcher getRequestDispatcher(String path) {
283: return this .request.getRequestDispatcher(path);
284: }
285:
286: /**
287: * The default behavior of this method is to return getRealPath(String path)
288: * on the wrapped request object.
289: */
290:
291: public String getRealPath(String path) {
292: return this .request.getRealPath(path);
293: }
294:
295: /**
296: * The default behavior of this method is to return
297: * getRemotePort() on the wrapped request object.
298: *
299: * @since 2.4
300: */
301: public int getRemotePort() {
302: return this .request.getRemotePort();
303: }
304:
305: /**
306: * The default behavior of this method is to return
307: * getLocalName() on the wrapped request object.
308: *
309: * @since 2.4
310: */
311: public String getLocalName() {
312: return this .request.getLocalName();
313: }
314:
315: /**
316: * The default behavior of this method is to return
317: * getLocalAddr() on the wrapped request object.
318: *
319: * @since 2.4
320: */
321: public String getLocalAddr() {
322: return this .request.getLocalAddr();
323: }
324:
325: /**
326: * The default behavior of this method is to return
327: * getLocalPort() on the wrapped request object.
328: *
329: * @since 2.4
330: */
331: public int getLocalPort() {
332: return this.request.getLocalPort();
333: }
334:
335: }
|