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 | 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 | |
} |