KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > tui > MockServletConfig


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/tui/MockServletConfig.java#5 $
3 // This software is subject to the terms of the Common Public License
4 // Agreement, available at the following URL:
5 // http://www.opensource.org/licenses/cpl.html.
6 // Copyright (C) 2005-2006 Julian Hyde and others
7 // All Rights Reserved.
8 // You must accept the terms of that agreement to use this software.
9 */

10
11 package mondrian.tui;
12
13 import java.util.Map JavaDoc;
14 import java.util.HashMap JavaDoc;
15 import java.util.Enumeration JavaDoc;
16 import java.util.Collections JavaDoc;
17 import javax.servlet.ServletConfig JavaDoc;
18 import javax.servlet.ServletContext JavaDoc;
19
20 /**
21  * This is a partial implementation of the ServletConfig where just
22  * enough is present to allow for communication between Mondrian's
23  * XMLA code and other code in the same JVM.
24  * Currently it is used in both the CmdRunner and in XMLA JUnit tests.
25  * <p>
26  * If you need to add to this implementation, please do so.
27  *
28  * @author <a>Richard M. Emberson</a>
29  * @version $Id: //open/mondrian/src/main/mondrian/tui/MockServletConfig.java#5 $
30  */

31 public class MockServletConfig implements ServletConfig JavaDoc {
32     private String JavaDoc servletName;
33     private Map JavaDoc<String JavaDoc, String JavaDoc> initParams;
34     private ServletContext JavaDoc servletContext;
35
36     public MockServletConfig() {
37         this(null);
38     }
39     public MockServletConfig(ServletContext JavaDoc servletContext) {
40         this.initParams = new HashMap JavaDoc<String JavaDoc, String JavaDoc>();
41         this.servletContext = servletContext;
42     }
43
44     /**
45      * Returns the name of this servlet instance.
46      *
47      */

48     public String JavaDoc getServletName() {
49         return servletName;
50     }
51
52     /**
53      * Returns a reference to the ServletContext in which the servlet is
54      * executing.
55      *
56      */

57     public ServletContext JavaDoc getServletContext() {
58         return servletContext;
59     }
60
61     /**
62      * Returns a String containing the value of the named initialization
63      * parameter, or null if the parameter does not exist.
64      *
65      */

66     public String JavaDoc getInitParameter(String JavaDoc key) {
67         return initParams.get(key);
68     }
69
70     /**
71      * Returns the names of the servlet's initialization parameters as an
72      * Enumeration of String objects, or an empty Enumeration if the servlet
73      * has no initialization parameters.
74      *
75      */

76     public Enumeration JavaDoc getInitParameterNames() {
77         return Collections.enumeration(initParams.keySet());
78     }
79
80     /////////////////////////////////////////////////////////////////////////
81
//
82
// implementation access
83
//
84
/////////////////////////////////////////////////////////////////////////
85
public void setServletName(String JavaDoc servletName) {
86         this.servletName = servletName;
87     }
88     public void addInitParameter(String JavaDoc key, String JavaDoc value) {
89         if (value != null) {
90             this.initParams.put(key, value);
91         }
92     }
93     public void setServletContext(ServletContext JavaDoc servletContext) {
94         this.servletContext = servletContext;
95     }
96 }
97
Popular Tags