Coverage Report - org.kuali.rice.krms.framework.engine.ResultLogger
 
Classes in this File Line Coverage Branch Coverage Complexity
ResultLogger
64%
9/14
50%
5/10
1.667
ResultLogger$1
N/A
N/A
1.667
ResultLogger$KRMSLoggerLoader
100%
2/2
N/A
1.667
 
 1  
 /**
 2  
  * Copyright 2005-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 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  
         /*using inner class provides thread safety.         */
 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  
                         // fire event to listeners
 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  
 }