001 /**
002 *
003 * Copyright 2004 Hiram Chirino
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 *
017 **/
018 package org.activemq;
019
020 import java.io.Serializable;
021
022 import javax.jms.BytesMessage;
023 import javax.jms.Destination;
024 import javax.jms.IllegalStateException;
025 import javax.jms.InvalidDestinationException;
026 import javax.jms.JMSException;
027 import javax.jms.MapMessage;
028 import javax.jms.Message;
029 import javax.jms.MessageConsumer;
030 import javax.jms.MessageListener;
031 import javax.jms.MessageProducer;
032 import javax.jms.ObjectMessage;
033 import javax.jms.Queue;
034 import javax.jms.QueueBrowser;
035 import javax.jms.QueueReceiver;
036 import javax.jms.QueueSender;
037 import javax.jms.QueueSession;
038 import javax.jms.StreamMessage;
039 import javax.jms.TemporaryQueue;
040 import javax.jms.TemporaryTopic;
041 import javax.jms.TextMessage;
042 import javax.jms.Topic;
043 import javax.jms.TopicSubscriber;
044
045 /**
046 * A QueueSession implementation that throws IllegalStateExceptions
047 * when Topic operations are attempted but which delegates
048 * to another QueueSession for all other operations.
049 *
050 * The ActiveMQSessions implement both Topic and Queue Sessions
051 * methods but the spec states that Queue session should throw Exceptions
052 * if topic operations are attempted on it.
053 *
054 * @version $Revision: 1.1.1.1 $
055 */
056 public class ActiveMQQueueSession implements QueueSession {
057
058 private final QueueSession next;
059
060 public ActiveMQQueueSession(QueueSession next) {
061 this.next = next;
062 }
063
064 /**
065 * @throws JMSException
066 */
067 public void close() throws JMSException {
068 next.close();
069 }
070 /**
071 * @throws JMSException
072 */
073 public void commit() throws JMSException {
074 next.commit();
075 }
076 /**
077 * @param queue
078 * @return
079 * @throws JMSException
080 */
081 public QueueBrowser createBrowser(Queue queue) throws JMSException {
082 return next.createBrowser(queue);
083 }
084 /**
085 * @param queue
086 * @param messageSelector
087 * @return
088 * @throws JMSException
089 */
090 public QueueBrowser createBrowser(Queue queue, String messageSelector)
091 throws JMSException {
092 return next.createBrowser(queue, messageSelector);
093 }
094 /**
095 * @return
096 * @throws JMSException
097 */
098 public BytesMessage createBytesMessage() throws JMSException {
099 return next.createBytesMessage();
100 }
101 /**
102 * @param destination
103 * @return
104 * @throws JMSException
105 */
106 public MessageConsumer createConsumer(Destination destination)
107 throws JMSException {
108 if( destination instanceof Topic )
109 throw new InvalidDestinationException("Topics are not supported by a QueueSession");
110 return next.createConsumer(destination);
111 }
112 /**
113 * @param destination
114 * @param messageSelector
115 * @return
116 * @throws JMSException
117 */
118 public MessageConsumer createConsumer(Destination destination,
119 String messageSelector) throws JMSException {
120 if( destination instanceof Topic )
121 throw new InvalidDestinationException("Topics are not supported by a QueueSession");
122 return next.createConsumer(destination, messageSelector);
123 }
124 /**
125 * @param destination
126 * @param messageSelector
127 * @param NoLocal
128 * @return
129 * @throws JMSException
130 */
131 public MessageConsumer createConsumer(Destination destination,
132 String messageSelector, boolean NoLocal) throws JMSException {
133 if( destination instanceof Topic )
134 throw new InvalidDestinationException("Topics are not supported by a QueueSession");
135 return next.createConsumer(destination, messageSelector, NoLocal);
136 }
137 /**
138 * @param topic
139 * @param name
140 * @return
141 * @throws JMSException
142 */
143 public TopicSubscriber createDurableSubscriber(Topic topic, String name)
144 throws JMSException {
145 throw new IllegalStateException("Operation not supported by a QueueSession");
146 }
147 /**
148 * @param topic
149 * @param name
150 * @param messageSelector
151 * @param noLocal
152 * @return
153 * @throws JMSException
154 */
155 public TopicSubscriber createDurableSubscriber(Topic topic, String name,
156 String messageSelector, boolean noLocal) throws JMSException {
157 throw new IllegalStateException("Operation not supported by a QueueSession");
158 }
159 /**
160 * @return
161 * @throws JMSException
162 */
163 public MapMessage createMapMessage() throws JMSException {
164 return next.createMapMessage();
165 }
166 /**
167 * @return
168 * @throws JMSException
169 */
170 public Message createMessage() throws JMSException {
171 return next.createMessage();
172 }
173 /**
174 * @return
175 * @throws JMSException
176 */
177 public ObjectMessage createObjectMessage() throws JMSException {
178 return next.createObjectMessage();
179 }
180 /**
181 * @param object
182 * @return
183 * @throws JMSException
184 */
185 public ObjectMessage createObjectMessage(Serializable object)
186 throws JMSException {
187 return next.createObjectMessage(object);
188 }
189 /**
190 * @param destination
191 * @return
192 * @throws JMSException
193 */
194 public MessageProducer createProducer(Destination destination)
195 throws JMSException {
196 if( destination instanceof Topic )
197 throw new InvalidDestinationException("Topics are not supported by a QueueSession");
198 return next.createProducer(destination);
199 }
200 /**
201 * @param queueName
202 * @return
203 * @throws JMSException
204 */
205 public Queue createQueue(String queueName) throws JMSException {
206 return next.createQueue(queueName);
207 }
208 /**
209 * @param queue
210 * @return
211 * @throws JMSException
212 */
213 public QueueReceiver createReceiver(Queue queue) throws JMSException {
214 return next.createReceiver(queue);
215 }
216 /**
217 * @param queue
218 * @param messageSelector
219 * @return
220 * @throws JMSException
221 */
222 public QueueReceiver createReceiver(Queue queue, String messageSelector)
223 throws JMSException {
224 return next.createReceiver(queue, messageSelector);
225 }
226 /**
227 * @param queue
228 * @return
229 * @throws JMSException
230 */
231 public QueueSender createSender(Queue queue) throws JMSException {
232 return next.createSender(queue);
233 }
234 /**
235 * @return
236 * @throws JMSException
237 */
238 public StreamMessage createStreamMessage() throws JMSException {
239 return next.createStreamMessage();
240 }
241 /**
242 * @return
243 * @throws JMSException
244 */
245 public TemporaryQueue createTemporaryQueue() throws JMSException {
246 return next.createTemporaryQueue();
247 }
248 /**
249 * @return
250 * @throws JMSException
251 */
252 public TemporaryTopic createTemporaryTopic() throws JMSException {
253 throw new IllegalStateException("Operation not supported by a QueueSession");
254 }
255 /**
256 * @return
257 * @throws JMSException
258 */
259 public TextMessage createTextMessage() throws JMSException {
260 return next.createTextMessage();
261 }
262 /**
263 * @param text
264 * @return
265 * @throws JMSException
266 */
267 public TextMessage createTextMessage(String text) throws JMSException {
268 return next.createTextMessage(text);
269 }
270 /**
271 * @param topicName
272 * @return
273 * @throws JMSException
274 */
275 public Topic createTopic(String topicName) throws JMSException {
276 throw new IllegalStateException("Operation not supported by a QueueSession");
277 }
278 /* (non-Javadoc)
279 * @see java.lang.Object#equals(java.lang.Object)
280 */
281 public boolean equals(Object arg0) {
282 return next.equals(arg0);
283 }
284 /**
285 * @return
286 * @throws JMSException
287 */
288 public int getAcknowledgeMode() throws JMSException {
289 return next.getAcknowledgeMode();
290 }
291 /**
292 * @return
293 * @throws JMSException
294 */
295 public MessageListener getMessageListener() throws JMSException {
296 return next.getMessageListener();
297 }
298 /**
299 * @return
300 * @throws JMSException
301 */
302 public boolean getTransacted() throws JMSException {
303 return next.getTransacted();
304 }
305 /* (non-Javadoc)
306 * @see java.lang.Object#hashCode()
307 */
308 public int hashCode() {
309 return next.hashCode();
310 }
311 /**
312 * @throws JMSException
313 */
314 public void recover() throws JMSException {
315 next.recover();
316 }
317 /**
318 * @throws JMSException
319 */
320 public void rollback() throws JMSException {
321 next.rollback();
322 }
323 /**
324 *
325 */
326 public void run() {
327 next.run();
328 }
329 /**
330 * @param listener
331 * @throws JMSException
332 */
333 public void setMessageListener(MessageListener listener)
334 throws JMSException {
335 next.setMessageListener(listener);
336 }
337 /* (non-Javadoc)
338 * @see java.lang.Object#toString()
339 */
340 public String toString() {
341 return next.toString();
342 }
343 /**
344 * @param name
345 * @throws JMSException
346 */
347 public void unsubscribe(String name) throws JMSException {
348 throw new IllegalStateException("Operation not supported by a QueueSession");
349 }
350
351 public QueueSession getNext() {
352 return next;
353 }
354
355 }