How tomcat works 之第十一章之 FilterDef
来源:互联网 发布:剑三喵萝异瞳捏脸数据 编辑:程序博客网 时间:2024/04/30 03:59
org.apache.catalian.deploy.FilterDef类代表一个filter定义,就如在部署描述符中定义的filter元素。
package org.apache.catalina.deploy;
import java.util.HashMap;
import java.util.Map;
public final class FilterDef {
/**
* The description of this filter.
*/
private String description = null;
public String getDescription() {
return (this.description);
}
public void setDescription(String description) {
this.description = description;
}
/**
* The display name of this filter.
*/
private String displayName = null;
public String getDisplayName() {
return (this.displayName);
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
/**
* The fully qualified name of the Java class that implements this
* filter.
*/
private String filterClass = null;
public String getFilterClass() {
return (this.filterClass);
}
public void setFilterclass(String filterClass) {
this.filterClass = filterClass;
}
/**
* The name of this filter, which must be unique among the filters
* defined for a particular web application.
*/
private String filterName = null;
public String getFilterName() {
return (this.filterName);
}
public void setFilterName(String filterName) {
this.filterName = filterName;
}
/**
* The large icon associated with this filter.
*/
private String largeIcon = null;
public String getLargeIcon() {
return (this.largeIcon);
}
public void setLargeIcon(String largeIcon) {
this.largeIcon = largeIcon;
}
/**
* The set of initialization parameters for this filter, keyed by
* parameter name.
*/
private Map parameters = new HashMap();
public Map getParameterMap() {
return (this.parameters);
}
/**
* The small icon associated with this filter.
*/
private String smallIcon = null;
public String getSmallIcon() {
return (this.smallIcon);
}
public void setSmallIcon(String smallIcon) {
this.smallIcon = smallIcon;
}
public void addInitParameter(String name, String value) {
parameters.put(name, value);
}
/**
* Render a String representation of this object.
*/
public String toString() {
StringBuffer sb = new StringBuffer("FilterDef[");
sb.append("filterName=");
sb.append(this.filterName);
sb.append(", filterClass=");
sb.append(this.filterClass);
sb.append("]");
return (sb.toString());
}
}
FilterDef类中的每个属性代表着会在filter元素中出现的子元素。这个类也包含了一个命名为parameters的Map代表一个Map,维护这个filter的所有初始化参数。addInitParameter方法增加name/value键值对。
ApplicationFilterConfig
此类实现了FilterConfig接口.ApplicationFilterConfig管理了过滤器实例,当web应用第一次启动的时候被创建了这些过滤器实例.
通过传递Context对象和FilterDef对象给ApplicationFilterConfig的构造函数来创建一个ApplicationFilterConfig对象.
publicApplicationFilterConfig(Context context, FilterDef filterDef) throwsClassCastException, ClassNotFoundException, IllegalAccessException,InstantiationException, ServletException
Context对象表示一个web应用,FilterDef对象表示一个filter对象.ApplicationFilterConfig类有getFilter方法来返回一个Filter对象.这个方法加载Filter类并实例化它.
Filter getFilter()throws ClassCastException, ClassNotFoundException, IllegalAccessException,InstantiationException, ServletException { // Return the existing filterinstance, if any if (this.filter != null) return (this.filter);
// Identify theclass loader we will be using
String filterClass= filterDef.getFilterClass(); ClassLoader classLoader = null; if(filterClass.startsWith("org.apache.catalina."))
classLoader =this.getClass().getClassLoader(); else classLoader =context.getLoader().getClassLoader(); ClassLoader oldCtxClassLoader = Thread.currentthread().getContextClassLoader();// Instantiate a new instance of this filter and return it Class clazz =classLoader.loadClass(filterClass); this.filter = (Filter) clazz.newInstance();filter.init(this); return (this.filter); }
- How tomcat works 之第十一章之 FilterDef
- How Tomcat works之第十一章之The ServletConfig 对象
- How Tomcat works之第十一章之Parent and Child
- How Tomcat works 之第十一章之StandardWrapperValue
- How Tomcat works之第十一章之ApplicationFilterChain
- How Tomcat works之第十一章之ApplicationFilterChain
- How Tomcat works之第十一章 Allocate The Servlet
- How Tomcat Works之第十二章之invoke方法
- How Tomcat works 之第十二章之重新载入支持
- How Tomcat works 之第十三章之 StandardHostMapper
- How Tomcat works之第六章:Lifecycle生命周期
- How Tomcat works之第九章 会话管理
- How Tomcat works 之第九章 BootStrap类
- How Tomcat works 之第十章 Security 安全
- How Tomcat works 之The Application 应用
- How Tomcat works 之 StandardWrapper 标准包装
- How Tomcat works之StandardContext 标准上下文
- How Tomcat works之 Host and Engine
- android 支付宝集成 使用常见错误
- c语言中指针的简单介绍
- firebird
- 关于腾讯云服务器使用FTP详细配置教程
- Bluetooth RFCOMM介绍
- How tomcat works 之第十一章之 FilterDef
- 黑马程序员3. static&javadoc&静态代码块
- eclipse alt+/快捷键失效
- 史上最全孕期知识问答——怀孕期间禁忌全知道 [转自:自媒体之家]
- 图片来回滚动和图片联接滚动
- freemarker写select组件报错总结(五)
- android 虚拟按键menu显示/隐藏问题
- SSH框架搭建遇到的问题---Action class [userAction] not found - action
- Function overloading