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
26
27
28
29 public final class BasicContext implements Context {
30
31 private final List<Agenda> agendas;
32 private final List<TermResolver<?>> termResolvers;
33
34
35
36
37
38
39 public BasicContext(List<Agenda> agendas, List<TermResolver<?>> termResolvers) {
40 this.agendas = agendas;
41 this.termResolvers = termResolvers;
42 }
43
44 @Override
45 public void execute(ExecutionEnvironment environment) {
46 if (termResolvers != null) for (TermResolver<?> termResolver : termResolvers) {
47 environment.addTermResolver(termResolver);
48 }
49 List<Agenda> matchingAgendas = findMatchingAgendas(environment);
50 for (Agenda matchingAgenda : matchingAgendas) {
51 matchingAgenda.execute(environment);
52 }
53 }
54
55
56
57
58
59
60 private List<Agenda> findMatchingAgendas(ExecutionEnvironment environment) {
61 List<Agenda> matchingAgendas = new ArrayList<Agenda>();
62 for (Agenda agenda : agendas) {
63 if (agenda.appliesTo(environment)) {
64 matchingAgendas.add(agenda);
65 }
66 }
67 return matchingAgendas;
68 }
69
70 @Override
71 public List<TermResolver<?>> getTermResolvers() {
72 return Collections.unmodifiableList(termResolvers);
73 }
74
75 }