001 package com.mockrunner.mock.jms; 002 003 import java.util.Enumeration; 004 import java.util.Vector; 005 006 import javax.jms.JMSException; 007 import javax.jms.Queue; 008 import javax.jms.QueueBrowser; 009 010 /** 011 * Mock implementation of JMS <code>QueueBrowser</code>. 012 */ 013 public class MockQueueBrowser implements QueueBrowser 014 { 015 private MockConnection connection; 016 private MockQueue queue; 017 private boolean closed; 018 private String messageSelector; 019 020 public MockQueueBrowser(MockConnection connection, MockQueue queue) 021 { 022 this(connection, queue, null); 023 } 024 025 public MockQueueBrowser(MockConnection connection, MockQueue queue, String messageSelector) 026 { 027 this.connection = connection; 028 this.queue = queue; 029 closed = false; 030 this.messageSelector = messageSelector; 031 } 032 033 /** 034 * Returns if this browser was closed. 035 * @return <code>true</code> if this browser is closed 036 */ 037 public boolean isClosed() 038 { 039 return closed; 040 } 041 042 public Queue getQueue() throws JMSException 043 { 044 connection.throwJMSException(); 045 return queue; 046 } 047 048 public String getMessageSelector() throws JMSException 049 { 050 connection.throwJMSException(); 051 return messageSelector; 052 } 053 054 public Enumeration getEnumeration() throws JMSException 055 { 056 connection.throwJMSException(); 057 if(isClosed()) 058 { 059 throw new JMSException("Browser is closed"); 060 } 061 return new Vector(queue.getCurrentMessageList()).elements(); 062 } 063 064 public void close() throws JMSException 065 { 066 connection.throwJMSException(); 067 closed = true; 068 } 069 }