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