//
// FlowStepPropSet.java - Copy variable to message property
//

package nyangau.jmsadapter;

//...simports:0:
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 FlowStepPropSet extends FlowStep
  {
  protected String var;
  protected String prop;
//...sFlowStepPropSet:2:
public FlowStepPropSet(Node eStep)
  throws FlowProcessorException
  {
  super(eStep);
  NamedNodeMap nnmStep = eStep.getAttributes();
  Node aVar = nnmStep.getNamedItem("var");
  var = ( aVar != null ) ? aVar.getNodeValue() : "v0";
  Node aProp = nnmStep.getNamedItem("prop");
  if ( aProp == null )
    throw new FlowProcessorException("unexpected missing prop in step "+name+", bad jmsadapter.xsd?");
  prop = aProp.getNodeValue();
  }
//...e
//...sprocess:2:
public void process(FlowContext c)
  throws FlowProcessorException, JMSException
  {
  JmsaMessage m = c.getMessage();
  Object o = c.getVar(var);
  if ( o == null )
    throw new FlowProcessorException(var+" undefined in step "+name);
  if ( o instanceof FlowNullValue )
    throw new FlowProcessorException(var+" is null in step "+name);
  try
    {
    m.setObjectProperty(prop, o);
      // This will only work for
      //   Boolean
      //   Byte
      //   Short
      //   Integer
      //   Long
      //   Float
      //   Double
      //   String
    }
  catch ( JMSException e )
    {
    throw new FlowProcessorException("can't set property "+prop+" in step "+name, e);
    }
  }
//...e
  }
