KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > chain > web > servlet > MockServletContext


1 /*
2  * Copyright 1999-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.commons.chain.web.servlet;
17
18
19 import javax.servlet.RequestDispatcher JavaDoc;
20 import javax.servlet.Servlet JavaDoc;
21 import javax.servlet.ServletContext JavaDoc;
22 import javax.servlet.ServletException JavaDoc;
23 import java.io.InputStream JavaDoc;
24 import java.net.MalformedURLException JavaDoc;
25 import java.net.URL JavaDoc;
26 import java.util.Enumeration JavaDoc;
27 import java.util.Hashtable JavaDoc;
28 import java.util.Set JavaDoc;
29
30
31 // Mock Object for ServletContext (Version 2.3)
32
public class MockServletContext implements ServletContext JavaDoc {
33
34
35     private Hashtable JavaDoc attributes = new Hashtable JavaDoc();
36     private Hashtable JavaDoc parameters = new Hashtable JavaDoc();
37
38
39     // --------------------------------------------------------- Public Methods
40

41
42     public void addInitParameter(String JavaDoc name, String JavaDoc value) {
43         parameters.put(name, value);
44     }
45
46
47     // ------------------------------------------------- ServletContext Methods
48

49
50     public Object JavaDoc getAttribute(String JavaDoc name) {
51         return (attributes.get(name));
52     }
53
54     public Enumeration JavaDoc getAttributeNames() {
55         return (attributes.keys());
56     }
57
58     public ServletContext JavaDoc getContext(String JavaDoc uripath) {
59         throw new UnsupportedOperationException JavaDoc();
60     }
61
62     public String JavaDoc getInitParameter(String JavaDoc name) {
63         return ((String JavaDoc) parameters.get(name));
64     }
65
66     public Enumeration JavaDoc getInitParameterNames() {
67         return (parameters.keys());
68     }
69
70     public int getMajorVersion() {
71         return (2);
72     }
73
74     public String JavaDoc getMimeType(String JavaDoc path) {
75         throw new UnsupportedOperationException JavaDoc();
76     }
77
78     public int getMinorVersion() {
79         return (3);
80     }
81
82     public RequestDispatcher JavaDoc getNamedDispatcher(String JavaDoc name) {
83         throw new UnsupportedOperationException JavaDoc();
84     }
85
86     public String JavaDoc getRealPath(String JavaDoc path) {
87         throw new UnsupportedOperationException JavaDoc();
88     }
89
90     public RequestDispatcher JavaDoc getRequestDispatcher(String JavaDoc path) {
91         throw new UnsupportedOperationException JavaDoc();
92     }
93
94     public URL JavaDoc getResource(String JavaDoc path) throws MalformedURLException JavaDoc {
95         throw new UnsupportedOperationException JavaDoc();
96     }
97
98     public InputStream JavaDoc getResourceAsStream(String JavaDoc path) {
99         throw new UnsupportedOperationException JavaDoc();
100     }
101
102     public Set JavaDoc getResourcePaths(String JavaDoc path) {
103         throw new UnsupportedOperationException JavaDoc();
104     }
105
106     public Servlet JavaDoc getServlet(String JavaDoc name) throws ServletException JavaDoc {
107         throw new UnsupportedOperationException JavaDoc();
108     }
109
110     public String JavaDoc getServletContextName() {
111         return ("MockServletContext");
112     }
113
114     public String JavaDoc getServerInfo() {
115         return ("MockServletContext");
116     }
117
118     public Enumeration JavaDoc getServlets() {
119         throw new UnsupportedOperationException JavaDoc();
120     }
121
122     public Enumeration JavaDoc getServletNames() {
123         throw new UnsupportedOperationException JavaDoc();
124     }
125
126     public void log(String JavaDoc message) {
127         throw new UnsupportedOperationException JavaDoc();
128     }
129
130     public void log(Exception JavaDoc exception, String JavaDoc message) {
131         throw new UnsupportedOperationException JavaDoc();
132     }
133
134     public void log(String JavaDoc message, Throwable JavaDoc exception) {
135         throw new UnsupportedOperationException JavaDoc();
136     }
137
138     public void removeAttribute(String JavaDoc name) {
139         attributes.remove(name);
140     }
141
142     public void setAttribute(String JavaDoc name, Object JavaDoc value) {
143         attributes.put(name, value);
144     }
145
146
147 }
148
Popular Tags