//
// Flow.java - A sequence of FlowSteps
//

package nyangau.jmsadapter;

//...simports:0:
import java.util.Enumeration;
import java.util.Vector;
import javax.jms.JMSException;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.Text;
//...e

public class Flow
  {
  protected static int unnamed = 0;
  protected String name;
  protected String eflow; // or null
  protected Vector<FlowStep> steps;
//...sFlow:2:
public Flow(Node eFlow)
  throws FlowProcessorException
  {
  // Get name
  NamedNodeMap nnmFlow = eFlow.getAttributes();
  Node aName = nnmFlow.getNamedItem("name");
  name = ( aName != null )
    ? aName.getNodeValue()
    : ( "__unnamedFlow"+unnamed++ );
  Node aEflow = nnmFlow.getNamedItem("eflow");
  eflow = ( aEflow != null ) ? aEflow.getNodeValue() : null;

  // Note that you might think we can lookup the eflow Flow right now,
  // but note that not all of them may have been read from the configuration
  // XML at the time we are called here, so we do this lookup lazily.

  // Add in all the steps
  steps = new Vector<FlowStep>();
  NodeList nlFlowSteps = eFlow.getChildNodes();
  for ( int i = 0; i < nlFlowSteps.getLength(); i++ )
    {
    Node eStep = nlFlowSteps.item(i);
    if ( eStep.getNodeType() == Node.ELEMENT_NODE )
      {
      FlowStep step = FlowStep.newFlowStep(eStep);
      steps.add(step);
      }
    }
  }
//...e
//...sgetName:2:
public String getName()
  { return name; }
//...e
//...sgetEflow:2:
public String getEflow()
  { return eflow; }
//...e
//...sprocess:2:
public void process(FlowContext c)
  throws FlowProcessorException, JMSException
  {
  for ( Enumeration<FlowStep> e = steps.elements(); e.hasMoreElements(); )
    {
    FlowStep step = e.nextElement();
    step.process(c);
    }
  }
//...e
  }
