KickJava   Java API By Example, From Geeks To Geeks.

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


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.Condition;
12 import com.opensymphony.workflow.StoreException;
13 import com.opensymphony.workflow.WorkflowContext;
14 import com.opensymphony.workflow.spi.Step;
15 import com.opensymphony.workflow.spi.WorkflowEntry;
16 import com.opensymphony.workflow.spi.WorkflowStore;
17
18 import java.util.*;
19
20
21 /**
22  * Simple utility condition that returns false if the owner is the caller. Looks at
23  * ALL current steps unless a stepId is given in the optional argument "stepId".
24  *
25  * @author <a HREF="mailto:plightbo@hotmail.com">Pat Lightbody</a>
26  */

27 public class DenyOwnerCondition implements Condition {
28     //~ Methods ////////////////////////////////////////////////////////////////
29

30     public boolean passesCondition(Map transientVars, Map args, PropertySet ps) throws StoreException {
31         int stepId = TextUtils.parseInt((String JavaDoc) args.get("stepId"));
32         WorkflowContext context = (WorkflowContext) transientVars.get("context");
33         WorkflowEntry entry = (WorkflowEntry) transientVars.get("entry");
34         WorkflowStore store = (WorkflowStore) transientVars.get("store");
35         List currentSteps = store.findCurrentSteps(entry.getId());
36
37         if (stepId == 0) {
38             for (Iterator iterator = currentSteps.iterator();
39                     iterator.hasNext();) {
40                 Step step = (Step) iterator.next();
41
42                 if (context.getCaller().equals(step.getOwner())) {
43                     return false;
44                 }
45             }
46         } else {
47             for (Iterator iterator = currentSteps.iterator();
48                     iterator.hasNext();) {
49                 Step step = (Step) iterator.next();
50
51                 if (stepId == step.getStepId()) {
52                     if (context.getCaller().equals(step.getOwner())) {
53                         return false;
54                     } else {
55                         return true;
56                     }
57                 }
58             }
59         }
60
61         return true;
62     }
63 }
64
Popular Tags