01: /*
02: * Copyright 2004-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.springframework.webflow.execution.support;
17:
18: import java.util.Collections;
19: import java.util.Map;
20:
21: import org.springframework.util.Assert;
22: import org.springframework.webflow.execution.ViewSelection;
23:
24: /**
25: * Concrete response type that requests that a <i>new</i> execution of a flow
26: * definition (representing the start of a new conversation) be launched.
27: * <p>
28: * This allows "redirect to new flow" semantics; useful for restarting a flow
29: * after completion, or starting an entirely new flow from within the end state
30: * of another flow definition.
31: *
32: * @author Keith Donald
33: * @author Erwin Vervaet
34: */
35: public final class FlowDefinitionRedirect extends ViewSelection {
36:
37: /**
38: * The id of the flow definition to launch.
39: */
40: private final String flowDefinitionId;
41:
42: /**
43: * A map of input attributes to pass to the flow.
44: */
45: private final Map executionInput;
46:
47: /**
48: * Creates a new flow definition redirect.
49: * @param flowDefinitionId the id of the flow definition to launch
50: * @param executionInput the input data to pass to the new flow execution on launch
51: */
52: public FlowDefinitionRedirect(String flowDefinitionId,
53: Map executionInput) {
54: Assert.hasText(flowDefinitionId,
55: "The flow definition id is required");
56: this .flowDefinitionId = flowDefinitionId;
57: if (executionInput == null) {
58: executionInput = Collections.EMPTY_MAP;
59: }
60: this .executionInput = executionInput;
61: }
62:
63: /**
64: * Return the id of the flow definition to launch a new execution of.
65: */
66: public String getFlowDefinitionId() {
67: return flowDefinitionId;
68: }
69:
70: /**
71: * Return the flow execution input map as an unmodifiable map. Never returns
72: * null.
73: */
74: public Map getExecutionInput() {
75: return Collections.unmodifiableMap(executionInput);
76: }
77:
78: public boolean equals(Object o) {
79: if (!(o instanceof FlowDefinitionRedirect)) {
80: return false;
81: }
82: FlowDefinitionRedirect other = (FlowDefinitionRedirect) o;
83: return flowDefinitionId.equals(other.flowDefinitionId)
84: && executionInput.equals(other.executionInput);
85: }
86:
87: public int hashCode() {
88: return flowDefinitionId.hashCode() + executionInput.hashCode();
89: }
90:
91: public String toString() {
92: return "flowRedirect:'" + flowDefinitionId + "'";
93: }
94: }
|