1
|
|
/* Generated by AspectJ version 1.0.5 */
|
2
|
|
package org.apache.cactus.server;
|
3
|
|
import java.util.Enumeration;
|
4
|
|
import java.util.Hashtable;
|
5
|
|
import java.util.Vector;
|
6
|
|
import javax.servlet.ServletConfig;
|
7
|
|
import javax.servlet.ServletContext;
|
8
|
|
|
9
|
|
/**
|
10
|
|
* Wrapper around <code>ServletConfig</code> which overrides the
|
11
|
|
* <code>getServletContext()</code> method to return our own wrapper around
|
12
|
|
* <code>ServletContext</code>.
|
13
|
|
*
|
14
|
|
* @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
|
15
|
|
*
|
16
|
|
* @version $Id: ServletConfigWrapper.java,v 1.2 2002/04/14 10:15:03 vmassol Exp $
|
17
|
|
* @see ServletContext
|
18
|
|
*/
|
19
|
|
public class ServletConfigWrapper implements ServletConfig {
|
20
|
|
/**
|
21
|
|
* The original servlet config object
|
22
|
|
*/
|
23
|
|
private ServletConfig originalConfig;
|
24
|
|
/**
|
25
|
|
* List of parameters set using the <code>setInitParameter()</code> method.
|
26
|
|
*/
|
27
|
|
private Hashtable initParameters;
|
28
|
|
/**
|
29
|
|
* Simulated name of the servlet
|
30
|
|
*/
|
31
|
|
private String servletName;
|
32
|
|
/**
|
33
|
|
* @param theOriginalConfig the original servlet config object
|
34
|
|
*/
|
35
|
177
|
public ServletConfigWrapper(ServletConfig theOriginalConfig) {
|
36
|
177
|
super();
|
37
|
177
|
this.originalConfig = theOriginalConfig;
|
38
|
177
|
this.initParameters = new Hashtable();
|
39
|
|
}
|
40
|
|
/**
|
41
|
|
* Sets a parameter as if it were set in the <code>web.xml</code> file.
|
42
|
|
*
|
43
|
|
* @param theName the parameter's name
|
44
|
|
* @param theValue the parameter's value
|
45
|
|
*/
|
46
|
3
|
public void setInitParameter(String theName, String theValue) {
|
47
|
3
|
this.initParameters.put(theName, theValue);
|
48
|
|
}
|
49
|
|
|
50
|
|
/**
|
51
|
|
* Sets the servlet name. That will be the value returned by the
|
52
|
|
* <code>getServletName()</code> method.
|
53
|
|
*
|
54
|
|
* @param theServletName the servlet's name
|
55
|
|
*/
|
56
|
3
|
public void setServletName(String theServletName) {
|
57
|
3
|
this.servletName = theServletName;
|
58
|
|
}
|
59
|
|
|
60
|
|
/**
|
61
|
|
* @return our own wrapped servlet context object
|
62
|
|
*/
|
63
|
18
|
public ServletContext getServletContext() {
|
64
|
18
|
return new ServletContextWrapper(this.originalConfig.getServletContext());
|
65
|
|
}
|
66
|
|
|
67
|
|
/**
|
68
|
|
* @param theName the name of the parameter's value to return
|
69
|
|
* @return the value of the parameter, looking for it first in the list of
|
70
|
|
* parameters set using the <code>setInitParameter()</code> method
|
71
|
|
* and then in those set in <code>web.xml</code>.
|
72
|
|
*/
|
73
|
15
|
public String getInitParameter(String theName) {
|
74
|
15
|
String value = (String)this.initParameters.get(theName);
|
75
|
15
|
if (value == null) {
|
76
|
12
|
value = this.originalConfig.getInitParameter(theName);
|
77
|
|
}
|
78
|
15
|
return value;
|
79
|
|
}
|
80
|
|
|
81
|
|
/**
|
82
|
|
* @return the union of the parameters defined in the Redirector
|
83
|
|
* <code>web.xml</code> file and the one set using the
|
84
|
|
* <code>setInitParameter()</code> method.
|
85
|
|
*/
|
86
|
3
|
public Enumeration getInitParameterNames() {
|
87
|
3
|
Vector names = new Vector();
|
88
|
3
|
Enumeration enum = this.initParameters.keys();
|
89
|
3
|
while (enum.hasMoreElements()){
|
90
|
3
|
String value = (String)enum.nextElement();
|
91
|
3
|
names.add(value);
|
92
|
|
}
|
93
|
3
|
enum = this.originalConfig.getInitParameterNames();
|
94
|
3
|
while (enum.hasMoreElements()){
|
95
|
3
|
String value = (String)enum.nextElement();
|
96
|
3
|
names.add(value);
|
97
|
|
}
|
98
|
3
|
return names.elements();
|
99
|
|
}
|
100
|
|
|
101
|
|
/**
|
102
|
|
* @return the simulated servlet's name if defined or the redirector
|
103
|
|
* servlet's name
|
104
|
|
*/
|
105
|
5
|
public String getServletName() {
|
106
|
5
|
if (this.servletName != null) {
|
107
|
3
|
return this.servletName;
|
108
|
|
}
|
109
|
2
|
return this.originalConfig.getServletName();
|
110
|
|
}
|
111
|
|
|
112
|
|
}
|