1 22 package org.jboss.mq; 23 24 import java.util.Enumeration ; 25 import java.util.NoSuchElementException ; 26 27 import javax.jms.InvalidSelectorException ; 28 import javax.jms.JMSException ; 29 import javax.jms.Queue ; 30 import org.jboss.mq.selectors.Selector; 31 32 import javax.jms.QueueBrowser ; 33 34 41 public class SpyQueueBrowser implements QueueBrowser 42 { 43 45 47 48 boolean closed; 49 50 Queue destination; 51 52 String messageSelector; 53 54 SpySession session; 55 57 59 67 SpyQueueBrowser(SpySession session, Queue destination, String messageSelector) throws InvalidSelectorException 68 { 69 this.destination = destination; 70 this.session = session; 71 this.messageSelector = messageSelector; 72 73 if (messageSelector != null) 77 new Selector(messageSelector); 78 } 79 80 82 84 public Queue getQueue() throws JMSException 85 { 86 return destination; 87 } 88 89 public String getMessageSelector() throws JMSException 90 { 91 return messageSelector; 92 } 93 94 public Enumeration getEnumeration() throws JMSException 95 { 96 if (closed) 97 throw new JMSException ("The QueueBrowser was closed"); 98 99 final SpyMessage data[] = session.connection.browse(destination, messageSelector); 100 return new Enumeration () 101 { 102 int i = 0; 103 public boolean hasMoreElements() 104 { 105 return i < data.length; 106 } 107 public Object nextElement() 108 { 109 if (!hasMoreElements()) 110 throw new NoSuchElementException (); 111 return data[i++]; 112 } 113 }; 114 } 115 116 public void close() throws JMSException 117 { 118 closed = true; 119 return; 120 } 121 122 124 126 128 130 } | Popular Tags |