01: package org.mockejb.jms;
02:
03: import javax.jms.*;
04: import java.util.*;
05:
06: /**
07: * <code>Topic</code> implementation.
08: * @author Dimitar Gospodinov
09: * @see javax.jms.Topic
10: */
11: public class MockTopic extends MockDestination implements Topic {
12:
13: private final Collection listeners = new ArrayList();
14:
15: /**
16: * Creates <code>MockTopic</code> with the specified name
17: * <code>name</code>
18: * @param name
19: */
20: public MockTopic(String name) {
21: super (name);
22: }
23:
24: /**
25: * Returns topic name.
26: * @return topic name
27: * @see javax.jms.Topic#getTopicName()
28: */
29: public String getTopicName() throws JMSException {
30: return getName();
31: }
32:
33: public void addMessageListener(MessageListener listener) {
34: listeners.add(listener);
35: }
36:
37: public void dispatch(Message msg) {
38: Iterator it = listeners.iterator();
39: while (it.hasNext()) {
40: MessageListener l = (MessageListener) it.next();
41: l.onMessage(msg);
42: }
43: }
44:
45: }
|