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 public class ResultLogger {
28 private EventListenerList listenerList = new EventListenerList();
29
30 private ResultLogger(){}
31
32
33 private static class KRMSLoggerLoader{
34 private static final ResultLogger INSTANCE = new ResultLogger();
35 }
36
37 public static ResultLogger getInstance(){
38 return KRMSLoggerLoader.INSTANCE;
39 }
40
41 public void addListener(ResultListener l) {
42 listenerList.add(ResultListener.class, l);
43 }
44
45 public void removeListener(ResultListener l){
46 listenerList.remove(ResultListener.class, l);
47 }
48
49 public void logResult(ResultEvent event){
50 if (isEnabled(event.getEnvironment())){
51
52 Object[] listeners = listenerList.getListenerList();
53 for (int i=1; i<listeners.length; i+=2){
54 ((ResultListener) listeners[i]).handleEvent(event);
55 }
56 }
57 }
58
59 public boolean isEnabled(ExecutionEnvironment environment){
60 return (
61 environment != null
62 && environment.getExecutionOptions() != null
63 && environment.getExecutionOptions().getFlag(ExecutionFlag.LOG_EXECUTION)
64 );
65 }
66 }