001 package com.mockrunner.jms;
002
003 import java.io.Serializable;
004 import java.util.HashMap;
005 import java.util.Map;
006
007 import com.mockrunner.mock.jms.MockQueue;
008 import com.mockrunner.mock.jms.MockTopic;
009
010 /**
011 * The <code>DestinationManager</code> can be used
012 * to create queues and topics, which is normally an
013 * administrative act. Since queues and topics are ususally
014 * acquired using JNDI in a J2EE environment, you can bind
015 * the created objects to the mock context with the help
016 * of {@link com.mockrunner.ejb.EJBTestModule#bindToContext}.
017 */
018 public class DestinationManager implements Serializable
019 {
020 private Map queues;
021 private Map topics;
022
023 public DestinationManager()
024 {
025 queues = new HashMap();
026 topics = new HashMap();
027 }
028
029 /**
030 * Creates a new <code>Queue</code> that is available
031 * for {@link com.mockrunner.mock.jms.MockQueueSession#createQueue}
032 * calls. Creating queues is an administrative act.
033 * Before {@link com.mockrunner.mock.jms.MockQueueSession#createQueue}
034 * can be sucessfully called, you have to create a <code>Queue</code>
035 * with this method. You can also bind the created queue to the
036 * mock JNDI context using {@link com.mockrunner.ejb.EJBTestModule#bindToContext}.
037 * @param name the name of the <code>Queue</code>
038 * @return the created <code>Queue</code>
039 */
040 public MockQueue createQueue(String name)
041 {
042 MockQueue queue = new MockQueue(name);
043 queues.put(name, queue);
044 return queue;
045 }
046
047 /**
048 * Removes a formerly created <code>Queue</code>.
049 * @param name the name of the <code>Queue</code>
050 */
051 public void removeQueue(String name)
052 {
053 queues.remove(name);
054 }
055
056 /**
057 * Returns a <code>Queue</code> that was created with
058 * {@link #createQueue} or <code>null</code> if no such
059 * <code>Queue</code> is present.
060 * @param name the name of the <code>Queue</code>
061 * @return the <code>Queue</code>
062 */
063 public MockQueue getQueue(String name)
064 {
065 return (MockQueue)queues.get(name);
066 }
067
068 /**
069 * Creates a new <code>Topic</code> that is available
070 * for {@link com.mockrunner.mock.jms.MockTopicSession#createTopic}
071 * calls. Creating topics is an administrative act.
072 * Before {@link com.mockrunner.mock.jms.MockTopicSession#createTopic}
073 * can be sucessfully called, you have to create a <code>Topic</code>
074 * with this method. You can also bind the created topic to the
075 * mock JNDI context using {@link com.mockrunner.ejb.EJBTestModule#bindToContext}.
076 * @param name the name of the <code>Topic</code>
077 * @return the created <code>Topic</code>
078 */
079 public MockTopic createTopic(String name)
080 {
081 MockTopic topic = new MockTopic(name);
082 topics.put(name, topic);
083 return topic;
084 }
085
086 /**
087 * Removes a formerly created <code>Topic</code>.
088 * @param name the name of the <code>Topic</code>
089 */
090 public void removeTopic(String name)
091 {
092 topics.remove(name);
093 }
094
095 /**
096 * Returns a <code>Topic</code> that was created with
097 * {@link #createTopic} or <code>null</code> if no such
098 * <code>Topic</code> is present.
099 * @param name the name of the <code>Topic</code>
100 * @return the <code>Topic</code>
101 */
102 public MockTopic getTopic(String name)
103 {
104 return (MockTopic)topics.get(name);
105 }
106 }