1 | |
package org.kuali.rice.krms.framework.engine; |
2 | |
|
3 | |
import javax.swing.event.EventListenerList; |
4 | |
|
5 | |
import org.kuali.rice.krms.api.engine.ExecutionEnvironment; |
6 | |
import org.kuali.rice.krms.api.engine.ExecutionFlag; |
7 | |
import org.kuali.rice.krms.api.engine.ResultEvent; |
8 | |
import org.kuali.rice.krms.framework.engine.result.EngineResultListener; |
9 | |
import org.kuali.rice.krms.framework.engine.result.Log4jResultListener; |
10 | |
import org.kuali.rice.krms.framework.engine.result.ResultListener; |
11 | |
|
12 | 1 | public class ResultLogger { |
13 | 1 | private EventListenerList listenerList = new EventListenerList(); |
14 | |
|
15 | 2 | private ResultLogger(){} |
16 | |
|
17 | |
|
18 | 10 | private static class KRMSLoggerLoader{ |
19 | 1 | private static final ResultLogger INSTANCE = new ResultLogger(); |
20 | |
} |
21 | |
|
22 | |
public static ResultLogger getInstance(){ |
23 | 10 | return KRMSLoggerLoader.INSTANCE; |
24 | |
} |
25 | |
|
26 | |
public void addListener(ResultListener l) { |
27 | 58 | listenerList.add(ResultListener.class, l); |
28 | 58 | } |
29 | |
|
30 | |
public void removeListener(ResultListener l){ |
31 | 0 | listenerList.remove(ResultListener.class, l); |
32 | 0 | } |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
public void init(){ |
39 | 29 | addListener(new EngineResultListener()); |
40 | 29 | addListener(new Log4jResultListener()); |
41 | 29 | } |
42 | |
|
43 | |
public void logResult(ResultEvent event){ |
44 | 103 | if (isEnabled(event.getEnvironment())){ |
45 | |
|
46 | 103 | Object[] listeners = listenerList.getListenerList(); |
47 | 2881 | for (int i=1; i<listeners.length; i+=2){ |
48 | 2778 | ((ResultListener) listeners[i]).handleEvent(event); |
49 | |
} |
50 | |
} |
51 | 103 | } |
52 | |
|
53 | |
public boolean isEnabled(ExecutionEnvironment environment){ |
54 | 205 | return ( |
55 | |
environment != null |
56 | |
&& environment.getExecutionOptions() != null |
57 | |
&& environment.getExecutionOptions().getFlag(ExecutionFlag.LOG_EXECUTION) |
58 | |
); |
59 | |
} |
60 | |
} |