KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > servletunit > ServletConfigSimulator


1 package servletunit;
2
3 // StrutsTestCase - a JUnit extension for testing Struts actions
4
// within the context of the ActionServlet.
5
// Copyright (C) 2002 Deryl Seale
6
//
7
// This library is free software; you can redistribute it and/or
8
// modify it under the terms of the Apache Software License as
9
// published by the Apache Software Foundation; either version 1.1
10
// of the License, or (at your option) any later version.
11
//
12
// This library is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// Apache Software Foundation Licens for more details.
16
//
17
// You may view the full text here: http://www.apache.org/LICENSE.txt
18

19 import javax.servlet.ServletConfig JavaDoc;
20 import javax.servlet.ServletContext JavaDoc;
21 import java.util.Enumeration JavaDoc;
22 import java.util.Hashtable JavaDoc;
23
24 /**
25  * This class simulates a ServletConfig.
26  */

27
28 public class ServletConfigSimulator implements ServletConfig JavaDoc
29 {
30
31     private Hashtable JavaDoc parameters;
32     private ServletContext JavaDoc context;
33
34     public ServletConfigSimulator()
35     {
36         parameters=new Hashtable JavaDoc();
37         context = new ServletContextSimulator();
38     }
39
40     /**
41      * Returns a <code>String</code> containing the value of the
42      * named initialization parameter, or <code>null</code> if
43      * the parameter does not exist.
44      *
45      * @param name a <code>String</code> specifying the name
46      * of the initialization parameter
47      *
48      * @return a <code>String</code> containing the value
49      * of the initialization parameter
50      *
51      */

52     public String JavaDoc getInitParameter(String JavaDoc name)
53     {
54         return (String JavaDoc) parameters.get(name);
55     }
56
57     /**
58      * Returns the names of the servlet's initialization parameters
59      * as an <code>Enumeration</code> of <code>String</code> objects,
60      * or an empty <code>Enumeration</code> if the servlet has
61      * no initialization parameters.
62      *
63      * @return an <code>Enumeration</code> of <code>String</code>
64      * objects containing the names of the servlet's
65      * initialization parameters
66      *
67      *
68      *
69      */

70     public Enumeration JavaDoc getInitParameterNames()
71     {
72         return parameters.keys();
73     }
74
75     /**
76      * Returns a reference to the {@link ServletContext} in which the caller
77      * is executing.
78      *
79      *
80      * @return a {@link ServletContext} object, used
81      * by the caller to interact with its servlet
82      * container
83      *
84      * @see ServletContext
85      *
86      */

87     public ServletContext JavaDoc getServletContext()
88     {
89         return context;
90     }
91
92     /**
93      * Returns the name of this servlet instance.
94      * The name may be provided via server administration, assigned in the
95      * web application deployment descriptor, or for an unregistered (and thus
96      * unnamed) servlet instance it will be the servlet's class name.
97      *
98      * @return the String "ActionServlet"
99      *
100      *
101      *
102      */

103     public String JavaDoc getServletName()
104     {
105         return "ActionServlet";
106     }
107
108     /**
109      * Sets a named initialization parameter with the supplied
110      * <code>String</code> value.
111      *
112      * @param key a <code>String</code> specifying the name
113      * of the initialization parameter
114      *
115      * @param value a <code>String</code> value for this initialization
116      * parameter
117      *
118      */

119     public void setInitParameter(String JavaDoc key,String JavaDoc value)
120     {
121         parameters.put(key,value);
122     }
123
124 }
125
126
Popular Tags