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