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.action.ActionDefinition; |
20 | |
import org.kuali.rice.krms.api.repository.type.KrmsTypeDefinition; |
21 | |
import org.kuali.rice.krms.framework.engine.Action; |
22 | |
import org.kuali.rice.krms.framework.type.ActionTypeService; |
23 | |
import org.kuali.rice.krms.impl.type.KrmsTypeResolver; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
final class LazyAction implements Action { |
32 | |
|
33 | |
private final ActionDefinition actionDefinition; |
34 | |
private final KrmsTypeResolver typeResolver; |
35 | |
|
36 | 0 | private final Object mutex = new Object(); |
37 | |
|
38 | |
|
39 | |
private volatile Action action; |
40 | |
|
41 | 0 | LazyAction(ActionDefinition actionDefinition, KrmsTypeResolver typeResolver) { |
42 | 0 | this.actionDefinition = actionDefinition; |
43 | 0 | this.typeResolver = typeResolver; |
44 | 0 | this.action = null; |
45 | 0 | } |
46 | |
|
47 | |
@Override |
48 | |
public void execute(ExecutionEnvironment environment) { |
49 | 0 | getAction().execute(environment); |
50 | 0 | } |
51 | |
|
52 | |
@Override |
53 | |
public void executeSimulation(ExecutionEnvironment environment) { |
54 | 0 | getAction().executeSimulation(environment); |
55 | 0 | } |
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
private Action getAction() { |
61 | 0 | Action localAction = action; |
62 | 0 | if (localAction == null) { |
63 | 0 | synchronized (mutex) { |
64 | 0 | localAction = action; |
65 | 0 | if (localAction == null) { |
66 | 0 | action = localAction = constructAction(); |
67 | |
} |
68 | 0 | } |
69 | |
} |
70 | 0 | return localAction; |
71 | |
} |
72 | |
|
73 | |
private Action constructAction() { |
74 | 0 | ActionTypeService actionTypeService = typeResolver.getActionTypeService(actionDefinition); |
75 | 0 | Action action = actionTypeService.loadAction(actionDefinition); |
76 | 0 | if (action == null) { |
77 | 0 | action = new Action() { |
78 | |
@Override |
79 | |
public void execute(ExecutionEnvironment environment) { |
80 | 0 | } |
81 | |
public void executeSimulation(ExecutionEnvironment environment) { |
82 | 0 | } |
83 | |
}; |
84 | |
} |
85 | 0 | return action; |
86 | |
} |
87 | |
|
88 | |
|
89 | |
} |