001    package com.mockrunner.mock.web;
002    
003    import java.util.Enumeration;
004    import java.util.HashMap;
005    import java.util.Map;
006    import java.util.Vector;
007    
008    import javax.servlet.ServletConfig;
009    import javax.servlet.ServletContext;
010    
011    /**
012     * Mock implementation of <code>ServletConfig</code>.
013     */
014    public class MockServletConfig implements ServletConfig
015    {
016        private ServletContext servletContext;
017        private Map initParameters;
018        private String servletName;
019        
020        public MockServletConfig()
021        {
022            initParameters = new HashMap();
023        }
024    
025        public synchronized String getServletName()
026        {
027            return servletName;
028        }
029        
030        public synchronized void setServletName(String servletName)
031        {
032            this.servletName = servletName;
033        }
034    
035        public synchronized ServletContext getServletContext()
036        {
037            return servletContext;
038        }
039        
040        /**
041         * Sets the <code>ServletContext</code>.
042         * @param servletContext the <code>ServletContext</code>
043         */
044        public synchronized void setServletContext(ServletContext servletContext)
045        {
046            this.servletContext = servletContext;
047        }
048        
049        /**
050         * Clears the init parameters.
051         */
052        public synchronized void clearInitParameters()
053        {
054            initParameters.clear();
055        }
056    
057        public synchronized String getInitParameter(String name)
058        {
059            return (String)initParameters.get(name);
060        }
061        
062        /**
063         * Sets an init parameter.
064         * @param name the name
065         * @param value the value
066         */
067        public synchronized void setInitParameter(String name, String value) 
068        {
069            initParameters.put(name, value);
070        }
071        
072        /**
073         * Sets several init parameters.
074         * @param parameters the parameter map
075         */
076        public synchronized void setInitParameters(Map parameters) 
077        {
078            initParameters.putAll(parameters);
079        }
080    
081        public synchronized Enumeration getInitParameterNames()
082        {
083            return new Vector(initParameters.keySet()).elements();
084        }
085    }