001: /*
002: * Copyright 1999-2004 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.commons.chain.web.servlet;
017:
018: import javax.servlet.RequestDispatcher;
019: import javax.servlet.Servlet;
020: import javax.servlet.ServletContext;
021: import javax.servlet.ServletException;
022: import java.io.InputStream;
023: import java.net.MalformedURLException;
024: import java.net.URL;
025: import java.util.Enumeration;
026: import java.util.Hashtable;
027: import java.util.Set;
028:
029: // Mock Object for ServletContext (Version 2.3)
030: public class MockServletContext implements ServletContext {
031:
032: private Hashtable attributes = new Hashtable();
033: private Hashtable parameters = new Hashtable();
034:
035: // --------------------------------------------------------- Public Methods
036:
037: public void addInitParameter(String name, String value) {
038: parameters.put(name, value);
039: }
040:
041: // ------------------------------------------------- ServletContext Methods
042:
043: public Object getAttribute(String name) {
044: return (attributes.get(name));
045: }
046:
047: public Enumeration getAttributeNames() {
048: return (attributes.keys());
049: }
050:
051: public ServletContext getContext(String uripath) {
052: throw new UnsupportedOperationException();
053: }
054:
055: public String getInitParameter(String name) {
056: return ((String) parameters.get(name));
057: }
058:
059: public Enumeration getInitParameterNames() {
060: return (parameters.keys());
061: }
062:
063: public int getMajorVersion() {
064: return (2);
065: }
066:
067: public String getMimeType(String path) {
068: throw new UnsupportedOperationException();
069: }
070:
071: public int getMinorVersion() {
072: return (3);
073: }
074:
075: public RequestDispatcher getNamedDispatcher(String name) {
076: throw new UnsupportedOperationException();
077: }
078:
079: public String getRealPath(String path) {
080: throw new UnsupportedOperationException();
081: }
082:
083: public RequestDispatcher getRequestDispatcher(String path) {
084: throw new UnsupportedOperationException();
085: }
086:
087: public URL getResource(String path) throws MalformedURLException {
088: throw new UnsupportedOperationException();
089: }
090:
091: public InputStream getResourceAsStream(String path) {
092: throw new UnsupportedOperationException();
093: }
094:
095: public Set getResourcePaths(String path) {
096: throw new UnsupportedOperationException();
097: }
098:
099: public Servlet getServlet(String name) throws ServletException {
100: throw new UnsupportedOperationException();
101: }
102:
103: public String getServletContextName() {
104: return ("MockServletContext");
105: }
106:
107: public String getServerInfo() {
108: return ("MockServletContext");
109: }
110:
111: public Enumeration getServlets() {
112: throw new UnsupportedOperationException();
113: }
114:
115: public Enumeration getServletNames() {
116: throw new UnsupportedOperationException();
117: }
118:
119: public void log(String message) {
120: throw new UnsupportedOperationException();
121: }
122:
123: public void log(Exception exception, String message) {
124: throw new UnsupportedOperationException();
125: }
126:
127: public void log(String message, Throwable exception) {
128: throw new UnsupportedOperationException();
129: }
130:
131: public void removeAttribute(String name) {
132: attributes.remove(name);
133: }
134:
135: public void setAttribute(String name, Object value) {
136: attributes.put(name, value);
137: }
138:
139: }
|