1 16 package org.springframework.webflow.engine; 17 18 import org.springframework.binding.mapping.AttributeMapper; 19 import org.springframework.core.style.ToStringCreator; 20 import org.springframework.util.Assert; 21 import org.springframework.webflow.core.collection.LocalAttributeMap; 22 import org.springframework.webflow.execution.Event; 23 import org.springframework.webflow.execution.FlowExecutionException; 24 import org.springframework.webflow.execution.FlowSession; 25 import org.springframework.webflow.execution.RequestContext; 26 import org.springframework.webflow.execution.ViewSelection; 27 28 59 public class EndState extends State { 60 61 65 private ViewSelector viewSelector = NullViewSelector.INSTANCE; 66 67 71 private AttributeMapper outputMapper; 72 73 83 public EndState(Flow flow, String id) throws IllegalArgumentException { 84 super(flow, id); 85 } 86 87 91 public ViewSelector getViewSelector() { 92 return viewSelector; 93 } 94 95 99 public void setViewSelector(ViewSelector viewSelector) { 100 Assert.notNull(viewSelector, "The view selector is required"); 101 this.viewSelector = viewSelector; 102 } 103 104 108 public AttributeMapper getOutputMapper() { 109 return outputMapper; 110 } 111 112 116 public void setOutputMapper(AttributeMapper outputMapper) { 117 this.outputMapper = outputMapper; 118 } 119 120 134 protected ViewSelection doEnter(RequestControlContext context) throws FlowExecutionException { 135 FlowSession activeSession = context.getFlowExecutionContext().getActiveSession(); 136 if (activeSession.isRoot()) { 137 ViewSelection selectedView = viewSelector.makeEntrySelection(context); 139 context.endActiveFlowSession(createSessionOutput(context)); 140 return selectedView; 141 } 142 else { 143 LocalAttributeMap sessionOutput = createSessionOutput(context); 145 context.endActiveFlowSession(sessionOutput); 146 return context.signalEvent(new Event(this, getId(), sessionOutput)); 147 } 148 } 149 150 155 protected LocalAttributeMap createSessionOutput(RequestContext context) { 156 LocalAttributeMap outputMap = new LocalAttributeMap(); 157 if (outputMapper != null) { 158 outputMapper.map(context, outputMap, null); 159 } 160 return outputMap; 161 } 162 163 protected void appendToString(ToStringCreator creator) { 164 creator.append("viewSelector", viewSelector).append("outputMapper", outputMapper); 165 } 166 } | Popular Tags |