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