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.StreamMessage;
035    import javax.jms.TemporaryQueue;
036    import javax.jms.TemporaryTopic;
037    import javax.jms.TextMessage;
038    import javax.jms.Topic;
039    import javax.jms.TopicPublisher;
040    import javax.jms.TopicSession;
041    import javax.jms.TopicSubscriber;
042    
043    /**
044     * A TopicSession implementation that throws IllegalStateExceptions when Queue
045     * operations are attempted but which delegates to another TopicSession for all
046     * other operations. The ActiveMQSessions implement both Topic and Queue
047     * Sessions methods but the spec states that TopicSession should throw
048     * Exceptions if queue operations are attempted on it.
049     *
050     *
051     */
052    public class ActiveMQTopicSession implements TopicSession {
053    
054        private final TopicSession next;
055    
056        public ActiveMQTopicSession(TopicSession next) {
057            this.next = next;
058        }
059    
060        /**
061         * @throws JMSException
062         */
063        public void close() throws JMSException {
064            next.close();
065        }
066    
067        /**
068         * @throws JMSException
069         */
070        public void commit() throws JMSException {
071            next.commit();
072        }
073    
074        /**
075         * @param queue
076         * @return
077         * @throws JMSException
078         */
079        public QueueBrowser createBrowser(Queue queue) throws JMSException {
080            throw new IllegalStateException("Operation not supported by a TopicSession");
081        }
082    
083        /**
084         * @param queue
085         * @param messageSelector
086         * @return
087         * @throws JMSException
088         */
089        public QueueBrowser createBrowser(Queue queue, String messageSelector) throws JMSException {
090            throw new IllegalStateException("Operation not supported by a TopicSession");
091        }
092    
093        /**
094         * @return
095         * @throws JMSException
096         */
097        public BytesMessage createBytesMessage() throws JMSException {
098            return next.createBytesMessage();
099        }
100    
101        /**
102         * @param destination
103         * @return
104         * @throws JMSException
105         */
106        public MessageConsumer createConsumer(Destination destination) throws JMSException {
107            if (destination instanceof Queue) {
108                throw new InvalidDestinationException("Queues are not supported by a TopicSession");
109            }
110            return next.createConsumer(destination);
111        }
112    
113        /**
114         * @param destination
115         * @param messageSelector
116         * @return
117         * @throws JMSException
118         */
119        public MessageConsumer createConsumer(Destination destination, String messageSelector) throws JMSException {
120            if (destination instanceof Queue) {
121                throw new InvalidDestinationException("Queues are not supported by a TopicSession");
122            }
123            return next.createConsumer(destination, messageSelector);
124        }
125    
126        /**
127         * @param destination
128         * @param messageSelector
129         * @param noLocal
130         * @return
131         * @throws JMSException
132         */
133        public MessageConsumer createConsumer(Destination destination, String messageSelector, boolean noLocal) throws JMSException {
134            if (destination instanceof Queue) {
135                throw new InvalidDestinationException("Queues are not supported by a TopicSession");
136            }
137            return next.createConsumer(destination, messageSelector, noLocal);
138        }
139    
140        /**
141         * @param topic
142         * @param name
143         * @return
144         * @throws JMSException
145         */
146        public TopicSubscriber createDurableSubscriber(Topic topic, String name) throws JMSException {
147            return next.createDurableSubscriber(topic, name);
148        }
149    
150        /**
151         * @param topic
152         * @param name
153         * @param messageSelector
154         * @param noLocal
155         * @return
156         * @throws JMSException
157         */
158        public TopicSubscriber createDurableSubscriber(Topic topic, String name, String messageSelector, boolean noLocal) throws JMSException {
159            return next.createDurableSubscriber(topic, name, messageSelector, noLocal);
160        }
161    
162        /**
163         * @return
164         * @throws JMSException
165         */
166        public MapMessage createMapMessage() throws JMSException {
167            return next.createMapMessage();
168        }
169    
170        /**
171         * @return
172         * @throws JMSException
173         */
174        public Message createMessage() throws JMSException {
175            return next.createMessage();
176        }
177    
178        /**
179         * @return
180         * @throws JMSException
181         */
182        public ObjectMessage createObjectMessage() throws JMSException {
183            return next.createObjectMessage();
184        }
185    
186        /**
187         * @param object
188         * @return
189         * @throws JMSException
190         */
191        public ObjectMessage createObjectMessage(Serializable object) throws JMSException {
192            return next.createObjectMessage(object);
193        }
194    
195        /**
196         * @param destination
197         * @return
198         * @throws JMSException
199         */
200        public MessageProducer createProducer(Destination destination) throws JMSException {
201            if (destination instanceof Queue) {
202                throw new InvalidDestinationException("Queues are not supported by a TopicSession");
203            }
204            return next.createProducer(destination);
205        }
206    
207        /**
208         * @param topic
209         * @return
210         * @throws JMSException
211         */
212        public TopicPublisher createPublisher(Topic topic) throws JMSException {
213            return next.createPublisher(topic);
214        }
215    
216        /**
217         * @param queueName
218         * @return
219         * @throws JMSException
220         */
221        public Queue createQueue(String queueName) throws JMSException {
222            throw new IllegalStateException("Operation not supported by a TopicSession");
223        }
224    
225        /**
226         * @return
227         * @throws JMSException
228         */
229        public StreamMessage createStreamMessage() throws JMSException {
230            return next.createStreamMessage();
231        }
232    
233        /**
234         * @param topic
235         * @return
236         * @throws JMSException
237         */
238        public TopicSubscriber createSubscriber(Topic topic) throws JMSException {
239            return next.createSubscriber(topic);
240        }
241    
242        /**
243         * @param topic
244         * @param messageSelector
245         * @param noLocal
246         * @return
247         * @throws JMSException
248         */
249        public TopicSubscriber createSubscriber(Topic topic, String messageSelector, boolean noLocal) throws JMSException {
250            return next.createSubscriber(topic, messageSelector, noLocal);
251        }
252    
253        /**
254         * @return
255         * @throws JMSException
256         */
257        public TemporaryQueue createTemporaryQueue() throws JMSException {
258            throw new IllegalStateException("Operation not supported by a TopicSession");
259        }
260    
261        /**
262         * @return
263         * @throws JMSException
264         */
265        public TemporaryTopic createTemporaryTopic() throws JMSException {
266            return next.createTemporaryTopic();
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            return next.createTopic(topicName);
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            next.unsubscribe(name);
385        }
386    
387        public TopicSession getNext() {
388            return next;
389        }
390    }