1 | |
package org.kuali.rice.krms.framework.engine; |
2 | |
|
3 | |
import javax.swing.event.EventListenerList; |
4 | |
|
5 | |
import org.kuali.rice.krms.api.ExecutionEnvironment; |
6 | |
import org.kuali.rice.krms.api.ResultEvent; |
7 | |
import org.kuali.rice.krms.api.ResultListener; |
8 | |
import org.kuali.rice.krms.api.ExecutionOptions; |
9 | |
import org.kuali.rice.krms.framework.engine.result.EngineResultListener; |
10 | |
import org.kuali.rice.krms.framework.engine.result.Log4jResultListener; |
11 | |
|
12 | 0 | public class ResultLogger { |
13 | 0 | private EventListenerList listenerList = new EventListenerList(); |
14 | |
|
15 | 0 | private ResultLogger(){} |
16 | |
|
17 | |
|
18 | 0 | private static class KRMSLoggerLoader{ |
19 | 0 | private static final ResultLogger INSTANCE = new ResultLogger(); |
20 | |
} |
21 | |
|
22 | |
public static ResultLogger getInstance(){ |
23 | 0 | return KRMSLoggerLoader.INSTANCE; |
24 | |
} |
25 | |
|
26 | |
public void addListener(ResultListener l) { |
27 | 0 | listenerList.add(ResultListener.class, l); |
28 | 0 | } |
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 | 0 | addListener(new EngineResultListener()); |
40 | 0 | addListener(new Log4jResultListener()); |
41 | 0 | } |
42 | |
|
43 | |
public void logResult(ResultEvent event){ |
44 | 0 | if (isEnabled(event.getEnvironment())){ |
45 | |
|
46 | 0 | Object[] listeners = listenerList.getListenerList(); |
47 | 0 | for (int i=1; i<listeners.length; i+=2){ |
48 | 0 | ((ResultListener) listeners[i]).handleEvent(event); |
49 | |
} |
50 | |
} |
51 | 0 | } |
52 | |
|
53 | |
public boolean isEnabled(ExecutionEnvironment environment){ |
54 | 0 | String logEnabled = environment.getExecutionOptions().get(ExecutionOptions.LOG_EXECUTION.toString()); |
55 | 0 | if (logEnabled != null ){ |
56 | 0 | return true; |
57 | |
} |
58 | 0 | return false; |
59 | |
} |
60 | |
} |