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