1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 }