和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来进行处理。这个接口定义了如下方法:
- public interface 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属性。
待续。。。