//
// JmsaMessageListener.java - JMS Adapter MessageListener
//
// This implementation converts the delivered message to JmsaXxxxMessage
// then transforms it (using whatever flow is applicable), and then
// delivers it to another listener (the real client).
//

package nyangau.jmsadapter;

import javax.jms.*;

public class JmsaMessageListener implements MessageListener
  {
  protected MessageListener ml;
  protected FlowProcessor fp;
//...sJmsaMessageListener:2:
public JmsaMessageListener(MessageListener listener, FlowProcessor flowproc)
  {
  ml = listener;
  fp = flowproc;
  }
//...e
//...sonMessage:2:
public void onMessage(Message message)
  {
  try
    {
    JmsaMessage m = JmsaMessage.copyOfMessageWithWrappedDestinations(message);

    // Invoke the Flow Processor
    m = fp.processIn(m);

    m.protect();

    ml.onMessage(m);
    }
  catch ( JMSException e )
    {
    // What the hell do I do here?
    // JMSException is thrown if we can't get the fields of the Message.
    // Presumably, if we can't access the fields, neither can the
    // real client, so pass it on to them, unprocessed, to deal with.
    ml.onMessage(message);
    }
  }
//...e
//...sgetMessageListener:2:
public MessageListener getMessageListener()
  { return ml; }
//...e
  }
