Coverage Report - org.kuali.rice.krms.framework.engine.ResultLogger
 
Classes in this File Line Coverage Branch Coverage Complexity
ResultLogger
0%
0/20
0%
0/6
1.571
ResultLogger$1
N/A
N/A
1.571
ResultLogger$KRMSLoggerLoader
0%
0/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.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  
         /*using inner class provides thread safety.         */
 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  
          * This method is just for the POC.
 36  
          * In the real world, adding listeners will be performed elsewhere.
 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  
                         // fire event to listeners
 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  
 }