/*
 * Created on 5 Feb 2007
 */
package uk.org.ponder.rsf.flow;

import java.util.ArrayList;
import java.util.List;

import uk.org.ponder.rsf.view.MappingViewResolver;
import uk.org.ponder.rsf.viewstate.ViewParameters;

/** Coordinates discovery of other ActionResultInterceptors from round the
 * context. A particular function is to locate "local ARIs" that are registered
 * as ViewComponentProducers just for the current view.
 * @author Antranig Basman (antranig@caret.cam.ac.uk)
 *
 */

public class ARIProcessor implements ActionResultInterceptor {
  private List interceptors;
  private MappingViewResolver mappingViewResolver;
  
  public void setInterceptors(List interceptors) {
    this.interceptors = interceptors;
  }  

  public void setMappingViewResolver(MappingViewResolver mappingViewResolver) {
    this.mappingViewResolver = mappingViewResolver;
  }
  
  public void interceptActionResult(ARIResult ariresult, ViewParameters incoming, 
      Object result) {
    if (interceptors == null) {
      interceptors = new ArrayList();
    }
    accreteViewARIs(interceptors, incoming);
    for (int i = 0; i < interceptors.size(); ++ i) {
      ActionResultInterceptor ari = (ActionResultInterceptor) interceptors.get(i);
      ari.interceptActionResult(ariresult, incoming, result);
    }
  }

  private void accreteViewARIs(List interceptors, ViewParameters incoming) {
    List producers = mappingViewResolver.getProducers(incoming.viewID);
    for (int i = 0; i < producers.size(); ++ i) {
      Object producer = producers.get(i);
      if (producer instanceof ActionResultInterceptor) {
        interceptors.add(mappingViewResolver.mapProducer(producer));
      }
    }
  }


}

@@ -1080,24 +1080,96 @@
 ();%0D%0A    %7D%0D%0A
+    ArrayList requestinterceptors = new ArrayList(interceptors);%0D%0A    %0D%0A
     accreteV
@@ -1176,16 +1176,23 @@
 iewARIs(
+request
 intercep
@@ -1233,16 +1233,23 @@
  0; i %3C 
+request
 intercep

Fix for egregious, eternal ARI2 bug