001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.server.dispatch;
031:
032: import com.caucho.config.Config;
033: import com.caucho.config.ConfigException;
034: import com.caucho.config.program.ContainerProgram;
035: import com.caucho.config.types.InitParam;
036: import com.caucho.server.util.CauchoSystem;
037: import com.caucho.util.L10N;
038:
039: import javax.servlet.Filter;
040: import javax.servlet.FilterConfig;
041: import javax.servlet.ServletContext;
042: import java.util.Collections;
043: import java.util.Enumeration;
044: import java.util.HashMap;
045: import java.util.Map;
046:
047: /**
048: * Configuration for a filter.
049: */
050: public class FilterConfigImpl implements FilterConfig {
051: private static final L10N L = new L10N(FilterConfigImpl.class);
052:
053: private String _filterName;
054: private String _filterClassName;
055: private Class _filterClass;
056: private String _displayName;
057: private HashMap<String, String> _initParams = new HashMap<String, String>();
058:
059: private ContainerProgram _init;
060:
061: private ServletContext _servletContext;
062:
063: /**
064: * Creates a new filter configuration object.
065: */
066: public FilterConfigImpl() {
067: }
068:
069: public void setId(String id) {
070: }
071:
072: /**
073: * Sets the filter name.
074: */
075: public void setFilterName(String name) {
076: _filterName = name;
077: }
078:
079: /**
080: * Gets the filter name.
081: */
082: public String getFilterName() {
083: return _filterName;
084: }
085:
086: /**
087: * Sets the filter class.
088: */
089: public void setFilterClass(String filterClassName)
090: throws ConfigException, ClassNotFoundException {
091: _filterClassName = filterClassName;
092:
093: _filterClass = CauchoSystem.loadClass(filterClassName);
094:
095: Config.validate(_filterClass, Filter.class);
096: }
097:
098: /**
099: * Gets the filter name.
100: */
101: public Class getFilterClass() {
102: return _filterClass;
103: }
104:
105: /**
106: * Gets the filter name.
107: */
108: public String getFilterClassName() {
109: return _filterClassName;
110: }
111:
112: /**
113: * Sets an init-param
114: */
115: public void setInitParam(String param, String value) {
116: _initParams.put(param, value);
117: }
118:
119: /**
120: * Sets an init-param
121: */
122: public void setInitParam(InitParam initParam) {
123: _initParams.putAll(initParam.getParameters());
124: }
125:
126: /**
127: * Gets the init params
128: */
129: public Map getInitParamMap() {
130: return _initParams;
131: }
132:
133: /**
134: * Gets the init params
135: */
136: public String getInitParameter(String name) {
137: return _initParams.get(name);
138: }
139:
140: /**
141: * Gets the init params
142: */
143: public Enumeration getInitParameterNames() {
144: return Collections.enumeration(_initParams.keySet());
145: }
146:
147: /**
148: * Returns the servlet context.
149: */
150: public ServletContext getServletContext() {
151: return _servletContext;
152: }
153:
154: /**
155: * Sets the servlet context.
156: */
157: public void setServletContext(ServletContext app) {
158: _servletContext = app;
159: }
160:
161: /**
162: * Sets the init block
163: */
164: public void setInit(ContainerProgram init) {
165: _init = init;
166: }
167:
168: /**
169: * Gets the init block
170: */
171: public ContainerProgram getInit() {
172: return _init;
173: }
174:
175: /**
176: * Sets the display name
177: */
178: public void setDisplayName(String displayName) {
179: _displayName = displayName;
180: }
181:
182: /**
183: * Gets the display name
184: */
185: public String getDisplayName() {
186: return _displayName;
187: }
188:
189: /**
190: * Sets the description
191: */
192: public void setDescription(String description) {
193: }
194:
195: /**
196: * Sets the icon
197: */
198: public void setIcon(String icon) {
199: }
200:
201: /**
202: * Returns a printable representation of the filter config object.
203: */
204: public String toString() {
205: return "FilterConfigImpl[name=" + _filterName + ",class="
206: + _filterClass + "]";
207: }
208: }
|