//
// JmsaQueueBrowserEnumeration.java - JMS Adapter QueueBrowser Enumeration
//
// Whenever the nextElement is requested, we get it and transform it,
// using the Flow Processor.
//

package nyangau.jmsadapter;

import java.util.Enumeration;
import javax.jms.*;

public class JmsaQueueBrowserEnumeration implements Enumeration
  {
  protected Enumeration e;
  protected FlowProcessor fp;
//...sJmsaQueueBrowserEnumeration:2:
public JmsaQueueBrowserEnumeration(Enumeration enumeration, FlowProcessor flowproc)
  {
  e  = enumeration;
  fp = flowproc;
  }
//...e
//...shasMoreElements:2:
public boolean hasMoreElements()
  { return e.hasMoreElements(); }
//...e
//...snextElement:2:
public Object nextElement()
  {
  Message message = (Message) e.nextElement();
  if ( message != null )
    try
      {
      JmsaMessage m = JmsaMessage.copyOfMessageWithWrappedDestinations(message);

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

      m.protect();

      message = m;
      }
    catch ( JMSException e )
      {
      // Yikes, what do I do now!
      // JMSException is caused because we can't read the fields of the message
      // so return the original unprocessed message and let the client
      // choke on it, just like we did.
      }
  return message;
  }
//...e
  }
