KickJava   Java API By Example, From Geeks To Geeks.

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


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.workflow.Condition;
10 import com.opensymphony.workflow.StoreException;
11 import com.opensymphony.workflow.WorkflowContext;
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 owner is the caller. Looks at
21  * ALL current steps unless a stepId is given in the optional argument "stepId".
22  *
23  * @author <a HREF="mailto:plightbo@hotmail.com">Pat Lightbody</a>
24  */

25 public class AllowOwnerOnlyCondition implements Condition {
26     //~ Methods ////////////////////////////////////////////////////////////////
27

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