1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.engine.node.service.impl;
17
18 import java.util.List;
19
20 import org.apache.log4j.Logger;
21 import org.kuali.rice.kew.engine.node.Branch;
22 import org.kuali.rice.kew.engine.node.BranchState;
23 import org.kuali.rice.kew.engine.node.dao.BranchDAO;
24 import org.kuali.rice.kew.engine.node.service.BranchService;
25
26
27
28 public class BranchServiceImpl implements BranchService {
29 private static final Logger LOG = Logger.getLogger(BranchServiceImpl.class);
30
31 private BranchDAO branchDAO;
32
33 public void save(Branch branch){
34 getBranchDAO().save(branch);
35 }
36
37 public BranchDAO getBranchDAO() {
38 return branchDAO;
39 }
40 public void setBranchDAO(BranchDAO branchDAO) {
41 this.branchDAO = branchDAO;
42 }
43
44 public void deleteBranchStates(List statesToBeDeleted){
45 getBranchDAO().deleteBranchStates(statesToBeDeleted);
46 }
47
48
49
50
51
52
53
54 private BranchState resolveScopedVariable(Branch branch, String name) {
55 Branch b = branch;
56 while (b != null) {
57 for (BranchState bs: b.getBranchState()) {
58 LOG.debug(bs);
59 }
60 LOG.debug("Resolving variable: '" + name + "' in scope (branch): '" + branch.getName() + "' (" + branch.getBranchId() + ")");
61 BranchState bs = b.getBranchState(name);
62 if (bs != null) {
63 return bs;
64 }
65 b = b.getParentBranch();
66 }
67 return null;
68 }
69
70 public String getScopedVariableValue(Branch branch, String name) {
71 BranchState bs = resolveScopedVariable(branch, name);
72 if (bs != null) return bs.getValue();
73 return null;
74 }
75
76 public String setScopedVariableValue(Branch branch, String name, String value) {
77 LOG.debug("Setting scoped variable value: " + name + " " + value);
78 BranchState bs = resolveScopedVariable(branch, name);
79 String oldValue = null;
80 if (bs == null) {
81 LOG.debug("Defining new variable named '" + name + "' at scope '" + branch + "'");
82
83 bs = new BranchState();
84 bs.setKey(name);
85 bs.setValue(value);
86 bs.setBranch(branch);
87 branch.addBranchState(bs);
88 } else {
89 oldValue = bs.getValue();
90 LOG.debug("Replacing old value of variable '" + name + "' (" + oldValue + ") at scope '" + branch + "' with new value: " + value);
91 bs.setValue(value);
92 }
93
94 save(bs.getBranch());
95 return oldValue;
96 }
97
98 }