Tomcat8.x Facade设计模式的使用
// 请求对象
class org.apache.catalina.connector.Request{
public ServletContext getServletContext() {
// 取得Servlet的上下文
return getContext().getServletContext();
}
public Context getContext() {
// org.apache.catalina.core.StandardContext
return mappingData.context;
}
public MappingData getMappingData() {
return mappingData;
}
}
// 上下文对象 ,对应webapps中的一级目录
class org.apache.catalina.core.StandardContext{
// 取得Servlet的上下文
public ServletContext getServletContext() {
context = new ApplicationContext(this);
return (context.getFacade());
}
}
// 应用
class org.apache.catalina.core.ApplicationContext{
// Servlet的上下文
private final ServletContext facade = new ApplicationContextFacade(this);
protected ServletContext getFacade() {
return (this.facade);
}
}