001 package com.mockrunner.jms; 002 003 import java.io.Serializable; 004 import java.util.ArrayList; 005 import java.util.List; 006 007 import com.mockrunner.mock.jms.MockMessageConsumer; 008 import com.mockrunner.mock.jms.MockMessageProducer; 009 import com.mockrunner.mock.jms.MockQueueSender; 010 import com.mockrunner.mock.jms.MockTopicPublisher; 011 012 /** 013 * A wrapper around {@link QueueTransmissionManager} and 014 * {@link TopicTransmissionManager} and {@link GenericTransmissionManager}. 015 * Can be used to access all senders, publishers, receivers and subscribers 016 * transparently. 017 */ 018 public class TransmissionManagerWrapper implements Serializable 019 { 020 private QueueTransmissionManager queueManager; 021 private TopicTransmissionManager topicManager; 022 private GenericTransmissionManager genericManager; 023 024 public TransmissionManagerWrapper(QueueTransmissionManager queueManager, TopicTransmissionManager topicManager, GenericTransmissionManager genericManager) 025 { 026 this.queueManager = queueManager; 027 this.topicManager = topicManager; 028 this.genericManager = genericManager; 029 } 030 031 /** 032 * Returns the underlying {@link QueueTransmissionManager}. 033 * @return the {@link QueueTransmissionManager} 034 */ 035 public QueueTransmissionManager getQueueTransmissionManager() 036 { 037 return queueManager; 038 } 039 040 /** 041 * Returns the underlying {@link TopicTransmissionManager}. 042 * @return the {@link TopicTransmissionManager} 043 */ 044 public TopicTransmissionManager getTopicTransmissionManager() 045 { 046 return topicManager; 047 } 048 049 /** 050 * Returns the underlying {@link GenericTransmissionManager}. 051 * @return the {@link GenericTransmissionManager} 052 */ 053 public GenericTransmissionManager getGenericTransmissionManager() 054 { 055 return genericManager; 056 } 057 058 /** 059 * Returns the {@link com.mockrunner.mock.jms.MockMessageProducer} object 060 * with the specified index or <code>null</code>, if no such 061 * {@link com.mockrunner.mock.jms.MockMessageProducer} exists. 062 * @param index the index 063 * @return the {@link com.mockrunner.mock.jms.MockMessageProducer} object 064 */ 065 public MockMessageProducer getMessageProducer(int index) 066 { 067 List messageProducerList = getMessageProducerList(); 068 if(messageProducerList.size() <= index || index < 0) return null; 069 return (MockMessageProducer)messageProducerList.get(index); 070 } 071 072 /** 073 * Returns a list of all producer objects. 074 * @return the list of {@link com.mockrunner.mock.jms.MockMessageProducer} objects 075 */ 076 public List getMessageProducerList() 077 { 078 List resultList = new ArrayList(); 079 resultList.addAll(queueManager.getQueueSenderList()); 080 resultList.addAll(topicManager.getTopicPublisherList()); 081 resultList.addAll(genericManager.getMessageProducerList()); 082 return resultList; 083 } 084 085 /** 086 * Returns a list of all queue senders, i.e. all producer objects, 087 * that are an instance of <code>QueueSender</code>. In 088 * contrast to {@link QueueTransmissionManager#getQueueSenderList}, 089 * this methods also includes the senders that were created without 090 * specifying an explicit queue (these senders are collected using 091 * {@link GenericTransmissionManager}). 092 * @return the list of {@link com.mockrunner.mock.jms.MockQueueSender} objects 093 */ 094 public List getQueueSenderList() 095 { 096 List resultList = new ArrayList(); 097 resultList.addAll(queueManager.getQueueSenderList()); 098 List genericList = genericManager.getMessageProducerList(); 099 for(int ii = 0; ii < genericList.size(); ii++) 100 { 101 Object next = genericList.get(ii); 102 if(next instanceof MockQueueSender) 103 { 104 resultList.add(next); 105 } 106 } 107 return resultList; 108 } 109 110 /** 111 * Returns the {@link com.mockrunner.mock.jms.MockQueueSender} object 112 * with the specified index or <code>null</code>, if no such 113 * {@link com.mockrunner.mock.jms.MockQueueSender} exists. 114 * In contrast to {@link QueueTransmissionManager#getQueueSender}, 115 * this methods also recognizes the senders that were created without 116 * specifying an explicit queue (these senders are collected using 117 * {@link GenericTransmissionManager}). 118 * @param index the index 119 * @return the {@link com.mockrunner.mock.jms.MockQueueSender} object 120 */ 121 public MockQueueSender getQueueSender(int index) 122 { 123 List queueSenderList = getQueueSenderList(); 124 if(queueSenderList.size() <= index || index < 0) return null; 125 return (MockQueueSender)queueSenderList.get(index); 126 } 127 128 /** 129 * Returns a list of all topic publishers, i.e. all producer objects, 130 * that are an instance of <code>TopicPublisher</code>. In 131 * contrast to {@link TopicTransmissionManager#getTopicPublisherList}, 132 * this methods also includes the publishers that were created without 133 * specifying an explicit topic (these publishers are collected using 134 * {@link GenericTransmissionManager}). 135 * @return the list of {@link com.mockrunner.mock.jms.MockTopicPublisher} objects 136 */ 137 public List getTopicPublisherList() 138 { 139 List resultList = new ArrayList(); 140 resultList.addAll(topicManager.getTopicPublisherList()); 141 List genericList = genericManager.getMessageProducerList(); 142 for(int ii = 0; ii < genericList.size(); ii++) 143 { 144 Object next = genericList.get(ii); 145 if(next instanceof MockTopicPublisher) 146 { 147 resultList.add(next); 148 } 149 } 150 return resultList; 151 } 152 153 /** 154 * Returns the {@link com.mockrunner.mock.jms.MockTopicPublisher} object 155 * with the specified index or <code>null</code>, if no such 156 * {@link com.mockrunner.mock.jms.MockTopicPublisher} exists. 157 * In contrast to {@link TopicTransmissionManager#getTopicPublisher}, 158 * this methods also recognizes the publishers that were created without 159 * specifying an explicit queue (these publishers are collected using 160 * {@link GenericTransmissionManager}). 161 * @param index the index 162 * @return the {@link com.mockrunner.mock.jms.MockTopicPublisher} object 163 */ 164 public MockTopicPublisher getTopicPublisher(int index) 165 { 166 List topicPublisherList = getTopicPublisherList(); 167 if(topicPublisherList.size() <= index || index < 0) return null; 168 return (MockTopicPublisher)topicPublisherList.get(index); 169 } 170 171 /** 172 * Returns the {@link com.mockrunner.mock.jms.MockMessageConsumer} object 173 * with the specified index or <code>null</code>, if no such 174 * {@link com.mockrunner.mock.jms.MockMessageConsumer} exists. 175 * @param index the index 176 * @return the {@link com.mockrunner.mock.jms.MockMessageConsumer} object 177 */ 178 public MockMessageConsumer getMessageConsumer(int index) 179 { 180 List messageConsumerList = getMessageConsumerList(); 181 if(messageConsumerList.size() <= index || index < 0) return null; 182 return (MockMessageConsumer)messageConsumerList.get(index); 183 } 184 185 /** 186 * Returns a list of all consumer objects. Includes durable subscribers. 187 * @return the list of {@link com.mockrunner.mock.jms.MockMessageConsumer} objects 188 */ 189 public List getMessageConsumerList() 190 { 191 List resultList = new ArrayList(); 192 resultList.addAll(queueManager.getQueueReceiverList()); 193 resultList.addAll(topicManager.getTopicSubscriberList()); 194 resultList.addAll(topicManager.getDurableTopicSubscriberMap().values()); 195 return resultList; 196 } 197 }