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 | 0 | public class BranchServiceImpl implements BranchService { |
30 | 0 | private static final Logger LOG = Logger.getLogger(BranchServiceImpl.class); |
31 | |
|
32 | |
private BranchDAO branchDAO; |
33 | |
|
34 | |
public void save(Branch branch){ |
35 | 0 | getBranchDAO().save(branch); |
36 | 0 | } |
37 | |
|
38 | |
public BranchDAO getBranchDAO() { |
39 | 0 | return branchDAO; |
40 | |
} |
41 | |
public void setBranchDAO(BranchDAO branchDAO) { |
42 | 0 | this.branchDAO = branchDAO; |
43 | 0 | } |
44 | |
|
45 | |
public void deleteBranchStates(List statesToBeDeleted){ |
46 | 0 | getBranchDAO().deleteBranchStates(statesToBeDeleted); |
47 | 0 | } |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
private BranchState resolveScopedVariable(Branch branch, String name) { |
56 | 0 | Branch b = branch; |
57 | 0 | while (b != null) { |
58 | 0 | for (BranchState bs: b.getBranchState()) { |
59 | 0 | LOG.debug(bs); |
60 | |
} |
61 | 0 | LOG.debug("Resolving variable: '" + name + "' in scope (branch): '" + branch.getName() + "' (" + branch.getBranchId() + ")"); |
62 | 0 | BranchState bs = b.getBranchState(name); |
63 | 0 | if (bs != null) { |
64 | 0 | return bs; |
65 | |
} |
66 | 0 | b = b.getParentBranch(); |
67 | 0 | } |
68 | 0 | return null; |
69 | |
} |
70 | |
|
71 | |
public String getScopedVariableValue(Branch branch, String name) { |
72 | 0 | BranchState bs = resolveScopedVariable(branch, name); |
73 | 0 | if (bs != null) return bs.getValue(); |
74 | 0 | return null; |
75 | |
} |
76 | |
|
77 | |
public String setScopedVariableValue(Branch branch, String name, String value) { |
78 | 0 | LOG.debug("Setting scoped variable value: " + name + " " + value); |
79 | 0 | BranchState bs = resolveScopedVariable(branch, name); |
80 | 0 | String oldValue = null; |
81 | 0 | if (bs == null) { |
82 | 0 | LOG.debug("Defining new variable named '" + name + "' at scope '" + branch + "'"); |
83 | |
|
84 | 0 | bs = new BranchState(name, value); |
85 | 0 | bs.setBranch(branch); |
86 | 0 | branch.addBranchState(bs); |
87 | |
} else { |
88 | 0 | oldValue = bs.getValue(); |
89 | 0 | LOG.debug("Replacing old value of variable '" + name + "' (" + oldValue + ") at scope '" + branch + "' with new value: " + value); |
90 | 0 | bs.setValue(value); |
91 | |
} |
92 | |
|
93 | 0 | save(bs.getBranch()); |
94 | 0 | return oldValue; |
95 | |
} |
96 | |
|
97 | |
} |