1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.framework.engine;
17
18 import javax.swing.event.EventListenerList;
19
20 import org.kuali.rice.krms.api.engine.ExecutionEnvironment;
21 import org.kuali.rice.krms.api.engine.ExecutionFlag;
22 import org.kuali.rice.krms.api.engine.ResultEvent;
23 import org.kuali.rice.krms.framework.engine.result.EngineResultListener;
24 import org.kuali.rice.krms.framework.engine.result.Log4jResultListener;
25 import org.kuali.rice.krms.framework.engine.result.ResultListener;
26
27
28
29
30
31
32 public class ResultLogger {
33 private EventListenerList listenerList = new EventListenerList();
34
35 private ResultLogger(){}
36
37
38 private static class KRMSLoggerLoader{
39 private static final ResultLogger INSTANCE = new ResultLogger();
40 }
41
42
43
44
45 public static ResultLogger getInstance(){
46 return KRMSLoggerLoader.INSTANCE;
47 }
48
49
50
51
52
53 public void addListener(ResultListener resultListener) {
54 listenerList.add(ResultListener.class, resultListener);
55 }
56
57
58
59
60
61 public void removeListener(ResultListener resultListener){
62 listenerList.remove(ResultListener.class, resultListener);
63 }
64
65
66
67
68
69 public void logResult(ResultEvent event){
70 if (isEnabled(event.getEnvironment())){
71
72 Object[] listeners = listenerList.getListenerList();
73 for (int i=1; i<listeners.length; i+=2){
74 ((ResultListener) listeners[i]).handleEvent(event);
75 }
76 }
77 }
78
79
80
81
82
83
84 public boolean isEnabled(ExecutionEnvironment environment){
85 return (
86 environment != null
87 && environment.getExecutionOptions() != null
88 && environment.getExecutionOptions().getFlag(ExecutionFlag.LOG_EXECUTION)
89 );
90 }
91 }