📄 requestprocessor.java
字号:
/* */package org.impact.stars.control.web;import java.util.Collection;import java.util.HashMap;import javax.servlet.ServletContext;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import java.io.*;import java.rmi.RemoteException;import org.impact.stars.util.Debug;import org.impact.stars.util.WebKeys;import org.impact.stars.control.event.StarsEvent;import org.impact.stars.control.exceptions.StarsEventException;import org.impact.stars.control.web.ScreenFlowManager;import org.impact.stars.control.web.checker.CheckerManager;import org.impact.stars.control.web.handlers.RequestHandler;/** * This is the web tier controller for the sample application. * * This class is responsible for processing all requests received from * the Main.jsp and generating necessary events to modify data which * are sent to the UserControllerWebImpl. * */public class RequestProcessor implements java.io.Serializable { private ServletContext context; private HashMap urlMappings; /** Empty constructor for use by the JSP engine. */ public RequestProcessor() {} public void init(ServletContext context) { this.context = context; urlMappings = (HashMap)context.getAttribute(WebKeys.URLMappingsKey); } /** * The UrlMapping object contains information that will match * a url to a mapping object that contains information about * the current screen, the RequestHandler that is needed to * process a request, and the RequestHandler that is needed * to insure that the propper screen is displayed. */ private URLMapping getURLMapping(String urlPattern) { if ((urlMappings != null) && urlMappings.containsKey(urlPattern)) { return (URLMapping)urlMappings.get(urlPattern); } else { return null; } } /** * This method is the core of the RequestProcessor. It receives all requests * and generates the necessary events. */ public void processRequest(HttpServletRequest request, HttpServletResponse response) throws StarsEventException, IOException { StarsEvent event = null; String client = request.getParameter("client"); String selectedUrl = request.getPathInfo(); String checkresult = null; //to check the access control PrintWriter out = response.getWriter(); Debug.println("Getting ModelManager :" ); ModelManager mm = (ModelManager)request.getSession().getAttribute(WebKeys.ModelManagerKey); // application level ModelManager AppModelManager apmm = (AppModelManager)context.getAttribute(WebKeys.AppModelManagerKey); // application level checkermanager Debug.println("Getting CheckerManager :" ); CheckerManager chm = (CheckerManager)context.getAttribute(WebKeys.CheckerManagerKey); UserControllerWebImpl ucrwimpl = (UserControllerWebImpl)request.getSession().getAttribute(WebKeys.WebControllerKey); if (ucrwimpl == null) { Debug.println("RequestProcessor : new UserControllerWebImpl" ); ucrwimpl = new UserControllerWebImpl(request.getSession()); mm.setURC(ucrwimpl); request.getSession().setAttribute(WebKeys.WebControllerKey, ucrwimpl); } RequestHandler handler = getHandler(selectedUrl); if (handler != null) { handler.setServletContext(context); handler.doStart(request); event = handler.processRequest(request); //check the consistency for this even if (event != null) { checkresult = chm.checkEvent(event); Debug.println("get Check result" + checkresult); if(checkresult.equals("OK")) { chm.doStart(event); //update model state Collection updatedModelList = ucrwimpl.handleEvent(event); mm.notifyListeners(updatedModelList); apmm.notifyListeners(updatedModelList); chm.doEnd(event); //reset model state } if(client== null) //client is applet not a page { out.println(checkresult); } } handler.doEnd(request); } if(client== null) //client is applet not a page { out.close(); } } /** * This method load the necessary RequestHandler class necessary to process a the * request for the specified URL. */ private RequestHandler getHandler(String selectedUrl) { Debug.println("RequestProcessor: inside getHandler " ); RequestHandler handler = null; URLMapping urlMapping = getURLMapping(selectedUrl); String requestProcessorString = null; if (urlMapping != null) { requestProcessorString = urlMapping.getRequestHandler(); if (urlMapping.useRequestHandler()) { try { Debug.println("RequestProcessor: loading handler " + requestProcessorString); handler = (RequestHandler)getClass().getClassLoader().loadClass(requestProcessorString).newInstance(); } catch (Exception ex) { Debug.println("RequestProcessor caught loading handler: " + ex); } } } return handler; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -