//
// FlowStepBodyType.java - Change Message body type
//

package nyangau.jmsadapter;

//...simports:0:
import java.io.Serializable;
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 FlowStepBodyType extends FlowStep
  {
//...senum BT:2:
protected enum BT
  {
  BT_BytesMessage,
  BT_TextMessage,
  BT_MapMessage,
  BT_StreamMessage,
  BT_ObjectMessage,
  BT_Message
  }
//...e
  protected BT bodytype;
//...sFlowStepBodyType:2:
public FlowStepBodyType(Node eStep)
  throws FlowProcessorException
  {
  super(eStep);
  NamedNodeMap nnmStep = eStep.getAttributes();
  Node aType = nnmStep.getNamedItem("type");
  if ( aType == null )
    throw new FlowProcessorException("unexpected missing type in step "+name+", bad jmsadapter.xsd?");
  String type = aType.getNodeValue();

  if ( type.equals("BytesMessage") )
    bodytype = BT.BT_BytesMessage;
  else if ( type.equals("TextMessage") )
    bodytype = BT.BT_TextMessage;
  else if ( type.equals("MapMessage") )
    bodytype = BT.BT_MapMessage;
  else if ( type.equals("StreamMessage") )
    bodytype = BT.BT_StreamMessage;
  else if ( type.equals("ObjectMessage") )
    bodytype = BT.BT_ObjectMessage;
  else if ( type.equals("Message") )
    bodytype = BT.BT_Message;
  else
    throw new FlowProcessorException("unexpected type in step "+name+", bad jmsadapter.xsd?");
  }
//...e
//...sprocess:2:
public void process(FlowContext c)
  throws FlowProcessorException, JMSException
  {
  JmsaMessage m = c.getMessage();
  switch ( bodytype )
    {
    case BT_BytesMessage:  m = new JmsaBytesMessage(m);  break;
    case BT_TextMessage:   m = new JmsaTextMessage(m);   break;
    case BT_MapMessage:    m = new JmsaMapMessage(m);    break;
    case BT_StreamMessage: m = new JmsaStreamMessage(m); break;
    case BT_ObjectMessage: m = new JmsaObjectMessage(m); break;
    case BT_Message:       m = new JmsaMessage(m);       break;
    }
  c.setMessage(m);
  }
//...e
  }
