1 16 package org.springframework.webflow.executor; 17 18 import java.io.Serializable ; 19 20 import org.springframework.core.style.ToStringCreator; 21 import org.springframework.util.Assert; 22 import org.springframework.webflow.execution.FlowExecutionContext; 23 import org.springframework.webflow.execution.ViewSelection; 24 import org.springframework.webflow.execution.support.ApplicationView; 25 import org.springframework.webflow.execution.support.ExternalRedirect; 26 import org.springframework.webflow.execution.support.FlowDefinitionRedirect; 27 import org.springframework.webflow.execution.support.FlowExecutionRedirect; 28 29 49 public class ResponseInstruction implements Serializable { 50 51 55 private String flowExecutionKey; 56 57 60 private transient FlowExecutionContext flowExecutionContext; 61 62 65 private ViewSelection viewSelection; 66 67 73 public ResponseInstruction(String flowExecutionKey, FlowExecutionContext flowExecutionContext, 74 ViewSelection viewSelection) { 75 Assert.notNull(flowExecutionKey, "The flow execution key is required"); 76 this.flowExecutionKey = flowExecutionKey; 77 init(flowExecutionContext, viewSelection); 78 } 79 80 87 public ResponseInstruction(FlowExecutionContext flowExecutionContext, ViewSelection viewSelection) { 88 init(flowExecutionContext, viewSelection); 89 } 90 91 94 private void init(FlowExecutionContext flowExecutionContext, ViewSelection viewSelection) { 95 Assert.notNull(flowExecutionContext, "The flow execution context is required"); 96 Assert.notNull(viewSelection, "The view selection is required"); 97 this.flowExecutionContext = flowExecutionContext; 98 this.viewSelection = viewSelection; 99 } 100 101 104 public String getFlowExecutionKey() { 105 return flowExecutionKey; 106 } 107 108 113 public FlowExecutionContext getFlowExecutionContext() { 114 return flowExecutionContext; 115 } 116 117 120 public ViewSelection getViewSelection() { 121 return viewSelection; 122 } 123 124 128 public boolean isActiveView() { 129 return isApplicationView() && flowExecutionContext.isActive(); 130 } 131 132 136 public boolean isEndingView() { 137 return isApplicationView() && !flowExecutionContext.isActive(); 138 } 139 140 142 146 public boolean isApplicationView() { 147 return viewSelection instanceof ApplicationView; 148 } 149 150 154 public boolean isFlowExecutionRedirect() { 155 return viewSelection instanceof FlowExecutionRedirect; 156 } 157 158 162 public boolean isFlowDefinitionRedirect() { 163 return viewSelection instanceof FlowDefinitionRedirect; 164 } 165 166 170 public boolean isExternalRedirect() { 171 return viewSelection instanceof ExternalRedirect; 172 } 173 174 178 public boolean isNull() { 179 return viewSelection == ViewSelection.NULL_VIEW; 180 } 181 182 public boolean equals(Object o) { 183 if (!(o instanceof ResponseInstruction)) { 184 return false; 185 } 186 ResponseInstruction other = (ResponseInstruction)o; 187 if (getFlowExecutionKey() != null) { 188 return getFlowExecutionKey().equals(other.getFlowExecutionKey()) 189 && viewSelection.equals(other.viewSelection); 190 } 191 else { 192 return other.getFlowExecutionKey() == null && viewSelection.equals(other.viewSelection); 193 } 194 } 195 196 public int hashCode() { 197 int hashCode = viewSelection.hashCode(); 198 if (getFlowExecutionKey() != null) { 199 hashCode += getFlowExecutionKey().hashCode(); 200 } 201 return hashCode; 202 } 203 204 public String toString() { 205 return new ToStringCreator(this).append("flowExecutionKey", flowExecutionKey) 206 .append("viewSelection", viewSelection).append("flowExecutionContext", flowExecutionContext).toString(); 207 } 208 } | Popular Tags |