KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > mock > MockServletContext


1 /********************************************************************************
2  * CruiseControl, a Continuous Integration Toolkit
3  * Copyright (c) 2003, ThoughtWorks, Inc.
4  * 651 W Washington Ave. Suite 600
5  * Chicago, IL 60661 USA
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * + Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * + Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  *
20  * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
21  * names of its contributors may be used to endorse or promote
22  * products derived from this software without specific prior
23  * written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
29  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  ********************************************************************************/

37 package net.sourceforge.cruisecontrol.mock;
38
39 import java.net.URL JavaDoc;
40 import java.net.MalformedURLException JavaDoc;
41 import java.io.InputStream JavaDoc;
42 import java.io.File JavaDoc;
43 import java.io.FileInputStream JavaDoc;
44 import java.io.FileNotFoundException JavaDoc;
45 import java.util.Collections JavaDoc;
46 import java.util.Enumeration JavaDoc;
47 import java.util.HashMap JavaDoc;
48 import java.util.Map JavaDoc;
49
50 import javax.servlet.ServletContext JavaDoc;
51 import javax.servlet.RequestDispatcher JavaDoc;
52 import javax.servlet.Servlet JavaDoc;
53 import javax.servlet.ServletException JavaDoc;
54
55 /**
56  *
57  * @author <a HREF="mailto:robertdw@sourceforge.net">Robert Watkins</a>
58  */

59 public class MockServletContext implements ServletContext JavaDoc {
60     private File JavaDoc baseResourceDir;
61     private Map JavaDoc initParams = new HashMap JavaDoc();
62
63     public MockServletContext() {
64     }
65
66     public String JavaDoc getInitParameter(String JavaDoc name) {
67         return (String JavaDoc) initParams.get(name);
68     }
69
70     public void setInitParameter(String JavaDoc name, String JavaDoc value) {
71         initParams.put(name, value);
72     }
73
74     public ServletContext JavaDoc getContext(String JavaDoc s) {
75         return null;
76     }
77
78     public int getMajorVersion() {
79         return 0;
80     }
81
82     public int getMinorVersion() {
83         return 0;
84     }
85
86     public String JavaDoc getMimeType(String JavaDoc s) {
87         return null;
88     }
89
90     public URL JavaDoc getResource(String JavaDoc s) throws MalformedURLException JavaDoc {
91
92         // JDK1.4 use File.toURI().toURL() instead
93
return new URL JavaDoc(baseResourceDir.toURL(), s);
94     }
95
96     public InputStream JavaDoc getResourceAsStream(String JavaDoc resourceName) {
97         try {
98             return new FileInputStream JavaDoc(new File JavaDoc(baseResourceDir, resourceName));
99         } catch (FileNotFoundException JavaDoc e) {
100             return null;
101         }
102     }
103
104     public RequestDispatcher JavaDoc getRequestDispatcher(String JavaDoc s) {
105         return null;
106     }
107
108     public RequestDispatcher JavaDoc getNamedDispatcher(String JavaDoc s) {
109         return null;
110     }
111
112     public Servlet JavaDoc getServlet(String JavaDoc s) throws ServletException JavaDoc {
113         return null;
114     }
115
116     public Enumeration JavaDoc getServlets() {
117         return null;
118     }
119
120     public Enumeration JavaDoc getServletNames() {
121         return null;
122     }
123
124     public void log(String JavaDoc s) {
125     }
126
127     public void log(Exception JavaDoc e, String JavaDoc s) {
128     }
129
130     public void log(String JavaDoc s, Throwable JavaDoc throwable) {
131     }
132
133     public String JavaDoc getRealPath(String JavaDoc s) {
134         return null;
135     }
136
137     public String JavaDoc getServerInfo() {
138         return null;
139     }
140
141     public Enumeration JavaDoc getInitParameterNames() {
142         return Collections.enumeration(initParams.keySet());
143     }
144
145     public Object JavaDoc getAttribute(String JavaDoc s) {
146         return null;
147     }
148
149     public Enumeration JavaDoc getAttributeNames() {
150         return null;
151     }
152
153     public void setAttribute(String JavaDoc s, Object JavaDoc o) {
154     }
155
156     public void removeAttribute(String JavaDoc s) {
157     }
158
159     /**
160      * Set the base resource dir, for use with getResource and getResourceAsStream.
161      * @param dir the base directory
162      */

163     public void setBaseResourceDir(File JavaDoc dir) {
164         baseResourceDir = dir;
165     }
166 }
167
Popular Tags