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 java.util.Collections;
19 import java.util.List;
20
21 import org.kuali.rice.krms.api.engine.ExecutionEnvironment;
22 import org.kuali.rice.krms.api.repository.proposition.PropositionDefinition;
23 import org.kuali.rice.krms.api.repository.type.KrmsTypeDefinition;
24 import org.kuali.rice.krms.framework.engine.Proposition;
25 import org.kuali.rice.krms.framework.engine.PropositionResult;
26 import org.kuali.rice.krms.framework.type.PropositionTypeService;
27 import org.kuali.rice.krms.impl.type.KrmsTypeResolver;
28
29
30
31
32
33
34
35 final class LazyProposition implements Proposition {
36
37 private final PropositionDefinition propositionDefinition;
38 private final KrmsTypeResolver resolver;
39
40 private final Object mutex = new Object();
41
42
43 private volatile Proposition proposition;
44
45 LazyProposition(PropositionDefinition propositionDefinition, KrmsTypeResolver resolver) {
46 this.propositionDefinition = propositionDefinition;
47 this.resolver = resolver;
48 this.proposition = null;
49 }
50
51 @Override
52 public PropositionResult evaluate(ExecutionEnvironment environment) {
53 return getProposition().evaluate(environment);
54 }
55
56
57
58
59 private Proposition getProposition() {
60 Proposition localProposition = proposition;
61 if (localProposition == null) {
62 synchronized (mutex) {
63 localProposition = proposition;
64 if (localProposition == null) {
65 proposition = localProposition = constructProposition();
66 }
67 }
68 }
69 return localProposition;
70 }
71
72 private Proposition constructProposition() {
73 PropositionTypeService propositionTypeService = resolver.getPropositionTypeService(propositionDefinition);
74 Proposition proposition = propositionTypeService.loadProposition(propositionDefinition);
75 if (proposition == null) {
76 proposition = new Proposition() {
77 @Override
78 public PropositionResult evaluate(ExecutionEnvironment environment) {
79 return new PropositionResult(true);
80 }
81
82 @Override
83 public List<Proposition> getChildren() {
84 return Collections.emptyList();
85 }
86
87 @Override
88 public boolean isCompound() {
89 return false;
90 }
91 };
92 }
93 return proposition;
94 }
95
96 @Override
97 public List<Proposition> getChildren() {
98 return getProposition().getChildren();
99 }
100
101 @Override
102 public boolean isCompound() {
103 return getProposition().isCompound();
104 }
105 }