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