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