KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > context > servlet > ServletContextMockImpl


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

16 package org.apache.myfaces.context.servlet;
17
18 import org.apache.myfaces.util.IteratorEnumeration;
19
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22
23 import javax.servlet.RequestDispatcher JavaDoc;
24 import javax.servlet.Servlet JavaDoc;
25 import javax.servlet.ServletContext JavaDoc;
26 import javax.servlet.ServletException JavaDoc;
27 import java.io.InputStream JavaDoc;
28 import java.net.MalformedURLException JavaDoc;
29 import java.net.URL JavaDoc;
30 import java.util.*;
31
32 /**
33  * DOCUMENT ME!
34  * @author Manfred Geiler (latest modification by $Author: matze $)
35  * @author Anton Koinov
36  * @version $Revision: 1.3 $ $Date: 2004/10/13 11:50:59 $
37  */

38 public class ServletContextMockImpl
39     implements ServletContext JavaDoc
40 {
41     private static final Log log = LogFactory.getLog(ServletContextMockImpl.class);
42
43     private Map _attributes = new HashMap();
44     private Map _initParameters = new HashMap();
45     private Map _resourceMap = new HashMap();
46
47
48     public ServletContext JavaDoc getContext(String JavaDoc s)
49     {
50         throw new UnsupportedOperationException JavaDoc();
51     }
52
53     public int getMajorVersion()
54     {
55         throw new UnsupportedOperationException JavaDoc();
56     }
57
58     public int getMinorVersion()
59     {
60         throw new UnsupportedOperationException JavaDoc();
61     }
62
63     public String JavaDoc getMimeType(String JavaDoc s)
64     {
65         throw new UnsupportedOperationException JavaDoc();
66     }
67
68     public Set getResourcePaths(String JavaDoc s)
69     {
70         /* is this needed by any test?
71         if (s.equals("/WEB-INF/lib/"))
72         {
73             return Collections.singleton("/WEB-INF/lib/myfaces.jar");
74         }
75         else
76         {
77             return null;
78         }
79         */

80         return Collections.EMPTY_SET;
81     }
82
83     public URL JavaDoc getResource(String JavaDoc s) throws MalformedURLException JavaDoc
84     {
85         String JavaDoc path = (String JavaDoc)_resourceMap.get(s);
86         if (path != null)
87         {
88             return Thread.currentThread().getContextClassLoader()
89                     .getResource(path);
90         }
91         else
92         {
93             log.warn("Resource '" + s + "' cannot be resolved.");
94             return null;
95         }
96     }
97
98     public InputStream JavaDoc getResourceAsStream(String JavaDoc s)
99     {
100         String JavaDoc path = (String JavaDoc)_resourceMap.get(s);
101         if (path != null)
102         {
103             return Thread.currentThread().getContextClassLoader()
104                     .getResourceAsStream(path);
105         }
106         else
107         {
108             log.warn("Resource '" + s + "' cannot be resolved.");
109             return null;
110         }
111     }
112
113     public RequestDispatcher JavaDoc getRequestDispatcher(String JavaDoc s)
114     {
115         throw new UnsupportedOperationException JavaDoc();
116     }
117
118     public RequestDispatcher JavaDoc getNamedDispatcher(String JavaDoc s)
119     {
120         throw new UnsupportedOperationException JavaDoc();
121     }
122
123     public Servlet JavaDoc getServlet(String JavaDoc s) throws ServletException JavaDoc
124     {
125         throw new UnsupportedOperationException JavaDoc();
126     }
127
128     public Enumeration getServlets()
129     {
130         throw new UnsupportedOperationException JavaDoc();
131     }
132
133     public Enumeration getServletNames()
134     {
135         throw new UnsupportedOperationException JavaDoc();
136     }
137
138     public void log(String JavaDoc s)
139     {
140         throw new UnsupportedOperationException JavaDoc();
141     }
142
143     /**@deprecated*/
144     public void log(Exception JavaDoc exception, String JavaDoc s)
145     {
146         throw new UnsupportedOperationException JavaDoc();
147     }
148
149     public void log(String JavaDoc s, Throwable JavaDoc throwable)
150     {
151         throw new UnsupportedOperationException JavaDoc();
152     }
153
154     public String JavaDoc getRealPath(String JavaDoc s)
155     {
156         return "/junit_dummy_real_path";
157     }
158
159     public String JavaDoc getServerInfo()
160     {
161         throw new UnsupportedOperationException JavaDoc();
162     }
163
164     public String JavaDoc getInitParameter(String JavaDoc s)
165     {
166         return (String JavaDoc) _initParameters.get(s);
167     }
168
169     public Enumeration getInitParameterNames()
170     {
171         return new IteratorEnumeration(_initParameters.keySet().iterator());
172     }
173
174     public Object JavaDoc getAttribute(String JavaDoc s)
175     {
176         return _attributes.get(s);
177     }
178
179     public Enumeration getAttributeNames()
180     {
181         return new IteratorEnumeration(_attributes.keySet().iterator());
182     }
183
184     public void setAttribute(String JavaDoc s, Object JavaDoc obj)
185     {
186         _attributes.put(s, obj);
187     }
188
189     public void removeAttribute(String JavaDoc s)
190     {
191         _attributes.remove(s);
192     }
193
194     public String JavaDoc getServletContextName()
195     {
196         throw new UnsupportedOperationException JavaDoc();
197     }
198
199
200     // mock methods
201

202     public void addResource(String JavaDoc webPath, String JavaDoc classPath)
203     {
204         _resourceMap.put(webPath, classPath);
205     }
206
207
208 }
209
Popular Tags