1 | |
package org.kuali.rice.krms.framework.engine; |
2 | |
|
3 | |
import java.util.ArrayList; |
4 | |
import java.util.Collections; |
5 | |
import java.util.List; |
6 | |
import java.util.Map; |
7 | |
|
8 | |
import org.kuali.rice.krms.api.Agenda; |
9 | |
import org.kuali.rice.krms.api.AssetResolver; |
10 | |
import org.kuali.rice.krms.api.Context; |
11 | |
import org.kuali.rice.krms.api.ExecutionEnvironment; |
12 | |
|
13 | |
public class BasicContext implements Context { |
14 | |
|
15 | |
private Map<String, String> qualifiers; |
16 | |
private List<Agenda> agendas; |
17 | |
private List<AssetResolver<?>> assetResolvers; |
18 | |
|
19 | 0 | public BasicContext(Map<String, String> qualifiers, List<Agenda> agendas, List<AssetResolver<?>> assetResolvers) { |
20 | 0 | this.qualifiers = qualifiers; |
21 | 0 | this.agendas = agendas; |
22 | 0 | this.assetResolvers = assetResolvers; |
23 | 0 | } |
24 | |
|
25 | |
@Override |
26 | |
public void execute(ExecutionEnvironment environment) { |
27 | 0 | if (assetResolvers != null) for (AssetResolver<?> assetResolver : assetResolvers) { |
28 | 0 | environment.addAssetResolver(assetResolver); |
29 | |
} |
30 | 0 | List<Agenda> matchingAgendas = findMatchingAgendas(environment); |
31 | 0 | for (Agenda matchingAgenda : matchingAgendas) { |
32 | 0 | matchingAgenda.execute(environment); |
33 | |
} |
34 | 0 | } |
35 | |
|
36 | |
protected List<Agenda> findMatchingAgendas(ExecutionEnvironment environment) { |
37 | 0 | List<Agenda> matchingAgendas = new ArrayList<Agenda>(); |
38 | 0 | for (Agenda agenda : agendas) { |
39 | 0 | if (agenda.appliesTo(environment)) { |
40 | 0 | matchingAgendas.add(agenda); |
41 | |
} |
42 | |
} |
43 | 0 | return matchingAgendas; |
44 | |
} |
45 | |
|
46 | |
@Override |
47 | |
public boolean appliesTo(ExecutionEnvironment environment) { |
48 | 0 | for (String contextQualifierName : qualifiers.keySet()) { |
49 | 0 | String qualifierValue = qualifiers.get(contextQualifierName); |
50 | 0 | String environmentQualifierValue = environment.getSelectionCriteria().getContextQualifiers().get(qualifierValue); |
51 | 0 | if (!qualifierValue.equals(environmentQualifierValue)) { |
52 | 0 | return false; |
53 | |
} |
54 | 0 | } |
55 | 0 | return true; |
56 | |
} |
57 | |
|
58 | |
public List<AssetResolver<?>> getAssetResolvers() { |
59 | 0 | return Collections.unmodifiableList(assetResolvers); |
60 | |
} |
61 | |
|
62 | |
} |