和Spring其他框架一樣,對於webflow,Spring也提供了2個系列,一個是servlet級別的webflow,它在org.springframework.webflow.mvc.servlet 包中,一個是portlet級別的webflow,它在org.springframework.webflow.mvc.portlet包中,我們這裡討論portlet級別的FlowHandler。
FlowHandlerAdapter,正如Spring官方注釋所說的,它將特定的flow定義文件關聯到Flow Handler上。它實現了HandlerAdaptor接口,這個接口的作用是讓Spring的DispatcherPortlet對應各種類型的request(比如actionRequest,resourceRequest,renderRequest,event)可以用特定的Handler來進行處理。這個接口定義了如下方法:
- publicinterface HandlerAdapter {
- boolean supports(Object handler);
- void handleAction(ActionRequest request, ActionResponse response, Object handler) throws Exception;
- ModelAndView handleRender(RenderRequest request, RenderResponse response, Object handler) throws Exception;
- ModelAndView handleResource(ResourceRequest request, ResourceResponse response, Object handler) throws Exception;
- void handleEvent(EventRequest request, EventResponse response, Object handler) throws Exception;
- }
那麼如何處理呢,在FlowHandlerAdapter中給出了對應的實現,我們以render為例,它的代碼如下:
- public ModelAndView handleRender(RenderRequest request, RenderResponse response, Object handler) throws Exception {
- FlowHandler flowHandler = (FlowHandler) handler;
- checkAndPrepare(request, response);
- populateConveniencePortletProperties(request);
- FlowException e = clearActionRequestFlowException(request, response, flowHandler);
- if (e != null) {
- return handleException(e, flowHandler, request, response);
- }
- String flowExecutionKey = flowUrlHandler.getFlowExecutionKey(request);
- if (flowExecutionKey != null) {
- return resumeFlowRender(request, response, flowHandler, flowExecutionKey);
- } else {
- MutableAttributeMap input = flowHandler.createExecutionInputMap(request);
- if (input == null) {
- input = defaultCreateFlowExecutionInputMap(request);
- }
- return startFlowRender(flowHandler, input, request, response);
- }
- }
從這裡我們可以看出,它在第2行中從參數獲得FlowHandler對象,在3行做初始化工作,第4行從render request中填出必要的Portlet屬性。