01: /*
02: * Created on 5 Feb 2007
03: */
04: package uk.org.ponder.rsf.flow.support;
05:
06: import java.util.ArrayList;
07: import java.util.List;
08:
09: import uk.org.ponder.rsf.flow.ARIResult;
10: import uk.org.ponder.rsf.flow.ActionResultInterceptor;
11: import uk.org.ponder.rsf.view.MappingViewResolver;
12: import uk.org.ponder.rsf.viewstate.ViewParameters;
13:
14: /** Coordinates discovery of other ActionResultInterceptors from round the
15: * context. A particular function is to locate "local ARIs" that are registered
16: * as ViewComponentProducers just for the current view.
17: * @author Antranig Basman (antranig@caret.cam.ac.uk)
18: *
19: */
20:
21: public class ARI2Processor implements ActionResultInterceptor {
22: private List interceptors;
23: private MappingViewResolver mappingViewResolver;
24:
25: public void setInterceptors(List interceptors) {
26: this .interceptors = interceptors;
27: }
28:
29: public void setMappingViewResolver(
30: MappingViewResolver mappingViewResolver) {
31: this .mappingViewResolver = mappingViewResolver;
32: }
33:
34: public void interceptActionResult(ARIResult ariresult,
35: ViewParameters incoming, Object result) {
36: if (interceptors == null) {
37: interceptors = new ArrayList();
38: }
39: ArrayList requestinterceptors = new ArrayList(interceptors);
40:
41: accreteViewARIs(requestinterceptors, incoming);
42: for (int i = 0; i < requestinterceptors.size(); ++i) {
43: ActionResultInterceptor ari = (ActionResultInterceptor) requestinterceptors
44: .get(i);
45: ari.interceptActionResult(ariresult, incoming, result);
46: }
47: }
48:
49: private void accreteViewARIs(List interceptors,
50: ViewParameters incoming) {
51: List producers = mappingViewResolver
52: .getProducers(incoming.viewID);
53: for (int i = 0; i < producers.size(); ++i) {
54: Object producer = producers.get(i);
55: if (producer instanceof ActionResultInterceptor) {
56: interceptors.add(mappingViewResolver
57: .mapProducer(producer));
58: }
59: }
60: }
61:
62: }
|