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     * @version $Revision: 1.2 $
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            return next.equals(arg0);
302        }
303    
304        /**
305         * @return
306         * @throws JMSException
307         */
308        public int getAcknowledgeMode() throws JMSException {
309            return next.getAcknowledgeMode();
310        }
311    
312        /**
313         * @return
314         * @throws JMSException
315         */
316        public MessageListener getMessageListener() throws JMSException {
317            return next.getMessageListener();
318        }
319    
320        /**
321         * @return
322         * @throws JMSException
323         */
324        public boolean getTransacted() throws JMSException {
325            return next.getTransacted();
326        }
327    
328        /*
329         * (non-Javadoc)
330         * 
331         * @see java.lang.Object#hashCode()
332         */
333        public int hashCode() {
334            return next.hashCode();
335        }
336    
337        /**
338         * @throws JMSException
339         */
340        public void recover() throws JMSException {
341            next.recover();
342        }
343    
344        /**
345         * @throws JMSException
346         */
347        public void rollback() throws JMSException {
348            next.rollback();
349        }
350    
351        /**
352         * 
353         */
354        public void run() {
355            next.run();
356        }
357    
358        /**
359         * @param listener
360         * @throws JMSException
361         */
362        public void setMessageListener(MessageListener listener) throws JMSException {
363            next.setMessageListener(listener);
364        }
365    
366        /*
367         * (non-Javadoc)
368         * 
369         * @see java.lang.Object#toString()
370         */
371        public String toString() {
372            return next.toString();
373        }
374    
375        /**
376         * @param name
377         * @throws JMSException
378         */
379        public void unsubscribe(String name) throws JMSException {
380            next.unsubscribe(name);
381        }
382    
383        public TopicSession getNext() {
384            return next;
385        }
386    }