1 16 package org.springframework.webflow.action; 17 18 import java.util.ArrayList ; 19 import java.util.List ; 20 21 import org.springframework.core.style.ToStringCreator; 22 import org.springframework.util.Assert; 23 import org.springframework.webflow.core.collection.LocalAttributeMap; 24 import org.springframework.webflow.core.collection.MutableAttributeMap; 25 import org.springframework.webflow.execution.Action; 26 import org.springframework.webflow.execution.Event; 27 import org.springframework.webflow.execution.RequestContext; 28 29 45 public class CompositeAction extends AbstractAction { 46 47 51 public static final String ACTION_RESULTS_ATTRIBUTE_NAME = "actionResults"; 52 53 56 private Action[] actions; 57 58 61 private boolean stopOnError; 62 63 67 public CompositeAction(Action[] actions) { 68 Assert.notEmpty(actions, "At least one action is required"); 69 this.actions = actions; 70 } 71 72 76 protected Action[] getActions() { 77 return actions; 78 } 79 80 83 public boolean isStopOnError() { 84 return stopOnError; 85 } 86 87 92 public void setStopOnError(boolean stopOnError) { 93 this.stopOnError = stopOnError; 94 } 95 96 public Event doExecute(RequestContext context) throws Exception { 97 Action[] actions = getActions(); 98 String eventId = getEventFactorySupport().getSuccessEventId(); 99 MutableAttributeMap eventAttributes = new LocalAttributeMap(); 100 List actionResults = new ArrayList (actions.length); 101 for (int i = 0; i < actions.length; i++) { 102 Event result = actions[i].execute(context); 103 actionResults.add(result); 104 if (result != null) { 105 eventId = result.getId(); 106 if (isStopOnError() && result.getId().equals(getEventFactorySupport().getErrorEventId())) { 107 break; 108 } 109 } 110 } 111 eventAttributes.put(ACTION_RESULTS_ATTRIBUTE_NAME, actionResults); 112 return new Event(this, eventId, eventAttributes); 113 } 114 115 public String toString() { 116 return new ToStringCreator(this).append("actions", getActions()).append("stopOnError", isStopOnError()) 117 .toString(); 118 } 119 } | Popular Tags |