KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Simple utility condition that returns true if the current step's status is
21  * the same as the required argument "status". Looks at ALL current steps unless
22  * a stepId is given in the optional argument "stepId".
23  *
24  * @author <a HREF="mailto:plightbo@hotmail.com">Pat Lightbody</a>
25  */

26 public class StatusCondition implements Condition {
27     //~ Methods ////////////////////////////////////////////////////////////////
28

29     public boolean passesCondition(Map transientVars, Map args, PropertySet ps) throws StoreException {
30         String JavaDoc status = TextUtils.noNull((String JavaDoc) args.get("status"));
31         int stepId = 0;
32         Object JavaDoc stepIdVal = args.get("stepId");
33
34         if (stepIdVal != null) {
35             try {
36                 stepId = Integer.parseInt(stepIdVal.toString());
37             } catch (Exception JavaDoc ex) {
38             }
39         }
40
41         WorkflowEntry entry = (WorkflowEntry) transientVars.get("entry");
42         WorkflowStore store = (WorkflowStore) transientVars.get("store");
43         List currentSteps = store.findCurrentSteps(entry.getId());
44
45         if (stepId == 0) {
46             for (Iterator iterator = currentSteps.iterator();
47                     iterator.hasNext();) {
48                 Step step = (Step) iterator.next();
49
50                 if (status.equals(step.getStatus())) {
51                     return true;
52                 }
53             }
54         } else {
55             for (Iterator iterator = currentSteps.iterator();
56                     iterator.hasNext();) {
57                 Step step = (Step) iterator.next();
58
59                 if (stepId == step.getStepId()) {
60                     if (status.equals(step.getStatus())) {
61                         return true;
62                     }
63                 }
64             }
65         }
66
67         return false;
68     }
69 }
70
Popular Tags