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