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.StreamMessage; 036 import javax.jms.TemporaryQueue; 037 import javax.jms.TemporaryTopic; 038 import javax.jms.TextMessage; 039 import javax.jms.Topic; 040 import javax.jms.TopicPublisher; 041 import javax.jms.TopicSession; 042 import javax.jms.TopicSubscriber; 043 044 /** 045 * A TopicSession implementation that throws IllegalStateExceptions 046 * when Queue operations are attempted but which delegates 047 * to another TopicSession for all other operations. 048 * 049 * The ActiveMQSessions implement both Topic and Queue Sessions 050 * methods but the spec states that TopicSession should throw Exceptions 051 * if queue operations are attempted on it. 052 * 053 * @version $Revision: 1.1.1.1 $ 054 */ 055 public class ActiveMQTopicSession implements TopicSession { 056 057 private final TopicSession next; 058 059 public ActiveMQTopicSession(TopicSession next) { 060 this.next = next; 061 } 062 063 /** 064 * @throws JMSException 065 */ 066 public void close() throws JMSException { 067 next.close(); 068 } 069 /** 070 * @throws JMSException 071 */ 072 public void commit() throws JMSException { 073 next.commit(); 074 } 075 /** 076 * @param queue 077 * @return 078 * @throws JMSException 079 */ 080 public QueueBrowser createBrowser(Queue queue) throws JMSException { 081 throw new IllegalStateException("Operation not supported by a TopicSession"); 082 } 083 /** 084 * @param queue 085 * @param messageSelector 086 * @return 087 * @throws JMSException 088 */ 089 public QueueBrowser createBrowser(Queue queue, String messageSelector) 090 throws JMSException { 091 throw new IllegalStateException("Operation not supported by a TopicSession"); 092 } 093 /** 094 * @return 095 * @throws JMSException 096 */ 097 public BytesMessage createBytesMessage() throws JMSException { 098 return next.createBytesMessage(); 099 } 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 }