KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > junit > internal > http > ServletContextWrapper


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.junit.internal.http;
8
9
10 import java.io.InputStream JavaDoc;
11 import java.net.URL JavaDoc;
12 import java.net.MalformedURLException JavaDoc;
13 import java.util.Enumeration JavaDoc;
14 import java.util.Set JavaDoc;
15
16 import javax.servlet.RequestDispatcher JavaDoc;
17 import javax.servlet.Servlet JavaDoc;
18 import javax.servlet.ServletContext JavaDoc;
19 import javax.servlet.ServletException JavaDoc;
20
21
22 /**
23  * A dummy servlet context object that simply forwards all
24  * request to a wrapped version of the actual servlet context.
25  * This allows for greater flexibility when testing. For
26  * example, if the a test needs to be run that changes the
27  * context, however, those changes should not be apparent
28  * to the next test, then a sub-class of this class could
29  * simply use a local hash for all the context attributes.
30  *
31  * @author Brian Pontarelli
32  * @since 1.0
33  * @version 1.0
34  */

35 public class ServletContextWrapper implements ServletContext JavaDoc {
36     
37     /**
38      * The dummy and wrapped context
39      */

40     protected ServletContext JavaDoc context;
41     
42
43     /**
44      * Constructs a new wrapper that wraps the given context
45      *
46      * @param context The context to wrap
47      */

48     public ServletContextWrapper(ServletContext JavaDoc context) {
49         this.context = context;
50     }
51     
52
53     /**
54      * Returns the original context
55      */

56     public ServletContext JavaDoc getWrappedContext() {
57         return context;
58     }
59
60     /** Forwards to the wrapped context */
61     public Object JavaDoc getAttribute(String JavaDoc name) {
62         return context.getAttribute(name);
63     }
64
65     /** Forwards to the wrapped context */
66     public Enumeration JavaDoc getAttributeNames() {
67         return context.getAttributeNames();
68     }
69
70     /** Forwards to the wrapped context */
71     public ServletContext JavaDoc getContext(String JavaDoc url) {
72         return context.getContext(url);
73     }
74
75     /** Forwards to the wrapped context */
76     public String JavaDoc getInitParameter(String JavaDoc name) {
77         return context.getInitParameter(name);
78     }
79
80     /** Forwards to the wrapped context */
81     public Enumeration JavaDoc getInitParameterNames() {
82         return context.getInitParameterNames();
83     }
84
85     /** Forwards to the wrapped context */
86     public int getMajorVersion() {
87         return context.getMajorVersion();
88     }
89
90     /** Forwards to the wrapped context */
91     public String JavaDoc getMimeType(String JavaDoc type) {
92         return context.getMimeType(type);
93     }
94
95     /** Forwards to the wrapped context */
96     public int getMinorVersion() {
97         return context.getMinorVersion();
98     }
99
100     /** Forwards to the wrapped context */
101     public RequestDispatcher JavaDoc getNamedDispatcher(String JavaDoc name) {
102         return context.getNamedDispatcher(name);
103     }
104
105     /** Forwards to the wrapped context */
106     public String JavaDoc getRealPath(String JavaDoc url) {
107         return context.getRealPath(url);
108     }
109
110     /** Forwards to the wrapped context */
111     public RequestDispatcher JavaDoc getRequestDispatcher(String JavaDoc url) {
112         return context.getRequestDispatcher(url);
113     }
114
115     /** Forwards to the wrapped context */
116     public URL JavaDoc getResource(String JavaDoc path) throws MalformedURLException JavaDoc {
117         return context.getResource(path);
118     }
119
120     /** Forwards to the wrapped context */
121     public InputStream JavaDoc getResourceAsStream(String JavaDoc path) {
122         return context.getResourceAsStream(path);
123     }
124
125     /** Forwards to the wrapped context */
126     public Set JavaDoc getResourcePaths(String JavaDoc path) {
127         return context.getResourcePaths(path);
128     }
129
130     /** Forwards to the wrapped context */
131     public String JavaDoc getServerInfo() {
132         return context.getServerInfo();
133     }
134
135     /**
136      * @deprecated
137      */

138     public Servlet JavaDoc getServlet(String JavaDoc name) throws ServletException JavaDoc {
139         return context.getServlet(name);
140     }
141
142     /** Forwards to the wrapped context */
143     public String JavaDoc getServletContextName() {
144         return context.getServletContextName();
145     }
146
147     /**
148      * @deprecated
149      */

150     public Enumeration JavaDoc getServletNames() {
151         return context.getServletNames();
152     }
153
154     /**
155      * @deprecated
156      */

157     public Enumeration JavaDoc getServlets() {
158         return context.getServlets();
159     }
160
161     /**
162      * @deprecated
163      */

164     public void log(Exception JavaDoc exception, String JavaDoc msg) {
165         context.log(exception, msg);
166     }
167
168     /** Forwards to the wrapped context */
169     public void log(String JavaDoc msg) {
170         context.log(msg);
171     }
172
173     /** Forwards to the wrapped context */
174     public void log(String JavaDoc msg, Throwable JavaDoc throwable) {
175         context.log(msg, throwable);
176     }
177
178     /** Forwards to the wrapped context */
179     public void removeAttribute(String JavaDoc name) {
180         context.removeAttribute(name);
181     }
182
183     /** Forwards to the wrapped context */
184     public void setAttribute(String JavaDoc name, Object JavaDoc value) {
185         context.setAttribute(name, value);
186     }
187 }
188
Popular Tags