01: package com.mockrunner.mock.jms;
02:
03: import javax.jms.JMSException;
04: import javax.jms.Message;
05: import javax.jms.Queue;
06: import javax.jms.QueueReceiver;
07:
08: /**
09: * Mock implementation of JMS <code>QueueReceiver</code>.
10: */
11: public class MockQueueReceiver extends MockMessageConsumer implements
12: QueueReceiver {
13: private MockSession session;
14: private MockQueue queue;
15:
16: public MockQueueReceiver(MockConnection connection,
17: MockQueueSession session, MockQueue queue) {
18: this (connection, session, queue, null);
19: }
20:
21: public MockQueueReceiver(MockConnection connection,
22: MockSession session, MockQueue queue, String messageSelector) {
23: super (connection, messageSelector);
24: this .session = session;
25: this .queue = queue;
26: }
27:
28: public Queue getQueue() throws JMSException {
29: getConnection().throwJMSException();
30: return queue;
31: }
32:
33: public Message receive() throws JMSException {
34: getConnection().throwJMSException();
35: if (isClosed()) {
36: throw new JMSException("Receiver is closed");
37: }
38: if (queue.isEmpty())
39: return null;
40: Message message;
41: if ((!getConnection().getConfigurationManager()
42: .getUseMessageSelectors())
43: || (null == getMessageFilter())) {
44: message = queue.getMessage();
45: } else {
46: message = queue.getMatchingMessage(getMessageFilter());
47: }
48: if (null == message)
49: return null;
50: if (session.isAutoAcknowledge())
51: message.acknowledge();
52: return message;
53: }
54: }
|