01: package com.meterware.servletunit;
02:
03: /********************************************************************************************************************
04: * $Id: ServletUnitServletConfig.java,v 1.8 2004/09/24 19:13:37 russgold Exp $
05: *
06: * Copyright (c) 2000-2003, Russell Gold
07: *
08: * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
09: * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
10: * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
11: * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12: *
13: * The above copyright notice and this permission notice shall be included in all copies or substantial portions
14: * of the Software.
15: *
16: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
17: * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
19: * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20: * DEALINGS IN THE SOFTWARE.
21: *
22: *******************************************************************************************************************/
23: import java.util.Enumeration;
24: import java.util.Hashtable;
25:
26: import javax.servlet.Servlet;
27: import javax.servlet.ServletConfig;
28: import javax.servlet.ServletContext;
29:
30: /**
31: * This class acts as a test environment for servlets.
32: **/
33: class ServletUnitServletConfig implements ServletConfig {
34:
35: ServletUnitServletConfig(String name, WebApplication application,
36: Hashtable initParams) {
37: _name = name;
38: _initParameters = initParams;
39: _context = application.getServletContext();
40: }
41:
42: //-------------------------------------------- ServletConfig methods ---------------------------------------------------
43:
44: /**
45: * Returns the value of the specified init parameter, or null if no such init parameter is defined.
46: **/
47: public String getInitParameter(String name) {
48: return (String) _initParameters.get(name);
49: }
50:
51: /**
52: * Returns an enumeration over the names of the init parameters.
53: **/
54: public Enumeration getInitParameterNames() {
55: return _initParameters.keys();
56: }
57:
58: /**
59: * Returns the current servlet context.
60: **/
61: public ServletContext getServletContext() {
62: return _context;
63: }
64:
65: /**
66: * Returns the registered name of the servlet, or its class name if it is not registered.
67: **/
68: public java.lang.String getServletName() {
69: return _name;
70: }
71:
72: //----------------------------------------------- private members ------------------------------------------------------
73:
74: private String _name;
75:
76: private final Hashtable _initParameters;
77:
78: private final ServletContext _context;
79:
80: }
|