1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.krms.impl.provider.repository; |
17 | |
|
18 | |
import org.kuali.rice.krms.api.engine.ExecutionEnvironment; |
19 | |
import org.kuali.rice.krms.api.repository.rule.RuleDefinition; |
20 | |
import org.kuali.rice.krms.framework.engine.Rule; |
21 | |
import org.kuali.rice.krms.framework.type.RuleTypeService; |
22 | |
import org.kuali.rice.krms.impl.type.KrmsTypeResolver; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
final class LazyRule implements Rule { |
31 | |
|
32 | |
private final RuleDefinition ruleDefinition; |
33 | |
private final KrmsTypeResolver typeResolver; |
34 | |
|
35 | 0 | private final Object mutex = new Object(); |
36 | |
|
37 | |
|
38 | |
private volatile Rule rule; |
39 | |
|
40 | 0 | LazyRule(RuleDefinition ruleDefinition, KrmsTypeResolver typeResolver) { |
41 | 0 | this.ruleDefinition = ruleDefinition; |
42 | 0 | this.typeResolver = typeResolver; |
43 | 0 | this.rule = null; |
44 | 0 | } |
45 | |
|
46 | |
@Override |
47 | |
public boolean evaluate(ExecutionEnvironment environment) { |
48 | 0 | return getRule().evaluate(environment); |
49 | |
} |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
private Rule getRule() { |
55 | 0 | Rule localRule = rule; |
56 | 0 | if (localRule == null) { |
57 | 0 | synchronized (mutex) { |
58 | 0 | localRule = rule; |
59 | 0 | if (localRule == null) { |
60 | 0 | rule = localRule = constructRule(); |
61 | |
} |
62 | 0 | } |
63 | |
} |
64 | 0 | return localRule; |
65 | |
} |
66 | |
|
67 | |
private Rule constructRule() { |
68 | 0 | RuleTypeService ruleTypeService = typeResolver.getRuleTypeService(ruleDefinition); |
69 | 0 | Rule rule = ruleTypeService.loadRule(ruleDefinition); |
70 | 0 | if (rule == null) { |
71 | 0 | rule = new Rule() { |
72 | |
@Override |
73 | |
public boolean evaluate(ExecutionEnvironment environment) { |
74 | 0 | return false; |
75 | |
} |
76 | |
}; |
77 | |
} |
78 | 0 | return rule; |
79 | |
} |
80 | |
|
81 | |
|
82 | |
} |