Coverage Report - org.kuali.rice.krms.framework.engine.BasicContext
 
Classes in this File Line Coverage Branch Coverage Complexity
BasicContext
93%
15/16
80%
8/10
2.25
 
 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 java.util.ArrayList;
 19  
 import java.util.Collections;
 20  
 import java.util.List;
 21  
 
 22  
 import org.kuali.rice.krms.api.engine.ExecutionEnvironment;
 23  
 import org.kuali.rice.krms.api.engine.TermResolver;
 24  
 
 25  
 public final class BasicContext implements Context {
 26  
         
 27  
         private final List<Agenda> agendas;
 28  
         private final List<TermResolver<?>> termResolvers;
 29  
         
 30  29
         public BasicContext(List<Agenda> agendas, List<TermResolver<?>> termResolvers) {
 31  29
                 this.agendas = agendas;
 32  29
                 this.termResolvers = termResolvers;
 33  29
         }
 34  
         
 35  
         @Override
 36  
         public void execute(ExecutionEnvironment environment) {
 37  29
                 if (termResolvers != null) for (TermResolver<?> termResolver : termResolvers) {
 38  29
                         environment.addTermResolver(termResolver);
 39  
                 }
 40  29
                 List<Agenda> matchingAgendas = findMatchingAgendas(environment);
 41  29
                 for (Agenda matchingAgenda : matchingAgendas) {
 42  29
                         matchingAgenda.execute(environment);
 43  
                 }
 44  29
         }
 45  
         
 46  
         private List<Agenda> findMatchingAgendas(ExecutionEnvironment environment) {
 47  29
                 List<Agenda> matchingAgendas = new ArrayList<Agenda>();
 48  29
                 for (Agenda agenda : agendas) {
 49  29
                         if (agenda.appliesTo(environment)) {
 50  29
                                 matchingAgendas.add(agenda);
 51  
                         }
 52  
                 }
 53  29
                 return matchingAgendas;
 54  
         }
 55  
         
 56  
         public List<TermResolver<?>> getTermResolvers() {
 57  0
                 return Collections.unmodifiableList(termResolvers);
 58  
         }
 59  
 
 60  
 }