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