001/* 002// This software is subject to the terms of the Eclipse Public License v1.0 003// Agreement, available at the following URL: 004// http://www.eclipse.org/legal/epl-v10.html. 005// You must accept the terms of that agreement to use this software. 006// 007// Copyright (C) 2005-2009 Pentaho and others 008// All Rights Reserved. 009*/ 010package mondrian.tui; 011 012import java.util.*; 013import javax.servlet.ServletConfig; 014import javax.servlet.ServletContext; 015 016/** 017 * This is a partial implementation of the ServletConfig where just 018 * enough is present to allow for communication between Mondrian's 019 * XMLA code and other code in the same JVM. 020 * Currently it is used in both the CmdRunner and in XMLA JUnit tests. 021 * <p> 022 * If you need to add to this implementation, please do so. 023 * 024 * @author <a>Richard M. Emberson</a> 025 */ 026public class MockServletConfig implements ServletConfig { 027 private String servletName; 028 private Map<String, String> initParams; 029 private ServletContext servletContext; 030 031 public MockServletConfig() { 032 this(null); 033 } 034 public MockServletConfig(ServletContext servletContext) { 035 this.initParams = new HashMap<String, String>(); 036 this.servletContext = servletContext; 037 } 038 039 /** 040 * Returns the name of this servlet instance. 041 * 042 */ 043 public String getServletName() { 044 return servletName; 045 } 046 047 /** 048 * Returns a reference to the ServletContext in which the servlet is 049 * executing. 050 * 051 */ 052 public ServletContext getServletContext() { 053 return servletContext; 054 } 055 056 /** 057 * Returns a String containing the value of the named initialization 058 * parameter, or null if the parameter does not exist. 059 * 060 */ 061 public String getInitParameter(String key) { 062 return initParams.get(key); 063 } 064 065 /** 066 * Returns the names of the servlet's initialization parameters as an 067 * Enumeration of String objects, or an empty Enumeration if the servlet 068 * has no initialization parameters. 069 * 070 */ 071 public Enumeration getInitParameterNames() { 072 return Collections.enumeration(initParams.keySet()); 073 } 074 075 ///////////////////////////////////////////////////////////////////////// 076 // 077 // implementation access 078 // 079 ///////////////////////////////////////////////////////////////////////// 080 public void setServletName(String servletName) { 081 this.servletName = servletName; 082 } 083 public void addInitParameter(String key, String value) { 084 if (value != null) { 085 this.initParams.put(key, value); 086 } 087 } 088 public void setServletContext(ServletContext servletContext) { 089 this.servletContext = servletContext; 090 } 091} 092 093// End MockServletConfig.java