001: /*
002: * ====================================================================
003: *
004: * XFLOW - Process Management System
005: * Copyright (C) 2003 Rob Tan
006: * All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions, and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions, and the disclaimer that follows
017: * these conditions in the documentation and/or other materials
018: * provided with the distribution.
019: *
020: * 3. The name "XFlow" must not be used to endorse or promote products
021: * derived from this software without prior written permission. For
022: * written permission, please contact rcktan@yahoo.com
023: *
024: * 4. Products derived from this software may not be called "XFlow", nor
025: * may "XFlow" appear in their name, without prior written permission
026: * from the XFlow Project Management (rcktan@yahoo.com)
027: *
028: * In addition, we request (but do not require) that you include in the
029: * end-user documentation provided with the redistribution and/or in the
030: * software itself an acknowledgement equivalent to the following:
031: * "This product includes software developed by the
032: * XFlow Project (http://xflow.sourceforge.net/)."
033: * Alternatively, the acknowledgment may be graphical using the logos
034: * available at http://xflow.sourceforge.net/
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL THE XFLOW AUTHORS OR THE PROJECT
040: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: *
049: * ====================================================================
050: * This software consists of voluntary contributions made by many
051: * individuals on behalf of the XFlow Project and was originally
052: * created by Rob Tan (rcktan@yahoo.com)
053: * For more information on the XFlow Project, please see:
054: * <http://xflow.sourceforge.net/>.
055: * ====================================================================
056: */
057: package xflow.common;
058:
059: import java.util.*;
060: import java.io.*;
061:
062: /**
063: * This class represents the workflow's state - its variables and participant process states
064: */
065: public class WorkflowState implements Serializable {
066:
067: public WorkflowId workflowId;
068: public String workflowName;
069: public int version;
070: public boolean isActive;
071: public String state;
072: public String initiator;
073: public Date timeStarted;
074: public Date timeEnded;
075: public HashMap variables; // returns a hash table of Variables
076: public Vector activeProcesses; // returns a list of ProcessStates for currently active processes
077:
078: /**
079: * Constructor
080: */
081: public WorkflowState() {
082: variables = new HashMap();
083: activeProcesses = new Vector();
084: }
085:
086: /**
087: * Sets a workflow ID
088: *
089: * @param workflowId the workflow ID
090: */
091: public void setWorkflowId(WorkflowId wfid) {
092: workflowId = wfid;
093: }
094:
095: /**
096: * Gets a workflow ID
097: *
098: * @return workflowId the workflow ID
099: */
100: public WorkflowId getWorkflowId() {
101: return workflowId;
102: }
103:
104: /**
105: * Sets a workflow name
106: *
107: * @param name the workflow name
108: */
109: public void setWorkflowName(String name) {
110: workflowName = name;
111: }
112:
113: /**
114: * Returns the workflow name
115: *
116: * @return workflowName the workflow name
117: */
118: public String getWorkflowName() {
119: return workflowName;
120: }
121:
122: /**
123: * Sets a workflow version
124: *
125: * @param v the workflow version
126: */
127: public void setWorkflowVersion(int v) {
128: version = v;
129: }
130:
131: /**
132: * Returns the workflow version
133: *
134: * @param version the workflow version
135: */
136: public int getWorkflowVersion() {
137: return version;
138: }
139:
140: /**
141: * Sets a workflow state
142: *
143: * @param s the workflow state name
144: */
145: public void setState(String s) {
146: state = s;
147: }
148:
149: /**
150: * Returns the workflow state
151: *
152: * @return workflowState the workflow state name
153: */
154: public String getState() {
155: return state;
156: }
157:
158: /**
159: * Sets the initiator
160: *
161: * @param s the initiator (user)
162: */
163: public void setInitiator(String s) {
164: initiator = s;
165: }
166:
167: /**
168: * Returns the initiator
169: *
170: * @return initiator the user who initiated the workflow
171: */
172: public String getInitiator() {
173: return initiator;
174: }
175:
176: /**
177: * Sets the active status
178: *
179: * @param b the active status
180: */
181: public void setIsActive(boolean b) {
182: isActive = b;
183: }
184:
185: /**
186: * Gets the active status
187: *
188: * @return the active status
189: */
190: public boolean getIsActive() {
191: return isActive;
192: }
193:
194: /**
195: * Sets the time started
196: *
197: * @param d the start time
198: */
199: public void setTimeStarted(Date ts) {
200: timeStarted = ts;
201: }
202:
203: /**
204: * Gets the time started
205: *
206: * @return the start time
207: */
208: public Date getTimeStarted() {
209: return timeStarted;
210: }
211:
212: /**
213: * Sets the time ended
214: *
215: * @param d the end time
216: */
217: public void setTimeEnded(Date ts) {
218: timeEnded = ts;
219: }
220:
221: /**
222: * Gets the time ended
223: *
224: * @return the end time
225: */
226: public Date getTimeEnded() {
227: return timeEnded;
228: }
229:
230: /**
231: * Sets the variables hash map
232: *
233: * @param v the variables hash map
234: */
235: public void setVariables(HashMap v) {
236: variables = v;
237: }
238:
239: /**
240: * Gets the variables hash map
241: *
242: * @return the variables hash map
243: */
244: public HashMap getVariables() {
245: return variables;
246: }
247:
248: /**
249: * Sets the vector of ProcessState objects of active processes
250: *
251: * @param v the vector of ProcessState objects
252: */
253: public void setActiveProcesses(Vector v) {
254: activeProcesses = v;
255: }
256:
257: /**
258: * Gets the vector of ProcessState objects of active processes
259: *
260: * @return the vector of ProcessState objects
261: */
262: public Vector getActiveProcesses() {
263: return activeProcesses;
264: }
265:
266: /**
267: * Gets the string representation of this object
268: *
269: * @return the string representation
270: */
271: public String toString() {
272: String result = "";
273: result += "Workflow ID: " + workflowId.getValue() + "\n";
274: result += "Workflow Name: " + workflowName + "\n";
275: result += "Workflow Version: " + version + "\n";
276: result += "IsActive: " + isActive + "\n";
277: result += "State: " + state + "\n";
278: result += "Initiator: " + initiator + "\n";
279: result += "Time Started: " + timeStarted + "\n";
280: result += "Time Ended: " + timeEnded + "\n";
281:
282: result += "Variables: \n";
283: Iterator itr = variables.keySet().iterator();
284: while (itr.hasNext()) {
285: String key = (String) itr.next();
286: Object val = variables.get(key);
287: result += " Key: " + key;
288: result += " Value: " + val + "\n";
289: }
290:
291: result += "Processes: \n";
292: for (int i = 0; i < activeProcesses.size(); i++) {
293: ProcessState ps = (ProcessState) activeProcesses
294: .elementAt(i);
295: result += ps.toString();
296: }
297:
298: return result;
299: }
300: }
|