001 /** 002 * Copyright 2005-2011 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.rice.krms.framework.engine; 017 018 import java.util.ArrayList; 019 import java.util.Collections; 020 import java.util.List; 021 022 import org.kuali.rice.krms.api.engine.ExecutionEnvironment; 023 import org.kuali.rice.krms.api.engine.TermResolver; 024 025 public final class BasicContext implements Context { 026 027 private final List<Agenda> agendas; 028 private final List<TermResolver<?>> termResolvers; 029 030 public BasicContext(List<Agenda> agendas, List<TermResolver<?>> termResolvers) { 031 this.agendas = agendas; 032 this.termResolvers = termResolvers; 033 } 034 035 @Override 036 public void execute(ExecutionEnvironment environment) { 037 if (termResolvers != null) for (TermResolver<?> termResolver : termResolvers) { 038 environment.addTermResolver(termResolver); 039 } 040 List<Agenda> matchingAgendas = findMatchingAgendas(environment); 041 for (Agenda matchingAgenda : matchingAgendas) { 042 matchingAgenda.execute(environment); 043 } 044 } 045 046 private List<Agenda> findMatchingAgendas(ExecutionEnvironment environment) { 047 List<Agenda> matchingAgendas = new ArrayList<Agenda>(); 048 for (Agenda agenda : agendas) { 049 if (agenda.appliesTo(environment)) { 050 matchingAgendas.add(agenda); 051 } 052 } 053 return matchingAgendas; 054 } 055 056 public List<TermResolver<?>> getTermResolvers() { 057 return Collections.unmodifiableList(termResolvers); 058 } 059 060 }