Coverage Report - org.kuali.rice.krms.framework.engine.ResultLogger
 
Classes in this File Line Coverage Branch Coverage Complexity
ResultLogger
88%
15/17
60%
6/10
1.571
ResultLogger$1
N/A
N/A
1.571
ResultLogger$KRMSLoggerLoader
100%
2/2
N/A
1.571
 
 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  
         /*using inner class provides thread safety.         */
 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  
          * This method is just for the POC.
 36  
          * In the real world, adding listeners will be performed elsewhere.
 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  106
                 if (isEnabled(event.getEnvironment())){
 45  
                         // fire event to listeners
 46  106
                         Object[] listeners = listenerList.getListenerList();
 47  2922
                         for (int i=1; i<listeners.length; i+=2){
 48  2816
                                 ((ResultListener) listeners[i]).handleEvent(event);
 49  
                         }
 50  
                 }
 51  106
         }
 52  
 
 53  
         public boolean isEnabled(ExecutionEnvironment environment){
 54  208
             return (
 55  
                     environment != null 
 56  
                     && environment.getExecutionOptions() != null 
 57  
                     && environment.getExecutionOptions().getFlag(ExecutionFlag.LOG_EXECUTION)
 58  
             );
 59  
         }
 60  
 }