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: import java.sql.*;
062:
063: import xflow.util.*;
064:
065: /**
066: * This class represents a work item that gets routed to a process.
067: */
068: public class WorkItem implements Serializable {
069:
070: public static final String JAVA_OBJECT = "JavaObject";
071: public static final String XML = "XML";
072:
073: private WorkItemId workItemId;
074: private WorkflowId workflowId;
075: private Object payload;
076: private String payloadType;
077: private HashMap properties = new HashMap();
078:
079: /**
080: * Constructor
081: */
082: public WorkItem() {
083: }
084:
085: /**
086: * Constructor
087: *
088: * @param wid a work item ID
089: */
090: public WorkItem(WorkItemId wid) {
091: workItemId = wid;
092: payload = null;
093: payloadType = "";
094: }
095:
096: /**
097: * Gets the work item ID
098: *
099: * @return the work item ID
100: */
101: public WorkItemId getId() {
102: return workItemId;
103: }
104:
105: /**
106: * Sets the work item ID
107: *
108: * @param id the work item ID
109: */
110: public void setId(WorkItemId id) {
111: workItemId = id;
112: }
113:
114: /**
115: * Gets the workflow instance ID
116: *
117: * @return the workflow instance ID
118: */
119: public WorkflowId getWorkflowId() {
120: return workflowId;
121: }
122:
123: /**
124: * Sets the workflow instance ID
125: *
126: * @param wfId the workflow instance ID
127: */
128: public void setWorkflowId(WorkflowId wfId) {
129: workflowId = wfId;
130: }
131:
132: /**
133: * Sets the payload of this work item.
134: *
135: * @param pload the payload
136: */
137: public void setPayload(Object pload) {
138: payload = pload;
139: }
140:
141: /**
142: * Gets the payload of this work item.
143: *
144: * @return the payload
145: */
146: public Object getPayload() {
147: return payload;
148: }
149:
150: /**
151: * Sets the payload type of this work item.
152: *
153: * @param pt the payload type - JAVA_OBJECT or XML
154: */
155: public void setPayloadType(String pt) {
156: payloadType = pt;
157: }
158:
159: /**
160: * Gets the payload type of this work item.
161: *
162: * @return the payload type - JAVA_OBJECT or XML
163: */
164: public String getPayloadType() {
165: return payloadType;
166: }
167:
168: /**
169: * Gets a work item's property
170: *
171: * @param key the property name
172: * @return the property value
173: */
174: public Object getProperty(String key) {
175: return properties.get(key);
176: }
177:
178: /**
179: * Sets a property on a work item
180: *
181: * @param key the property name
182: * @param value the property value - must be serializable
183: *
184: */
185: public void setProperty(String key, Object value) {
186: properties.put(key, value);
187: }
188:
189: /**
190: * Gets a work item's property hash map
191: *
192: * @return the property hash map
193: */
194: public HashMap getProperties() {
195: return properties;
196: }
197:
198: /**
199: * Sets a work item's property hash map
200: *
201: * @param m the property hash map
202: */
203: public void setProperties(HashMap m) {
204: properties = m;
205: }
206:
207: /**
208: * Gets the string representation of this object
209: *
210: * @return the string representation
211: */
212: public String toString() {
213: String str = "";
214: str += "WorkItem Id: " + workItemId + "\n";
215: str += "Workflow Id: " + workflowId + "\n";
216: str += "Payload: " + payload + "\n";
217: str += "Payload Type: " + payloadType + "\n";
218: Iterator itr = properties.keySet().iterator();
219: while (itr.hasNext()) {
220: String key = (String) itr.next();
221: Object val = properties.get(key);
222: str += "key = " + key;
223: str += " value = " + val + "\n";
224: }
225: return str;
226: }
227: }
|