001: /*
002: * Copyright 2004-2007 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.springframework.webflow.executor.jsf;
017:
018: import java.io.Serializable;
019:
020: import org.springframework.core.style.ToStringCreator;
021: import org.springframework.webflow.execution.FlowExecution;
022: import org.springframework.webflow.execution.ViewSelection;
023: import org.springframework.webflow.execution.repository.FlowExecutionKey;
024: import org.springframework.webflow.execution.repository.FlowExecutionLock;
025:
026: /**
027: * A holder storing a reference to a flow execution and the key of that flow execution if it has been (or is about to
028: * be) managed in a repository.
029: *
030: * @author Keith Donald
031: */
032: public class FlowExecutionHolder implements Serializable {
033:
034: /**
035: * The flow execution continuation key (may be null if the flow execution has not yet been generated a repository
036: * key). May change as well over the life of this object, as a flow execution can be given a new key to capture its
037: * state at another point in time.
038: */
039: private FlowExecutionKey flowExecutionKey;
040:
041: /**
042: * The held flow execution representing the state of an ongoing conversation at a point in time.
043: */
044: private FlowExecution flowExecution;
045:
046: /**
047: * The lock obtained to exclusively manipulate the flow execution.
048: */
049: private FlowExecutionLock flowExecutionLock;
050:
051: /**
052: * The currently selected view selection for this request.
053: */
054: private ViewSelection viewSelection;
055:
056: /**
057: * Creates a new flow execution holder for a flow execution that has not yet been placed in a repository.
058: * @param flowExecution the flow execution to hold
059: */
060: public FlowExecutionHolder(FlowExecution flowExecution) {
061: this .flowExecution = flowExecution;
062: }
063:
064: /**
065: * Creates a new flow execution holder for a flow execution that has been restored from a repository.
066: * @param flowExecutionKey the continuation key
067: * @param flowExecution the flow execution to hold
068: * @param flowExecutionLock the lock acquired on the flow execution
069: */
070: public FlowExecutionHolder(FlowExecutionKey flowExecutionKey,
071: FlowExecution flowExecution,
072: FlowExecutionLock flowExecutionLock) {
073: this .flowExecutionKey = flowExecutionKey;
074: this .flowExecution = flowExecution;
075: this .flowExecutionLock = flowExecutionLock;
076: }
077:
078: /**
079: * Returns the continuation key.
080: */
081: public FlowExecutionKey getFlowExecutionKey() {
082: return flowExecutionKey;
083: }
084:
085: /**
086: * Sets the continuation key.
087: */
088: public void setFlowExecutionKey(FlowExecutionKey key) {
089: this .flowExecutionKey = key;
090: }
091:
092: /**
093: * Returns the flow execution.
094: */
095: public FlowExecution getFlowExecution() {
096: return flowExecution;
097: }
098:
099: /**
100: * Returns the flow execution lock
101: */
102: public FlowExecutionLock getFlowExecutionLock() {
103: return flowExecutionLock;
104: }
105:
106: /**
107: * Sets the lock acquired on the flow execution
108: * @param lock the flow execution lock
109: */
110: public void setFlowExecutionLock(FlowExecutionLock lock) {
111: this .flowExecutionLock = lock;
112: }
113:
114: /**
115: * Returns the view selected from the current flow execution request.
116: */
117: public ViewSelection getViewSelection() {
118: return viewSelection;
119: }
120:
121: /**
122: * Sets the selected view from the current flow execution request.
123: * @param viewSelection the view selection
124: */
125: public void setViewSelection(ViewSelection viewSelection) {
126: this .viewSelection = viewSelection;
127: }
128:
129: /**
130: * Replace the current flow execution with the one provided. This method will clear out all state associated with
131: * the original execution and unlock it if necessary.
132: * @param flowExecution the new "current" flow execution
133: */
134: public void replaceWith(FlowExecution flowExecution) {
135: this .flowExecutionKey = null;
136: this .viewSelection = null;
137: unlockFlowExecutionIfNecessary();
138: this .flowExecution = flowExecution;
139: }
140:
141: /**
142: * Unlock the held flow execution if necessary.
143: */
144: public void unlockFlowExecutionIfNecessary() {
145: if (flowExecutionLock != null) {
146: flowExecutionLock.unlock();
147: this .flowExecutionLock = null;
148: }
149: }
150:
151: public String toString() {
152: return new ToStringCreator(this ).append("flowExecutionKey",
153: flowExecutionKey)
154: .append("flowExecution", flowExecution).toString();
155: }
156: }
|