01: package org.obe.runtime.strategy;
02:
03: import org.obe.spi.WorkflowContext;
04: import org.obe.spi.model.ActivityInstance;
05: import org.obe.spi.model.WorkItem;
06: import org.obe.spi.runtime.CompletionStrategy;
07: import org.wfmc.wapi.WMActivityInstanceState;
08: import org.wfmc.wapi.WMWorkItemState;
09: import org.wfmc.wapi.WMWorkflowException;
10:
11: import java.util.Collection;
12: import java.util.Iterator;
13:
14: /**
15: * Completes an activity when all of its work items are closed.
16: *
17: * @author Adrian Price
18: */
19: public class AllCompletionStrategy implements CompletionStrategy {
20: public WMActivityInstanceState apply(WorkflowContext ctx)
21: throws WMWorkflowException {
22:
23: ActivityInstance activityInstance = ctx.getActivityInstance();
24: WMActivityInstanceState activityState = WMActivityInstanceState
25: .valueOf(activityInstance.getState());
26: Collection workItems = activityInstance.getWorkItems();
27: for (Iterator iter = workItems.iterator(); iter.hasNext();) {
28: WorkItem wi = (WorkItem) iter.next();
29: WMWorkItemState state = WMWorkItemState.valueOf(wi
30: .getState());
31: if (state.isOpen())
32: return activityState;
33: }
34: return WMActivityInstanceState.CLOSED_COMPLETED;
35: }
36: }
|