001: /*--
002:
003: Copyright (C) 2002-2005 Adrian Price.
004: All rights reserved.
005:
006: Redistribution and use in source and binary forms, with or without
007: modification, are permitted provided that the following conditions
008: are met:
009:
010: 1. Redistributions of source code must retain the above copyright
011: notice, this list of conditions, and the following disclaimer.
012:
013: 2. Redistributions in binary form must reproduce the above copyright
014: notice, this list of conditions, and the disclaimer that follows
015: these conditions in the documentation and/or other materials
016: provided with the distribution.
017:
018: 3. The names "OBE" and "Open Business Engine" must not be used to
019: endorse or promote products derived from this software without prior
020: written permission. For written permission, please contact
021: adrianprice@sourceforge.net.
022:
023: 4. Products derived from this software may not be called "OBE" or
024: "Open Business Engine", nor may "OBE" or "Open Business Engine"
025: appear in their name, without prior written permission from
026: Adrian Price (adrianprice@users.sourceforge.net).
027:
028: THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
029: WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
030: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
031: DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
032: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
033: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
034: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
035: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
036: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
037: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
038: POSSIBILITY OF SUCH DAMAGE.
039:
040: For more information on OBE, please see
041: <http://obe.sourceforge.net/>.
042:
043: */
044:
045: package org.obe.engine.persistence;
046:
047: import org.obe.client.api.base.*;
048: import org.obe.spi.model.ActivityInstance;
049: import org.obe.spi.model.AttributeInstance;
050: import org.obe.spi.model.ProcessInstance;
051: import org.obe.spi.model.WorkItem;
052: import org.obe.xpdl.model.workflow.WorkflowProcess;
053: import org.wfmc.wapi.*;
054:
055: /**
056: * Creates WAPI value objects from run-time entities.
057: * TODO: use the factory pattern to enable different API implementations to
058: * use this class.
059: *
060: * @author Adrian Price
061: */
062: public final class WAPIHelper {
063: public static WMProcessDefinition fromWorkflowProcess(
064: WorkflowProcess workflow) {
065:
066: return new WMProcessDefinitionImpl(workflow.getId(), workflow
067: .getPackage().getId(), workflow.getName(),
068: WMProcessDefinitionState.valueOf(workflow.getState()));
069: }
070:
071: public static WMProcessDefinition[] fromWorkflowProcesses(
072: WorkflowProcess[] workflows) {
073:
074: WMProcessDefinition[] wmWorkflows = new WMProcessDefinition[workflows.length];
075: for (int i = 0; i < workflows.length; i++) {
076: WorkflowProcess workflow = workflows[i];
077: if (workflow == null)
078: break;
079: wmWorkflows[i] = new WMProcessDefinitionImpl(workflow
080: .getId(), workflow.getPackage().getId(), workflow
081: .getName(), WMProcessDefinitionState
082: .valueOf(workflow.getState()));
083: }
084: return wmWorkflows;
085: }
086:
087: public static WMProcessInstance fromProcessInstance(
088: ProcessInstance process) {
089:
090: ActivityInstance parentActivityInstance = process
091: .getParentActivityInstance();
092: return new WMProcessInstanceImpl(
093: process.getName(),
094: process.getProcessInstanceId(),
095: process.getProcessDefinitionId(),
096: parentActivityInstance == null ? null
097: : parentActivityInstance
098: .getActivityInstanceId(),
099: parentActivityInstance == null ? null
100: : parentActivityInstance.getProcessInstanceId(),
101: WMProcessInstanceState.valueOf(process.getState()),
102: process.getPriority(), fromParticipantNames(process
103: .getParticipants()), process.getCreatedDate(),
104: process.getStartedDate(), process.getTargetDate(),
105: process.getDueDate(), process.getCompletedDate(),
106: process.getActivityTargetDate(), process
107: .getActivityDueDate());
108: }
109:
110: public static WMProcessInstance[] fromProcessInstances(
111: ProcessInstance[] processes) {
112:
113: WMProcessInstance[] wmProcesses = new WMProcessInstance[processes.length];
114: for (int i = 0; i < processes.length; i++) {
115: ProcessInstance process = processes[i];
116: if (process == null)
117: break;
118: ActivityInstance parentActivityInstance = process
119: .getParentActivityInstance();
120: wmProcesses[i] = new WMProcessInstanceImpl(process
121: .getName(), process.getProcessInstanceId(), process
122: .getProcessDefinitionId(),
123: parentActivityInstance == null ? null
124: : parentActivityInstance
125: .getActivityInstanceId(),
126: parentActivityInstance == null ? null
127: : parentActivityInstance
128: .getProcessInstanceId(),
129: WMProcessInstanceState.valueOf(process.getState()),
130: process.getPriority(), fromParticipantNames(process
131: .getParticipants()), process
132: .getCreatedDate(),
133: process.getStartedDate(), process.getTargetDate(),
134: process.getDueDate(), process.getCompletedDate(),
135: process.getActivityTargetDate(), process
136: .getActivityDueDate());
137: }
138: return wmProcesses;
139: }
140:
141: public static WMActivityInstance fromActivityInstance(
142: ActivityInstance activity) {
143:
144: return new WMActivityInstanceImpl(activity
145: .getActivityInstanceId(), activity.getName(), activity
146: .getActivityDefinitionId(), activity
147: .getProcessInstanceId(), activity
148: .getProcessDefinitionId(), activity.getPriority(),
149: activity.getStartedDate(), activity.getTargetDate(),
150: activity.getDueDate(), activity.getCompletedDate(),
151: WMActivityInstanceState.valueOf(activity.getState()),
152: fromParticipantNames(activity.getParticipants()));
153: }
154:
155: public static WMActivityInstance[] fromActivityInstances(
156: ActivityInstance[] activities) {
157:
158: WMActivityInstance[] wmActivities = new WMActivityInstance[activities.length];
159: for (int i = 0; i < activities.length; i++) {
160: ActivityInstance activity = activities[i];
161: if (activity == null)
162: break;
163: wmActivities[i] = new WMActivityInstanceImpl(activity
164: .getActivityInstanceId(), activity.getName(),
165: activity.getActivityDefinitionId(), activity
166: .getProcessInstanceId(), activity
167: .getProcessDefinitionId(), activity
168: .getPriority(), activity.getStartedDate(),
169: activity.getTargetDate(), activity.getDueDate(),
170: activity.getCompletedDate(),
171: WMActivityInstanceState
172: .valueOf(activity.getState()),
173: fromParticipantNames(activity.getParticipants()));
174: }
175: return wmActivities;
176: }
177:
178: public static WMWorkItem fromWorkItem(WorkItem workItem) {
179: return new WMWorkItemImpl(workItem.getWorkItemId(), workItem
180: .getName(), workItem.getActivityInstanceId(), workItem
181: .getActivityDefinitionId(), workItem
182: .getProcessInstanceId(), workItem
183: .getProcessDefinitionId(), workItem.getPriority(),
184: workItem.getStartedDate(), workItem.getTargetDate(),
185: workItem.getDueDate(), workItem.getCompletedDate(),
186: workItem.getToolIndex(), WMWorkItemState
187: .valueOf(workItem.getState()),
188: new WMParticipantImpl(workItem.getParticipant()),
189: workItem.getPerformer());
190: }
191:
192: public static WMWorkItem[] fromWorkItems(WorkItem[] workitems) {
193: WMWorkItem[] wmWorkItems = new WMWorkItem[workitems.length];
194: for (int i = 0; i < workitems.length; i++) {
195: WorkItem workItem = workitems[i];
196: if (workItem == null)
197: break;
198: wmWorkItems[i] = new WMWorkItemImpl(workItem
199: .getWorkItemId(), workItem.getName(), workItem
200: .getActivityInstanceId(), workItem
201: .getActivityDefinitionId(), workItem
202: .getProcessInstanceId(), workItem
203: .getProcessDefinitionId(), workItem.getPriority(),
204: workItem.getStartedDate(),
205: workItem.getTargetDate(), workItem.getDueDate(),
206: workItem.getCompletedDate(), workItem
207: .getToolIndex(), WMWorkItemState
208: .valueOf(workItem.getState()),
209: new WMParticipantImpl(workItem.getParticipant()),
210: workItem.getPerformer());
211: }
212: return wmWorkItems;
213: }
214:
215: public static WMAttribute fromAttributeInstance(
216: AttributeInstance attr) {
217:
218: return new WMAttributeImpl(attr.getName(), attr.getType(), attr
219: .getValue());
220: }
221:
222: public static WMAttribute[] fromAttributeInstances(
223: AttributeInstance[] attrs) {
224:
225: WMAttribute[] wmAttrs = new WMAttribute[attrs.length];
226: for (int i = 0; i < attrs.length; i++) {
227: AttributeInstance attr = attrs[i];
228: if (attr == null)
229: break;
230: wmAttrs[i] = new WMAttributeImpl(attr.getName(), attr
231: .getType(), attr.getValue());
232: }
233: return wmAttrs;
234: }
235:
236: private static WMParticipant[] fromParticipantNames(
237: String[] participantNames) {
238:
239: WMParticipant[] participants = new WMParticipant[participantNames.length];
240: for (int i = 0; i < participantNames.length; i++) {
241: participants[i] = new WMParticipantImpl(participantNames[i]);
242: }
243: return participants;
244: }
245:
246: // Prevent instantiation.
247: private WAPIHelper() {
248: }
249: }
|