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.FilterConfig; 009 import javax.servlet.ServletContext; 010 011 /** 012 * Mock implementation of <code>FilterConfig</code>. 013 */ 014 public class MockFilterConfig implements FilterConfig 015 { 016 private ServletContext context; 017 private Map initParameters; 018 private String name; 019 020 public MockFilterConfig() 021 { 022 initParameters = new HashMap(); 023 } 024 025 /** 026 * Sets the <code>ServletContext</code>. 027 * @param context the <code>ServletContext</code> 028 */ 029 public synchronized void setupServletContext(ServletContext context) 030 { 031 this.context = context; 032 } 033 034 public synchronized String getFilterName() 035 { 036 return name; 037 } 038 039 public synchronized void setFilterName(String name) 040 { 041 this.name = name; 042 } 043 044 public synchronized ServletContext getServletContext() 045 { 046 return context; 047 } 048 049 public synchronized void clearInitParameters() 050 { 051 initParameters.clear(); 052 } 053 054 /** 055 * Clears the init parameters. 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 }