1 16 package org.springframework.webflow.execution.factory; 17 18 import org.springframework.core.style.StylerUtils; 19 import org.springframework.core.style.ToStringCreator; 20 import org.springframework.util.Assert; 21 import org.springframework.webflow.definition.FlowDefinition; 22 23 31 public class FlowExecutionListenerCriteriaFactory { 32 33 36 public FlowExecutionListenerCriteria allFlows() { 37 return new WildcardFlowExecutionListenerCriteria(); 38 } 39 40 44 public FlowExecutionListenerCriteria flow(String flowId) { 45 return new FlowIdFlowExecutionListenerCriteria(flowId); 46 } 47 48 53 public FlowExecutionListenerCriteria flows(String [] flowIds) { 54 return new FlowIdFlowExecutionListenerCriteria(flowIds); 55 } 56 57 61 private static class WildcardFlowExecutionListenerCriteria implements FlowExecutionListenerCriteria { 62 63 public boolean appliesTo(FlowDefinition definition) { 64 return true; 65 } 66 67 public String toString() { 68 return "*"; 69 } 70 } 71 72 76 private static class FlowIdFlowExecutionListenerCriteria implements FlowExecutionListenerCriteria { 77 78 81 private String [] flowIds; 82 83 88 public FlowIdFlowExecutionListenerCriteria(String flowId) { 89 Assert.notNull(flowId, "The flow id is required"); 90 this.flowIds = new String [] { flowId }; 91 } 92 93 98 public FlowIdFlowExecutionListenerCriteria(String [] flowIds) { 99 Assert.notEmpty(flowIds, "The flow id array is required"); 100 this.flowIds = flowIds; 101 } 102 103 public boolean appliesTo(FlowDefinition definition) { 104 for (int i = 0; i < flowIds.length; i++) { 105 if (flowIds[i].equals(definition.getId())) { 106 return true; 107 } 108 } 109 return false; 110 } 111 112 public String toString() { 113 return new ToStringCreator(this).append("flowIds", StylerUtils.style(flowIds)).toString(); 114 } 115 } 116 } | Popular Tags |