KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > tui > MockServletContext


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/tui/MockServletContext.java#5 $
3 // This software is subject to the terms of the Common Public License
4 // Agreement, available at the following URL:
5 // http://www.opensource.org/licenses/cpl.html.
6 // Copyright (C) 2005-2006 Julian Hyde and others
7 // All Rights Reserved.
8 // You must accept the terms of that agreement to use this software.
9 */

10
11 package mondrian.tui;
12
13 import java.io.InputStream JavaDoc;
14 import java.util.HashMap JavaDoc;
15 import java.util.Set JavaDoc;
16 import java.util.Map JavaDoc;
17 import java.util.Properties JavaDoc;
18 import java.util.Enumeration JavaDoc;
19 import java.util.Collections JavaDoc;
20 import java.net.URL JavaDoc;
21 import java.net.MalformedURLException JavaDoc;
22 import javax.servlet.Servlet JavaDoc;
23 import javax.servlet.ServletException JavaDoc;
24 import javax.servlet.ServletContext JavaDoc;
25 import javax.servlet.RequestDispatcher JavaDoc;
26
27 /**
28  * This is a partial implementation of the ServletContext where just
29  * enough is present to allow for communication between Mondrian's
30  * XMLA code and other code in the same JVM.
31  * Currently it is used in both the CmdRunner and in XMLA JUnit tests.
32  * <p>
33  * If you need to add to this implementation, please do so.
34  *
35  * @author <a>Richard M. Emberson</a>
36  * @version $Id: //open/mondrian/src/main/mondrian/tui/MockServletContext.java#5 $
37  */

38 public class MockServletContext implements ServletContext JavaDoc {
39
40     public static final String JavaDoc PARAM_DATASOURCES_CONFIG = "DataSourcesConfig";
41     public static final String JavaDoc PARAM_CHAR_ENCODING = "CharacterEncoding";
42     public static final String JavaDoc PARAM_CALLBACKS = "Callbacks";
43
44     private Map JavaDoc<String JavaDoc, URL JavaDoc> resources;
45     private Map JavaDoc<String JavaDoc, Object JavaDoc> attributes;
46     private int majorVersion;
47     private int minorVersion;
48     private Properties JavaDoc parameters;
49
50     public MockServletContext() {
51         this.majorVersion = 1;
52         this.minorVersion = 1;
53         this.resources = Collections.emptyMap();
54         this.attributes = Collections.emptyMap();
55         this.parameters = new Properties JavaDoc();
56     }
57
58
59     /**
60      * Returns a ServletContext object that corresponds to a specified URL on
61      * the server.
62      *
63      */

64     public ServletContext JavaDoc getContext(String JavaDoc s) {
65         // TODO
66
return null;
67     }
68
69     /**
70      * Returns the major version of the Java Servlet API that this servlet
71      * container supports.
72      *
73      */

74     public int getMajorVersion() {
75         return this.majorVersion;
76     }
77
78     /**
79      * Returns the minor version of the Servlet API that this servlet container
80      * supports.
81      *
82      */

83     public int getMinorVersion() {
84         return this.minorVersion;
85     }
86
87     /**
88      * Returns the MIME type of the specified file, or null if the MIME type is
89      * not known.
90      *
91      */

92     public String JavaDoc getMimeType(String JavaDoc s) {
93         // TODO
94
return null;
95     }
96
97     /**
98      *
99      *
100      */

101     public Set JavaDoc getResourcePaths(String JavaDoc s) {
102         // TODO
103
return null;
104     }
105
106     /**
107      * Returns a URL to the resource that is mapped to a specified path.
108      *
109      */

110     public URL JavaDoc getResource(String JavaDoc name) throws MalformedURLException JavaDoc {
111         return resources.get(name);
112     }
113
114     /**
115      * Returns the resource located at the named path as an InputStream object.
116      *
117      */

118     public InputStream JavaDoc getResourceAsStream(String JavaDoc s) {
119         // TODO
120
return null;
121     }
122
123     /**
124      * Returns a RequestDispatcher object that acts as a wrapper for the
125      * resource located at the given path.
126      *
127      */

128     public RequestDispatcher JavaDoc getRequestDispatcher(String JavaDoc s) {
129         // TODO
130
return null;
131     }
132
133     /**
134      * Returns a RequestDispatcher object that acts as a wrapper for the named
135      * servlet.
136      *
137      */

138     public RequestDispatcher JavaDoc getNamedDispatcher(String JavaDoc s) {
139         // TODO
140
return null;
141     }
142
143     /**
144      * Deprecated. As of Java Servlet API 2.1, with no direct replacement.
145      *
146      * This method was originally defined to retrieve a servlet from a
147      * ServletContext. In this version, this method always returns null and
148      * remains only to preserve binary compatibility. This method will be
149      * permanently removed in a future version of the Java Servlet API.
150      *
151      * In lieu of this method, servlets can share information using the
152      * ServletContext class and can perform shared business logic by invoking
153      * methods on common non-servlet classes.
154      *
155      * @deprecated Method getServlet is deprecated
156      */

157
158     public Servlet JavaDoc getServlet(String JavaDoc s) throws ServletException JavaDoc {
159         // TODO
160
return null;
161     }
162
163     /**
164      * Deprecated. As of Java Servlet API 2.0, with no replacement.
165      *
166      * This method was originally defined to return an Enumeration of all the
167      * servlets known to this servlet context. In this version, this method
168      * always returns an empty enumeration and remains only to preserve binary
169      * compatibility. This method will be permanently removed in a future
170      * version of the Java Servlet API.
171      *
172      * @deprecated Method getServlets is deprecated
173      * @return
174      */

175     public Enumeration JavaDoc getServlets() {
176         // TODO
177
return null;
178     }
179
180     /**
181      * Deprecated. As of Java Servlet API 2.1, with no replacement.
182      *
183      * This method was originally defined to return an Enumeration of all the
184      * servlet names known to this context. In this version, this method always
185      * returns an empty Enumeration and remains only to preserve binary
186      * compatibility. This method will be permanently removed in a future
187      * version of the Java Servlet API.
188      *
189      * @deprecated Method getServletNames is deprecated
190      * @return
191      */

192     public Enumeration JavaDoc getServletNames() {
193         // TODO
194
return null;
195     }
196
197     /**
198      * Writes the specified message to a servlet log file, usually an event log.
199      *
200      */

201     public void log(String JavaDoc s) {
202         // TODO
203
}
204
205     /**
206      * Deprecated. As of Java Servlet API 2.1, use log(String message, Throwable
207      * throwable) instead.
208      *
209      * This method was originally defined to write an exception's stack trace
210      * and an explanatory error message to the servlet log file.
211      *
212      * @deprecated Method log is deprecated
213      */

214     public void log(Exception JavaDoc exception, String JavaDoc s) {
215         log(s, exception);
216     }
217
218     /**
219      * Writes an explanatory message and a stack trace for a given Throwable
220      * exception to the servlet log file.
221      *
222      */

223     public void log(String JavaDoc s, Throwable JavaDoc throwable) {
224         // TODO
225
}
226
227     /**
228      * Returns a String containing the real path for a given virtual path.
229      *
230      */

231     public String JavaDoc getRealPath(String JavaDoc path) {
232         return path;
233     }
234
235     /**
236      * Returns the name and version of the servlet container on which the
237      * servlet is running.
238      *
239      */

240     public String JavaDoc getServerInfo() {
241         // TODO
242
return null;
243     }
244
245     /**
246      * Returns a String containing the value of the named context-wide
247      * initialization parameter, or null if the parameter does not exist.
248      *
249      */

250     public String JavaDoc getInitParameter(String JavaDoc name) {
251         return parameters.getProperty(name);
252     }
253
254     /**
255      * Returns the names of the context's initialization parameters as an
256      * Enumeration of String objects, or an empty Enumeration if the context has
257      * no initialization parameters.
258      *
259      */

260     public Enumeration JavaDoc getInitParameterNames() {
261         return parameters.propertyNames();
262     }
263
264     /**
265      *
266      *
267      */

268     public Object JavaDoc getAttribute(String JavaDoc s) {
269         return this.attributes.get(s);
270     }
271
272     /**
273      * Returns an Enumeration containing the attribute names available within
274      * this servlet context.
275      *
276      */

277     public Enumeration JavaDoc getAttributeNames() {
278         // TODO
279
return Collections.enumeration(this.attributes.keySet());
280     }
281
282     /**
283      * Binds an object to a given attribute name in this servlet context.
284      *
285      */

286     public void setAttribute(String JavaDoc s, Object JavaDoc obj) {
287         if (this.attributes == Collections.EMPTY_MAP) {
288             this.attributes = new HashMap JavaDoc<String JavaDoc, Object JavaDoc>();
289         }
290         this.attributes.put(s, obj);
291     }
292
293     /**
294      * Removes the attribute with the given name from the servlet context.
295      *
296      */

297     public void removeAttribute(String JavaDoc s) {
298         this.attributes.remove(s);
299     }
300
301     /**
302      *
303      *
304      */

305     public String JavaDoc getServletContextName() {
306         // TODO
307
return null;
308     }
309
310
311
312
313     /////////////////////////////////////////////////////////////////////////
314
//
315
// implementation access
316
//
317
/////////////////////////////////////////////////////////////////////////
318
public void setMajorVersion(int majorVersion) {
319         this.majorVersion = majorVersion;
320     }
321     public void setMinorVersion(int minorVersion) {
322         this.minorVersion = minorVersion;
323     }
324     public void addResource(String JavaDoc name, URL JavaDoc url) {
325         if (this.resources == Collections.EMPTY_MAP) {
326             this.resources = new HashMap JavaDoc<String JavaDoc, URL JavaDoc>();
327         }
328         this.resources.put(name, url);
329     }
330     public void addInitParameter(String JavaDoc name, String JavaDoc value) {
331         if (value != null) {
332             this.parameters.setProperty(name, value);
333         }
334     }
335 }
336
Popular Tags