KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > workflow > util > MostRecentOwner


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.workflow.util;
6
7 import com.opensymphony.module.propertyset.PropertySet;
8
9 import com.opensymphony.util.TextUtils;
10
11 import com.opensymphony.workflow.*;
12 import com.opensymphony.workflow.spi.Step;
13 import com.opensymphony.workflow.spi.WorkflowEntry;
14 import com.opensymphony.workflow.spi.WorkflowStore;
15
16 import java.util.*;
17
18
19 /**
20  * Sets the persistent variable "mostRecentOwner" to the owner of the most
21  * recent step that had an id equal to one of the values in the stepId list. If there is
22  * none found, the variable is unset. This function accepts the following
23  * arguments:
24  *
25  * <ul>
26  * <li>stepId - a comma-seperated list of the most recent steps to look for (required)</li>
27  * </ul>
28  *
29  * @author <a HREF="mailto:plightbo@hotmail.com">Pat Lightbody</a>
30  * @author <a HREF="mailto:mischwar@cisco.com">Mike Schwartz</a>
31  * @version $Revision: 1.2 $
32  */

33 public class MostRecentOwner implements FunctionProvider {
34     //~ Methods ////////////////////////////////////////////////////////////////
35

36     public void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException {
37         // expects a stepId name/value pair
38
String JavaDoc stepIdString = (String JavaDoc) args.get("stepId");
39         WorkflowEntry entry = (WorkflowEntry) transientVars.get("entry");
40
41         if (stepIdString == null) {
42             throw new WorkflowException("This function expects a stepId!");
43         }
44
45         StringTokenizer st = new StringTokenizer(stepIdString, ",");
46         List stepIds = new LinkedList();
47
48         while (st.hasMoreTokens()) {
49             stepIds.add(st.nextToken().trim());
50         }
51
52         WorkflowStore store = (WorkflowStore) transientVars.get("store");
53         List historySteps = store.findHistorySteps(entry.getId());
54
55         for (Iterator iterator = historySteps.iterator(); iterator.hasNext();) {
56             Step step = (Step) iterator.next();
57
58             if (stepIds.contains(String.valueOf(step.getStepId())) && TextUtils.stringSet(step.getOwner())) {
59                 transientVars.put("mostRecentOwner", step.getOwner());
60
61                 break;
62             }
63         }
64     }
65 }
66
Popular Tags