01: package com.mockrunner.jms;
02:
03: import java.util.HashMap;
04: import java.util.Map;
05:
06: import com.mockrunner.mock.jms.MockQueue;
07: import com.mockrunner.mock.jms.MockTopic;
08:
09: /**
10: * The <code>DestinationManager</code> can be used
11: * to create queues and topics, which is normally an
12: * administrative act. Since queues and topics are ususally
13: * acquired using JNDI in a J2EE environment, you can bind
14: * the created objects to the mock context with the help
15: * of {@link com.mockrunner.ejb.EJBTestModule#bindToContext}.
16: */
17: public class DestinationManager {
18: private Map queues;
19: private Map topics;
20:
21: public DestinationManager() {
22: queues = new HashMap();
23: topics = new HashMap();
24: }
25:
26: /**
27: * Creates a new <code>Queue</code> that is available
28: * for {@link com.mockrunner.mock.jms.MockQueueSession#createQueue}
29: * calls. Creating queues is an administrative act.
30: * Before {@link com.mockrunner.mock.jms.MockQueueSession#createQueue}
31: * can be sucessfully called, you have to create a <code>Queue</code>
32: * with this method. You can also bind the created queue to the
33: * mock JNDI context using {@link com.mockrunner.ejb.EJBTestModule#bindToContext}.
34: * @param name the name of the <code>Queue</code>
35: * @return the created <code>Queue</code>
36: */
37: public MockQueue createQueue(String name) {
38: MockQueue queue = new MockQueue(name);
39: queues.put(name, queue);
40: return queue;
41: }
42:
43: /**
44: * Removes a formerly created <code>Queue</code>.
45: * @param name the name of the <code>Queue</code>
46: */
47: public void removeQueue(String name) {
48: queues.remove(name);
49: }
50:
51: /**
52: * Returns a <code>Queue</code> that was created with
53: * {@link #createQueue} or <code>null</code> if no such
54: * <code>Queue</code> is present.
55: * @param name the name of the <code>Queue</code>
56: * @return the <code>Queue</code>
57: */
58: public MockQueue getQueue(String name) {
59: return (MockQueue) queues.get(name);
60: }
61:
62: /**
63: * Creates a new <code>Topic</code> that is available
64: * for {@link com.mockrunner.mock.jms.MockTopicSession#createTopic}
65: * calls. Creating topics is an administrative act.
66: * Before {@link com.mockrunner.mock.jms.MockTopicSession#createTopic}
67: * can be sucessfully called, you have to create a <code>Topic</code>
68: * with this method. You can also bind the created topic to the
69: * mock JNDI context using {@link com.mockrunner.ejb.EJBTestModule#bindToContext}.
70: * @param name the name of the <code>Topic</code>
71: * @return the created <code>Topic</code>
72: */
73: public MockTopic createTopic(String name) {
74: MockTopic topic = new MockTopic(name);
75: topics.put(name, topic);
76: return topic;
77: }
78:
79: /**
80: * Removes a formerly created <code>Topic</code>.
81: * @param name the name of the <code>Topic</code>
82: */
83: public void removeTopic(String name) {
84: topics.remove(name);
85: }
86:
87: /**
88: * Returns a <code>Topic</code> that was created with
89: * {@link #createTopic} or <code>null</code> if no such
90: * <code>Topic</code> is present.
91: * @param name the name of the <code>Topic</code>
92: * @return the <code>Topic</code>
93: */
94: public MockTopic getTopic(String name) {
95: return (MockTopic) topics.get(name);
96: }
97: }
|