1 16 package org.springframework.webflow.engine; 17 18 import org.springframework.core.style.StylerUtils; 19 import org.springframework.core.style.ToStringCreator; 20 import org.springframework.webflow.definition.TransitionDefinition; 21 import org.springframework.webflow.definition.TransitionableStateDefinition; 22 import org.springframework.webflow.execution.RequestContext; 23 import org.springframework.webflow.execution.ViewSelection; 24 25 35 public abstract class TransitionableState extends State implements TransitionableStateDefinition { 36 37 40 private TransitionSet transitions = new TransitionSet(); 41 42 45 private ActionList exitActionList = new ActionList(); 46 47 56 protected TransitionableState(Flow flow, String id) throws IllegalArgumentException { 57 super(flow, id); 58 } 59 60 62 public TransitionDefinition[] getTransitions() { 63 return getTransitionSet().toArray(); 64 } 65 66 69 public TransitionSet getTransitionSet() { 70 return transitions; 71 } 72 73 79 public Transition getRequiredTransition(RequestContext context) throws NoMatchingTransitionException { 80 Transition transition = getTransitionSet().getTransition(context); 81 if (transition == null) { 82 throw new NoMatchingTransitionException(getFlow().getId(), getId(), context.getLastEvent(), 83 "No transition found on occurence of event '" + context.getLastEvent() + "' in state '" + getId() 84 + "' of flow '" + getFlow().getId() + "' -- valid transitional criteria are " 85 + StylerUtils.style(getTransitionSet().getTransitionCriterias()) 86 + " -- likely programmer error, check the set of TransitionCriteria for this state"); 87 } 88 return transition; 89 } 90 91 96 public ActionList getExitActionList() { 97 return exitActionList; 98 } 99 100 102 111 public ViewSelection onEvent(RequestControlContext context) throws NoMatchingTransitionException { 112 return getRequiredTransition(context).execute(this, context); 113 } 114 115 126 public ViewSelection reenter(RequestControlContext context) { 127 return enter(context); 128 } 129 130 136 public void exit(RequestControlContext context) { 137 exitActionList.execute(context); 138 } 139 140 protected void appendToString(ToStringCreator creator) { 141 creator.append("transitions", transitions).append("exitActionList", exitActionList); 142 } 143 } | Popular Tags |