Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/activemq/ActiveMQTopicSession.java


1   /**
2    * 
3    * Copyright 2004 Hiram Chirino
4    * 
5    * Licensed under the Apache License, Version 2.0 (the "License"); 
6    * you may not use this file except in compliance with the License. 
7    * You may obtain a copy of the License at 
8    * 
9    * http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, 
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
14   * See the License for the specific language governing permissions and 
15   * limitations under the License. 
16   * 
17   **/
18  package org.activemq;
19  
20  import java.io.Serializable;
21  
22  import javax.jms.BytesMessage;
23  import javax.jms.Destination;
24  import javax.jms.IllegalStateException;
25  import javax.jms.InvalidDestinationException;
26  import javax.jms.JMSException;
27  import javax.jms.MapMessage;
28  import javax.jms.Message;
29  import javax.jms.MessageConsumer;
30  import javax.jms.MessageListener;
31  import javax.jms.MessageProducer;
32  import javax.jms.ObjectMessage;
33  import javax.jms.Queue;
34  import javax.jms.QueueBrowser;
35  import javax.jms.StreamMessage;
36  import javax.jms.TemporaryQueue;
37  import javax.jms.TemporaryTopic;
38  import javax.jms.TextMessage;
39  import javax.jms.Topic;
40  import javax.jms.TopicPublisher;
41  import javax.jms.TopicSession;
42  import javax.jms.TopicSubscriber;
43  
44  /**
45   * A TopicSession implementation that throws IllegalStateExceptions
46   * when Queue operations are attempted but which delegates 
47   * to another TopicSession for all other operations.
48   * 
49   * The ActiveMQSessions implement both Topic and Queue Sessions 
50   * methods but the spec states that TopicSession should throw Exceptions 
51   * if queue operations are attempted on it.  
52   * 
53   * @version $Revision: 1.1.1.1 $
54   */
55  public class ActiveMQTopicSession implements TopicSession {
56  
57    private final TopicSession next;
58  
59    public ActiveMQTopicSession(TopicSession next) {
60      this.next = next;
61    }
62  
63    /**
64     * @throws JMSException
65     */
66    public void close() throws JMSException {
67      next.close();
68    }
69    /**
70     * @throws JMSException
71     */
72    public void commit() throws JMSException {
73      next.commit();
74    }
75    /**
76     * @param queue
77     * @return
78     * @throws JMSException
79     */
80    public QueueBrowser createBrowser(Queue queue) throws JMSException {
81      throw new IllegalStateException("Operation not supported by a TopicSession");
82    }
83    /**
84     * @param queue
85     * @param messageSelector
86     * @return
87     * @throws JMSException
88     */
89    public QueueBrowser createBrowser(Queue queue, String messageSelector)
90        throws JMSException {
91      throw new IllegalStateException("Operation not supported by a TopicSession");
92    }
93    /**
94     * @return
95     * @throws JMSException
96     */
97    public BytesMessage createBytesMessage() throws JMSException {
98      return next.createBytesMessage();
99    }
100   /**
101    * @param destination
102    * @return
103    * @throws JMSException
104    */
105   public MessageConsumer createConsumer(Destination destination)
106       throws JMSException {
107     if( destination instanceof Queue )
108       throw new InvalidDestinationException("Queues are not supported by a TopicSession");
109     return next.createConsumer(destination);
110   }
111   /**
112    * @param destination
113    * @param messageSelector
114    * @return
115    * @throws JMSException
116    */
117   public MessageConsumer createConsumer(Destination destination,
118       String messageSelector) throws JMSException {
119     if( destination instanceof Queue )
120       throw new InvalidDestinationException("Queues are not supported by a TopicSession");
121     return next.createConsumer(destination, messageSelector);
122   }
123   /**
124    * @param destination
125    * @param messageSelector
126    * @param NoLocal
127    * @return
128    * @throws JMSException
129    */
130   public MessageConsumer createConsumer(Destination destination,
131       String messageSelector, boolean NoLocal) throws JMSException {
132     if( destination instanceof Queue )
133       throw new InvalidDestinationException("Queues are not supported by a TopicSession");
134     return next.createConsumer(destination, messageSelector, NoLocal);
135   }
136   /**
137    * @param topic
138    * @param name
139    * @return
140    * @throws JMSException
141    */
142   public TopicSubscriber createDurableSubscriber(Topic topic, String name)
143       throws JMSException {
144     return next.createDurableSubscriber(topic, name);
145   }
146   /**
147    * @param topic
148    * @param name
149    * @param messageSelector
150    * @param noLocal
151    * @return
152    * @throws JMSException
153    */
154   public TopicSubscriber createDurableSubscriber(Topic topic, String name,
155       String messageSelector, boolean noLocal) throws JMSException {
156     return next.createDurableSubscriber(topic, name, messageSelector,
157         noLocal);
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 Queue )
197       throw new InvalidDestinationException("Queues are not supported by a TopicSession");
198     return next.createProducer(destination);
199   }
200   /**
201    * @param topic
202    * @return
203    * @throws JMSException
204    */
205   public TopicPublisher createPublisher(Topic topic) throws JMSException {
206     return next.createPublisher(topic);
207   }
208   /**
209    * @param queueName
210    * @return
211    * @throws JMSException
212    */
213   public Queue createQueue(String queueName) throws JMSException {
214     throw new IllegalStateException("Operation not supported by a TopicSession");
215   }
216   /**
217    * @return
218    * @throws JMSException
219    */
220   public StreamMessage createStreamMessage() throws JMSException {
221     return next.createStreamMessage();
222   }
223   /**
224    * @param topic
225    * @return
226    * @throws JMSException
227    */
228   public TopicSubscriber createSubscriber(Topic topic) throws JMSException {
229     return next.createSubscriber(topic);
230   }
231   /**
232    * @param topic
233    * @param messageSelector
234    * @param noLocal
235    * @return
236    * @throws JMSException
237    */
238   public TopicSubscriber createSubscriber(Topic topic,
239       String messageSelector, boolean noLocal) throws JMSException {
240     return next.createSubscriber(topic, messageSelector, noLocal);
241   }
242   /**
243    * @return
244    * @throws JMSException
245    */
246   public TemporaryQueue createTemporaryQueue() throws JMSException {
247     throw new IllegalStateException("Operation not supported by a TopicSession");
248   }
249   /**
250    * @return
251    * @throws JMSException
252    */
253   public TemporaryTopic createTemporaryTopic() throws JMSException {
254     return next.createTemporaryTopic();
255   }
256   /**
257    * @return
258    * @throws JMSException
259    */
260   public TextMessage createTextMessage() throws JMSException {
261     return next.createTextMessage();
262   }
263   /**
264    * @param text
265    * @return
266    * @throws JMSException
267    */
268   public TextMessage createTextMessage(String text) throws JMSException {
269     return next.createTextMessage(text);
270   }
271   /**
272    * @param topicName
273    * @return
274    * @throws JMSException
275    */
276   public Topic createTopic(String topicName) throws JMSException {
277     return next.createTopic(topicName);
278   }
279   /* (non-Javadoc)
280    * @see java.lang.Object#equals(java.lang.Object)
281    */
282   public boolean equals(Object arg0) {
283     return next.equals(arg0);
284   }
285   /**
286    * @return
287    * @throws JMSException
288    */
289   public int getAcknowledgeMode() throws JMSException {
290     return next.getAcknowledgeMode();
291   }
292   /**
293    * @return
294    * @throws JMSException
295    */
296   public MessageListener getMessageListener() throws JMSException {
297     return next.getMessageListener();
298   }
299   /**
300    * @return
301    * @throws JMSException
302    */
303   public boolean getTransacted() throws JMSException {
304     return next.getTransacted();
305   }
306   /* (non-Javadoc)
307    * @see java.lang.Object#hashCode()
308    */
309   public int hashCode() {
310     return next.hashCode();
311   }
312   /**
313    * @throws JMSException
314    */
315   public void recover() throws JMSException {
316     next.recover();
317   }
318   /**
319    * @throws JMSException
320    */
321   public void rollback() throws JMSException {
322     next.rollback();
323   }
324   /**
325    * 
326    */
327   public void run() {
328     next.run();
329   }
330   /**
331    * @param listener
332    * @throws JMSException
333    */
334   public void setMessageListener(MessageListener listener)
335       throws JMSException {
336     next.setMessageListener(listener);
337   }
338   /* (non-Javadoc)
339    * @see java.lang.Object#toString()
340    */
341   public String toString() {
342     return next.toString();
343   }
344   /**
345    * @param name
346    * @throws JMSException
347    */
348   public void unsubscribe(String name) throws JMSException {
349     next.unsubscribe(name);
350   }
351 
352     public TopicSession getNext() {
353         return next;
354     }
355 }