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