001 /*
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements. See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership. The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License. You may obtain a copy of the License at
010 *
011 * http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing,
014 * software distributed under the License is distributed on an
015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016 * KIND, either express or implied. See the License for the
017 * specific language governing permissions and limitations
018 * under the License.
019 *
020 */
021 package org.apache.qpid.client;
022
023 import java.io.Serializable;
024
025 import javax.jms.BytesMessage;
026 import javax.jms.Destination;
027 import javax.jms.IllegalStateException;
028 import javax.jms.JMSException;
029 import javax.jms.MapMessage;
030 import javax.jms.Message;
031 import javax.jms.MessageConsumer;
032 import javax.jms.MessageListener;
033 import javax.jms.MessageProducer;
034 import javax.jms.ObjectMessage;
035 import javax.jms.Queue;
036 import javax.jms.QueueBrowser;
037 import javax.jms.QueueReceiver;
038 import javax.jms.QueueSender;
039 import javax.jms.QueueSession;
040 import javax.jms.Session;
041 import javax.jms.StreamMessage;
042 import javax.jms.TemporaryQueue;
043 import javax.jms.TemporaryTopic;
044 import javax.jms.TextMessage;
045 import javax.jms.Topic;
046 import javax.jms.TopicSubscriber;
047
048 /**
049 * Need this adaptor class to conform to JMS spec and throw IllegalStateException
050 * from createDurableSubscriber, unsubscribe, createTopic & createTemporaryTopic
051 */
052 public class AMQQueueSessionAdaptor implements QueueSession, AMQSessionAdapter
053 {
054 //holds a session for delegation
055 protected final AMQSession _session;
056
057 /**
058 * Construct an adaptor with a session to wrap
059 * @param session
060 */
061 public AMQQueueSessionAdaptor(Session session)
062 {
063 _session = (AMQSession) session;
064 }
065
066 public TemporaryQueue createTemporaryQueue() throws JMSException {
067 return _session.createTemporaryQueue();
068 }
069
070 public Queue createQueue(String string) throws JMSException {
071 return _session.createQueue(string);
072 }
073
074 public QueueReceiver createReceiver(Queue queue) throws JMSException {
075 return _session.createReceiver(queue);
076 }
077
078 public QueueReceiver createReceiver(Queue queue, String string) throws JMSException {
079 return _session.createReceiver(queue, string);
080 }
081
082 public QueueSender createSender(Queue queue) throws JMSException {
083 return _session.createSender(queue);
084 }
085
086 public QueueBrowser createBrowser(Queue queue) throws JMSException {
087 return _session.createBrowser(queue);
088 }
089
090 public QueueBrowser createBrowser(Queue queue, String string) throws JMSException {
091 return _session.createBrowser(queue, string);
092 }
093
094 public BytesMessage createBytesMessage() throws JMSException {
095 return _session.createBytesMessage();
096 }
097
098 public MapMessage createMapMessage() throws JMSException {
099 return _session.createMapMessage();
100 }
101
102 public Message createMessage() throws JMSException {
103 return _session.createMessage();
104 }
105
106 public ObjectMessage createObjectMessage() throws JMSException {
107 return _session.createObjectMessage();
108 }
109
110 public ObjectMessage createObjectMessage(Serializable serializable) throws JMSException {
111 return _session.createObjectMessage(serializable);
112 }
113
114 public StreamMessage createStreamMessage() throws JMSException {
115 return _session.createStreamMessage();
116 }
117
118 public TextMessage createTextMessage() throws JMSException {
119 return _session.createTextMessage();
120 }
121
122 public TextMessage createTextMessage(String string) throws JMSException {
123 return _session.createTextMessage(string);
124 }
125
126 public boolean getTransacted() throws JMSException {
127 return _session.getTransacted();
128 }
129
130 public int getAcknowledgeMode() throws JMSException {
131 return _session.getAcknowledgeMode();
132 }
133
134 public void commit() throws JMSException {
135 _session.commit();
136 }
137
138 public void rollback() throws JMSException {
139 _session.rollback();
140 }
141
142 public void close() throws JMSException {
143 _session.close();
144 }
145
146 public void recover() throws JMSException {
147 _session.recover();
148 }
149
150 public MessageListener getMessageListener() throws JMSException {
151 return _session.getMessageListener();
152 }
153
154 public void setMessageListener(MessageListener messageListener) throws JMSException {
155 _session.setMessageListener(messageListener);
156 }
157
158 public void run() {
159 _session.run();
160 }
161
162 public MessageProducer createProducer(Destination destination) throws JMSException {
163 return _session.createProducer(destination);
164 }
165
166 public MessageConsumer createConsumer(Destination destination) throws JMSException {
167 return _session.createConsumer(destination);
168 }
169
170 public MessageConsumer createConsumer(Destination destination, String string) throws JMSException {
171 return _session.createConsumer(destination,string);
172 }
173
174 public MessageConsumer createConsumer(Destination destination, String string, boolean b) throws JMSException {
175 return _session.createConsumer(destination,string,b);
176 }
177
178 //The following methods cannot be called from a QueueSession as per JMS spec
179
180 public Topic createTopic(String string) throws JMSException {
181 throw new IllegalStateException("Cannot call createTopic from QueueSession");
182 }
183
184 public TopicSubscriber createDurableSubscriber(Topic topic, String string) throws JMSException {
185 throw new IllegalStateException("Cannot call createDurableSubscriber from QueueSession");
186 }
187
188 public TopicSubscriber createDurableSubscriber(Topic topic, String string, String string1, boolean b) throws JMSException {
189 throw new IllegalStateException("Cannot call createDurableSubscriber from QueueSession");
190 }
191
192 public TemporaryTopic createTemporaryTopic() throws JMSException {
193 throw new IllegalStateException("Cannot call createTemporaryTopic from QueueSession");
194 }
195
196 public void unsubscribe(String string) throws JMSException {
197 throw new IllegalStateException("Cannot call unsubscribe from QueueSession");
198 }
199
200 public AMQSession getSession()
201 {
202 return _session;
203 }
204 }
|