1 16 package org.springframework.webflow.executor.support; 17 18 import org.apache.commons.logging.Log; 19 import org.apache.commons.logging.LogFactory; 20 import org.springframework.util.Assert; 21 import org.springframework.webflow.context.ExternalContext; 22 import org.springframework.webflow.core.FlowException; 23 import org.springframework.webflow.executor.FlowExecutor; 24 import org.springframework.webflow.executor.ResponseInstruction; 25 26 49 public class FlowRequestHandler { 50 51 54 private static final Log logger = LogFactory.getLog(FlowRequestHandler.class); 55 56 59 private FlowExecutor flowExecutor; 60 61 65 private FlowExecutorArgumentExtractor argumentExtractor; 66 67 72 public FlowRequestHandler(FlowExecutor flowExecutor) { 73 this(flowExecutor, new RequestParameterFlowExecutorArgumentHandler()); 74 } 75 76 81 public FlowRequestHandler(FlowExecutor flowExecutor, FlowExecutorArgumentExtractor argumentExtractor) { 82 Assert.notNull(flowExecutor, "The flow executor is required"); 83 Assert.notNull(argumentExtractor, "The flow executor argument extractor is required"); 84 this.flowExecutor = flowExecutor; 85 this.argumentExtractor = argumentExtractor; 86 } 87 88 91 public FlowExecutor getFlowExecutor() { 92 return flowExecutor; 93 } 94 95 98 public FlowExecutorArgumentExtractor getArgumentExtractor() { 99 return argumentExtractor; 100 } 101 102 107 public ResponseInstruction handleFlowRequest(ExternalContext context) throws FlowException { 108 if (logger.isDebugEnabled()) { 109 logger.debug("Request initiated by " + context); 110 } 111 if (argumentExtractor.isFlowExecutionKeyPresent(context)) { 112 String flowExecutionKey = argumentExtractor.extractFlowExecutionKey(context); 113 if (argumentExtractor.isEventIdPresent(context)) { 114 String eventId = argumentExtractor.extractEventId(context); 115 ResponseInstruction response = flowExecutor.resume(flowExecutionKey, eventId, context); 116 if (logger.isDebugEnabled()) { 117 logger.debug("Returning [resume] " + response); 118 } 119 return response; 120 } 121 else { 122 ResponseInstruction response = flowExecutor.refresh(flowExecutionKey, context); 123 if (logger.isDebugEnabled()) { 124 logger.debug("Returning [refresh] " + response); 125 } 126 return response; 127 } 128 } 129 else { 130 String flowDefinitionId = argumentExtractor.extractFlowId(context); 131 ResponseInstruction response = flowExecutor.launch(flowDefinitionId, context); 132 if (logger.isDebugEnabled()) { 133 logger.debug("Returning [launch] " + response); 134 } 135 return response; 136 } 137 } 138 } | Popular Tags |