package org.theonefx.wcframework.mvc.wcweb; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.theonefx.wcframework.mvc.WebApplicationContext; /** * @File : RequestDispatcher.java * @ClassName : RequestDispatcher * @Author : 陈曦 * @Date : 2012-3-22 下午02:12:06 * @Version : v1.0 * @Description : WCF的web请求分发器 */ public class RequestDispatcher { private final WebApplicationContext wactx; private final ServletContext servletContext; private final ActionProxyFactory actionFactory; public RequestDispatcher(ServletContext servletContext) { this.servletContext = servletContext; this.wactx = (WebApplicationContext) servletContext.getAttribute(WebApplicationContext.APPCTX_ATTRNAME); this.actionFactory = new ActionProxyFactory(wactx); servletContext.setAttribute(ActionProxyFactory.FactoryKey, actionFactory); } public boolean dispatch(HttpServletRequest req, HttpServletResponse res, RequestPather pather) throws Exception { return dispatch(req, res, pather, null); } public boolean dispatch(HttpServletRequest req, HttpServletResponse res, RequestPather pather, ActionInvocationContext rctx) throws Exception { ActionProxy proxy = getActionProxy(pather.getPath(), req); if (proxy == null) { return false; } else { if (rctx == null) { rctx = new ActionInvocationContext(wactx, pather, req, res, servletContext, this); } proxy.execute(rctx); return true; } } public ActionProxy getActionProxy(String path, HttpServletRequest req) { ActionProxy proxy = actionFactory.get(path, req); return proxy; } public void depose() { // 清理工作,暂时不需要做什么 } }