package org.opengroupware.jope.appserver.elements;

import java.util.List;

import org.opengroupware.jope.appserver.WOActionResults;
import org.opengroupware.jope.appserver.WOContext;
import org.opengroupware.jope.appserver.WODynamicElement;
import org.opengroupware.jope.appserver.WOElement;
import org.opengroupware.jope.appserver.WORequest;
import org.opengroupware.jope.appserver.WOResponse;

public class WOCompoundElement extends WODynamicElement {

  protected List<WOElement> children;
  
  public WOCompoundElement(List<WOElement> _children ){
    super(null /* name */, null /* assocs */, null /* template */);
    
    this.children = _children;
  }

  /* responder */
  
  public void takeValuesFromRequest(WORequest _rq, WOContext _ctx) {
    _ctx.appendZeroElementIDComponent();
    
    for (WOElement element: this.children) {
      element.takeValuesFromRequest(_rq, _ctx);
      _ctx.incrementLastElementIDComponent();
    }
    
    _ctx.deleteLastElementIDComponent();
  }
  
  public WOActionResults invokeAction(WORequest _rq, WOContext _ctx) {
    // TODO: implement me, required for WOComponentAction's
    // - we need to check the senderID for the element we are dealing with
    return null;
  }
  
  public void appendToResponse(WOResponse _r, WOContext _ctx) {
    _ctx.appendZeroElementIDComponent();
    
    for (WOElement element: this.children) {
      element.appendToResponse(_r, _ctx);
      _ctx.incrementLastElementIDComponent();
    }
    
    _ctx.deleteLastElementIDComponent();
  }
}
