//
// FlowStep.java - One step of a flow
//

package nyangau.jmsadapter;

//...simports:0:
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
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;
import javax.jms.JMSException;
//...e

public class FlowStep
  {
  protected static int unnamed = 0;
  protected String name;
//...sFlowStep:2:
public FlowStep(Node eStep)
  throws FlowProcessorException
  {
  NamedNodeMap nnmStep = eStep.getAttributes();
  Node aName = nnmStep.getNamedItem("name");
  name = ( aName != null )
    ? aName.getNodeValue()
    : ( "__unnamedStep"+unnamed++ );

  // Opportunity to pull out things which make sense for every FlowStep.
  // eg: we could enable debugging on each one.
  // At the moment, we don't do this.
  }
//...e
//...sprocess:2:
public void process(FlowContext c)
  throws FlowProcessorException, JMSException
  { throw new FlowProcessorException("subclass of FlowStep should override this"); }
//...e
//...snewFlowStep:2:
public static FlowStep newFlowStep(Node eStep)
  throws FlowProcessorException
  {
  String stepName = eStep.getNodeName();
  if ( stepName.equals("propget") )
    return new FlowStepPropGet(eStep);
  if ( stepName.equals("propset") )
    return new FlowStepPropSet(eStep);
  if ( stepName.equals("propdel") )
    return new FlowStepPropDel(eStep);
  if ( stepName.equals("bodyget") )
    return new FlowStepBodyGet(eStep);
  if ( stepName.equals("bodyset") )
    return new FlowStepBodySet(eStep);
  if ( stepName.equals("bodydel") )
    return new FlowStepBodyDel(eStep);
  if ( stepName.equals("bodytype") )
    return new FlowStepBodyType(eStep);
  if ( stepName.equals("varset") )
    return new FlowStepVarSet(eStep);
  if ( stepName.equals("vardef") )
    return new FlowStepVarDef(eStep);
  if ( stepName.equals("vardel") )
    return new FlowStepVarDel(eStep);
  if ( stepName.equals("vartype") )
    return new FlowStepVarType(eStep);
  if ( stepName.equals("varmap") )
    return new FlowStepVarMap(eStep);
  if ( stepName.equals("varselect") )
    return new FlowStepVarSelect(eStep);
  if ( stepName.equals("xmlvalidate") )
    return new FlowStepXmlValidate(eStep);
  if ( stepName.equals("xmltransform") )
    return new FlowStepXmlTransform(eStep);
  if ( stepName.equals("call") )
    return new FlowStepCall(eStep);
  if ( stepName.equals("switch") )
    return new FlowStepSwitch(eStep);
  if ( stepName.equals("throw") )
    return new FlowStepThrow(eStep);
  if ( stepName.equals("debug") )
    return new FlowStepDebug(eStep);
  if ( stepName.equals("userstep") )
//...suse Class\46\forName:6:
{
NamedNodeMap nnmStep = eStep.getAttributes();
Node aClass = nnmStep.getNamedItem("class");
if ( aClass == null )
  throw new FlowProcessorException("unexpected missing class in stepuser, bad jmsadapter.xsd?");
String className = aClass.getNodeValue();
Class<?> c;
try
  {
  c = Class.forName(className);
  }
catch ( ClassNotFoundException e )
  {
  throw new FlowProcessorException("ClassNotFoundException loading "+className, e);
  }
Constructor ctor;
try
  {
  ctor = c.getConstructor(new Class[]{Node.class});
  }
catch ( NoSuchMethodException e )
  {
  throw new FlowProcessorException("named class "+className+" doesn't have an appropriate constructor", e);
  }
catch ( SecurityException e )
  {
  throw new FlowProcessorException("named class "+className+" constructor can't be called", e);
  }
try
  {
  return (FlowStep) ctor.newInstance(new Object[]{eStep});
  }
catch ( InstantiationException e )
  {
  throw new FlowProcessorException("InstantiationException creating a newInstance of "+className, e);
  }
catch ( IllegalAccessException e )
  {
  throw new FlowProcessorException("IllegalAccessException creating a newInstance of "+className, e);
  }
catch ( IllegalArgumentException e )
  {
  throw new FlowProcessorException("IllegalArgumentException creating a newInstance of "+className, e);
  }
catch ( InvocationTargetException e )
  {
  throw new FlowProcessorException("InvocationTargetException creating a newInstance of "+className, e);
  }
}
//...e
  throw new FlowProcessorException("unexpected flow step "+stepName+", bad jmsadapter.xsd?");
  }
//...e
  }
