View Javadoc

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  	public BasicContext(List<Agenda> agendas, List<TermResolver<?>> termResolvers) {
31  		this.agendas = agendas;
32  		this.termResolvers = termResolvers;
33  	}
34  	
35  	@Override
36  	public void execute(ExecutionEnvironment environment) {
37  		if (termResolvers != null) for (TermResolver<?> termResolver : termResolvers) {
38  			environment.addTermResolver(termResolver);
39  		}
40  		List<Agenda> matchingAgendas = findMatchingAgendas(environment);
41  		for (Agenda matchingAgenda : matchingAgendas) {
42  			matchingAgenda.execute(environment);
43  		}
44  	}
45  	
46  	private List<Agenda> findMatchingAgendas(ExecutionEnvironment environment) {
47  		List<Agenda> matchingAgendas = new ArrayList<Agenda>();
48  		for (Agenda agenda : agendas) {
49  			if (agenda.appliesTo(environment)) {
50  				matchingAgendas.add(agenda);
51  			}
52  		}
53  		return matchingAgendas;
54  	}
55  	
56  	public List<TermResolver<?>> getTermResolvers() {
57  		return Collections.unmodifiableList(termResolvers);
58  	}
59  
60  }