01: package com.mockrunner.mock.jms;
02:
03: import java.util.Enumeration;
04: import java.util.Vector;
05:
06: import javax.jms.JMSException;
07: import javax.jms.Queue;
08: import javax.jms.QueueBrowser;
09:
10: /**
11: * Mock implementation of JMS <code>QueueBrowser</code>.
12: */
13: public class MockQueueBrowser implements QueueBrowser {
14: private MockConnection connection;
15: private MockQueue queue;
16: private boolean closed;
17: private String messageSelector;
18:
19: public MockQueueBrowser(MockConnection connection, MockQueue queue) {
20: this (connection, queue, null);
21: }
22:
23: public MockQueueBrowser(MockConnection connection, MockQueue queue,
24: String messageSelector) {
25: this .connection = connection;
26: this .queue = queue;
27: closed = false;
28: this .messageSelector = messageSelector;
29: }
30:
31: /**
32: * Returns if this browser was closed.
33: * @return <code>true</code> if this browser is closed
34: */
35: public boolean isClosed() {
36: return closed;
37: }
38:
39: public Queue getQueue() throws JMSException {
40: connection.throwJMSException();
41: return queue;
42: }
43:
44: public String getMessageSelector() throws JMSException {
45: connection.throwJMSException();
46: return messageSelector;
47: }
48:
49: public Enumeration getEnumeration() throws JMSException {
50: connection.throwJMSException();
51: if (isClosed()) {
52: throw new JMSException("Browser is closed");
53: }
54: return new Vector(queue.getCurrentMessageList()).elements();
55: }
56:
57: public void close() throws JMSException {
58: connection.throwJMSException();
59: closed = true;
60: }
61: }
|