01: package com.mockrunner.mock.web;
02:
03: import java.util.Enumeration;
04: import java.util.HashMap;
05: import java.util.Map;
06: import java.util.Vector;
07:
08: import javax.servlet.ServletConfig;
09: import javax.servlet.ServletContext;
10:
11: /**
12: * Mock implementation of <code>ServletConfig</code>.
13: */
14: public class MockServletConfig implements ServletConfig {
15: private ServletContext servletContext;
16: private Map initParameters;
17: private String servletName;
18:
19: public MockServletConfig() {
20: initParameters = new HashMap();
21: }
22:
23: public synchronized String getServletName() {
24: return servletName;
25: }
26:
27: public synchronized void setServletName(String servletName) {
28: this .servletName = servletName;
29: }
30:
31: public synchronized ServletContext getServletContext() {
32: return servletContext;
33: }
34:
35: /**
36: * Sets the <code>ServletContext</code>.
37: * @param servletContext the <code>ServletContext</code>
38: */
39: public synchronized void setServletContext(
40: ServletContext servletContext) {
41: this .servletContext = servletContext;
42: }
43:
44: /**
45: * Clears the init parameters.
46: */
47: public synchronized void clearInitParameters() {
48: initParameters.clear();
49: }
50:
51: public synchronized String getInitParameter(String name) {
52: return (String) initParameters.get(name);
53: }
54:
55: /**
56: * Sets an init parameter.
57: * @param name the name
58: * @param value the value
59: */
60: public synchronized void setInitParameter(String name, String value) {
61: initParameters.put(name, value);
62: }
63:
64: /**
65: * Sets several init parameters.
66: * @param parameters the parameter map
67: */
68: public synchronized void setInitParameters(Map parameters) {
69: initParameters.putAll(parameters);
70: }
71:
72: public synchronized Enumeration getInitParameterNames() {
73: return new Vector(initParameters.keySet()).elements();
74: }
75: }
|