package org.opengroupware.jope.appserver.elements;

import java.util.Map;

import org.opengroupware.jope.appserver.core.WOAssociation;
import org.opengroupware.jope.appserver.core.WOContext;
import org.opengroupware.jope.appserver.core.WOElement;
import org.opengroupware.jope.appserver.core.WOResponse;

/*
 * WOParam
 * 
 * TODO: document
 * TODO: WO also allows for an 'action' binding. Not sure whethers thats useful.
 */
public class WOParam extends WOHTMLDynamicElement {
  
  protected WOAssociation name;
  protected WOAssociation value;

  public WOParam
    (String _name, Map<String, WOAssociation> _assocs, WOElement _template)
  {
    super(_name, _assocs, _template);
  }
  
  /* generate responds */

  @Override
  public void appendToResponse(WOResponse _r, WOContext _ctx) {
    Object cursor = _ctx.cursor();
    
    _r.appendBeginTag("param");
    
    if (this.name != null)
      _r.appendAttribute("name", this.name.stringValueInComponent(cursor));
    if (this.value != null)
      _r.appendAttribute("value", this.value.stringValueInComponent(cursor));
    
    this.appendExtraAttributesToResponse(_r, _ctx);
    _r.appendBeginTagClose();
  }
  
  /* description */
  
  @Override
  public void appendAttributesToDescription(StringBuffer _d) {
    super.appendAttributesToDescription(_d);
    
    this.appendAssocToDescription(_d, "name",  this.name);
    this.appendAssocToDescription(_d, "value", this.value);
  }  
}
