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