KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > jms > client > JBossSession


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.jms.client;
8
9 import java.io.Serializable JavaDoc;
10
11 import javax.jms.BytesMessage JavaDoc;
12 import javax.jms.Destination JavaDoc;
13 import javax.jms.JMSException JavaDoc;
14 import javax.jms.MapMessage JavaDoc;
15 import javax.jms.Message JavaDoc;
16 import javax.jms.MessageConsumer JavaDoc;
17 import javax.jms.MessageListener JavaDoc;
18 import javax.jms.MessageProducer JavaDoc;
19 import javax.jms.ObjectMessage JavaDoc;
20 import javax.jms.Queue JavaDoc;
21 import javax.jms.QueueBrowser JavaDoc;
22 import javax.jms.QueueReceiver JavaDoc;
23 import javax.jms.QueueSender JavaDoc;
24 import javax.jms.QueueSession JavaDoc;
25 import javax.jms.Session JavaDoc;
26 import javax.jms.StreamMessage JavaDoc;
27 import javax.jms.TemporaryQueue JavaDoc;
28 import javax.jms.TemporaryTopic JavaDoc;
29 import javax.jms.TextMessage JavaDoc;
30 import javax.jms.Topic JavaDoc;
31 import javax.jms.TopicPublisher JavaDoc;
32 import javax.jms.TopicSession JavaDoc;
33 import javax.jms.TopicSubscriber JavaDoc;
34 import javax.jms.XAQueueSession JavaDoc;
35 import javax.jms.XASession JavaDoc;
36 import javax.jms.XATopicSession JavaDoc;
37 import javax.transaction.xa.XAResource JavaDoc;
38
39 import org.jboss.jms.destination.JBossTemporaryDestination;
40
41 /**
42  * A session
43  *
44  * @author <a HREF="mailto:adrian@jboss.org>Adrian Brock</a>
45  * @version $Revision: 1.2 $
46  */

47 public class JBossSession
48    implements Session JavaDoc, QueueSession JavaDoc, TopicSession JavaDoc,
49               XASession JavaDoc, XAQueueSession JavaDoc, XATopicSession JavaDoc
50 {
51    // Constants -----------------------------------------------------
52

53    /** The default message selector */
54    private static String JavaDoc defaultSelector = null;
55
56    /** The default no local flag */
57    private static boolean defaultNoLocal = false;
58
59    // Attributes ----------------------------------------------------
60

61    /** The delegate */
62    private SessionDelegate delegate;
63
64    /** Whether this is an XASession */
65    private boolean isXA;
66
67    /** The transacted flag */
68    private boolean transacted;
69
70    /** The acknowledgement mode */
71    private int acknowledgeMode;
72
73    /** The message listener */
74    private MessageListener JavaDoc listener;
75
76     // Static --------------------------------------------------------
77

78    // Constructors --------------------------------------------------
79

80    // Public --------------------------------------------------------
81

82    /**
83     * Construct a new JBossSession
84     *
85     * @param delegate the session delegate
86     * @param isXA whether the session is xa
87     * @param transacted whether the session is transacted
88     * @param acknowledgeMode the acknowledgement mode
89     * @throws JMSException for any error
90     */

91    public JBossSession(SessionDelegate delegate, boolean isXA, boolean transacted, int acknowledgeMode)
92       throws JMSException JavaDoc
93    {
94       this.delegate = delegate;
95       this.isXA = isXA;
96       this.transacted = transacted;
97       this.acknowledgeMode = acknowledgeMode;
98    }
99
100    // Session implementation ----------------------------------------
101

102     public void close() throws JMSException JavaDoc
103     {
104       delegate.closing();
105       delegate.close();
106     }
107
108     public void commit() throws JMSException JavaDoc
109     {
110       if (transacted == false)
111          throw new JMSException JavaDoc("Not a transacted session");
112       delegate.commit();
113     }
114
115     public QueueBrowser JavaDoc createBrowser(Queue JavaDoc queue, String JavaDoc messageSelector) throws JMSException JavaDoc
116     {
117       if (queue == null)
118          throw new JMSException JavaDoc("Null queue");
119       return new JBossBrowser(delegate.createBrowser(queue, messageSelector), queue, messageSelector);
120     }
121
122     public QueueBrowser JavaDoc createBrowser(Queue JavaDoc queue) throws JMSException JavaDoc
123     {
124       return createBrowser(queue, defaultSelector);
125     }
126
127     public BytesMessage JavaDoc createBytesMessage() throws JMSException JavaDoc
128     {
129       return delegate.createBytesMessage();
130     }
131
132     public MessageConsumer JavaDoc createConsumer(Destination JavaDoc destination, String JavaDoc messageSelector, boolean noLocal)
133         throws JMSException JavaDoc
134     {
135         if (destination == null)
136          throw new JMSException JavaDoc("Null destination");
137       return new JBossConsumer(delegate.createConsumer(destination, null, messageSelector, noLocal), destination, messageSelector, noLocal);
138     }
139
140     public MessageConsumer JavaDoc createConsumer(Destination JavaDoc destination, String JavaDoc messageSelector) throws JMSException JavaDoc
141     {
142       return createConsumer(destination, messageSelector, defaultNoLocal);
143     }
144
145     public MessageConsumer JavaDoc createConsumer(Destination JavaDoc destination) throws JMSException JavaDoc
146     {
147       return createConsumer(destination, defaultSelector, defaultNoLocal);
148     }
149
150     public TopicSubscriber JavaDoc createDurableSubscriber(Topic JavaDoc topic, String JavaDoc name, String JavaDoc messageSelector, boolean noLocal)
151         throws JMSException JavaDoc
152     {
153       if (topic == null)
154          throw new JMSException JavaDoc("Null topic");
155       if (name == null)
156          throw new JMSException JavaDoc("Null subscription");
157       return (TopicSubscriber JavaDoc) delegate.createConsumer(topic, name, messageSelector, noLocal);
158     }
159
160     public TopicSubscriber JavaDoc createDurableSubscriber(Topic JavaDoc topic, String JavaDoc name) throws JMSException JavaDoc
161     {
162       return (TopicSubscriber JavaDoc) createDurableSubscriber(topic, name, null, defaultNoLocal);
163     }
164
165     public MapMessage JavaDoc createMapMessage() throws JMSException JavaDoc
166     {
167       return delegate.createMapMessage();
168     }
169
170     public Message JavaDoc createMessage() throws JMSException JavaDoc
171     {
172       return delegate.createMessage();
173     }
174
175     public ObjectMessage JavaDoc createObjectMessage() throws JMSException JavaDoc
176     {
177       return createObjectMessage(null);
178     }
179
180     public ObjectMessage JavaDoc createObjectMessage(Serializable JavaDoc object) throws JMSException JavaDoc
181     {
182       return delegate.createObjectMessage(object);
183     }
184
185     public MessageProducer JavaDoc createProducer(Destination JavaDoc destination) throws JMSException JavaDoc
186     {
187       return new JBossProducer(delegate.createProducer(destination), destination);
188     }
189
190     public Queue JavaDoc createQueue(String JavaDoc queueName) throws JMSException JavaDoc
191     {
192         return (Queue JavaDoc) delegate.getDestination(queueName);
193     }
194
195     public StreamMessage JavaDoc createStreamMessage() throws JMSException JavaDoc
196     {
197       return delegate.createStreamMessage();
198     }
199
200     public TemporaryQueue JavaDoc createTemporaryQueue() throws JMSException JavaDoc
201     {
202       return (TemporaryQueue JavaDoc) delegate.createTempDestination(JBossTemporaryDestination.TEMPORARY_QUEUE);
203     }
204
205     public TemporaryTopic JavaDoc createTemporaryTopic() throws JMSException JavaDoc
206     {
207       return (TemporaryTopic JavaDoc) delegate.createTempDestination(JBossTemporaryDestination.TEMPORARY_TOPIC);
208     }
209
210     public TextMessage JavaDoc createTextMessage() throws JMSException JavaDoc
211     {
212       return createTextMessage(null);
213     }
214
215     public TextMessage JavaDoc createTextMessage(String JavaDoc text) throws JMSException JavaDoc
216     {
217       return delegate.createTextMessage(text);
218     }
219
220     public Topic JavaDoc createTopic(String JavaDoc topicName) throws JMSException JavaDoc
221     {
222       return (Topic JavaDoc) delegate.getDestination(topicName);
223     }
224
225     public int getAcknowledgeMode() throws JMSException JavaDoc
226     {
227       return acknowledgeMode;
228     }
229
230     public MessageListener JavaDoc getMessageListener() throws JMSException JavaDoc
231     {
232       return listener;
233     }
234
235     public boolean getTransacted() throws JMSException JavaDoc
236     {
237       return transacted;
238     }
239
240     public void recover() throws JMSException JavaDoc
241     {
242       delegate.recover();
243     }
244
245     public void rollback() throws JMSException JavaDoc
246     {
247       if (transacted == false)
248          throw new JMSException JavaDoc("Not a transacted session");
249       delegate.rollback();
250     }
251
252     public void run()
253     {
254       if (listener == null)
255          throw new IllegalStateException JavaDoc("No message listener");
256       delegate.run();
257     }
258
259     public void setMessageListener(MessageListener JavaDoc listener) throws JMSException JavaDoc
260     {
261       delegate.setMessageListener(listener);
262       this.listener = listener;
263     }
264
265     public void unsubscribe(String JavaDoc name) throws JMSException JavaDoc
266     {
267       delegate.unsubscribe(name);
268     }
269
270    // XASession implementation --------------------------------------
271

272    public Session JavaDoc getSession() throws JMSException JavaDoc
273    {
274       return this;
275    }
276
277    public XAResource JavaDoc getXAResource()
278    {
279       if (isXA == false)
280          throw new IllegalArgumentException JavaDoc("Not an XASession");
281       return delegate.getXAResource();
282    }
283
284    // QueueSession implementation -----------------------------------
285

286     public QueueReceiver JavaDoc createReceiver(Queue JavaDoc queue, String JavaDoc messageSelector) throws JMSException JavaDoc
287     {
288       return (QueueReceiver JavaDoc) createConsumer(queue, messageSelector);
289     }
290
291     public QueueReceiver JavaDoc createReceiver(Queue JavaDoc queue) throws JMSException JavaDoc
292     {
293       return (QueueReceiver JavaDoc) createConsumer(queue);
294     }
295
296     public QueueSender JavaDoc createSender(Queue JavaDoc queue) throws JMSException JavaDoc
297     {
298       return (QueueSender JavaDoc) createProducer(queue);
299     }
300
301    // TopicSession implementation -----------------------------------
302

303    public TopicSubscriber JavaDoc createSubscriber(Topic JavaDoc topic) throws JMSException JavaDoc
304    {
305       return (TopicSubscriber JavaDoc) createConsumer(topic);
306    }
307
308    public TopicSubscriber JavaDoc createSubscriber(Topic JavaDoc topic, String JavaDoc messageSelector, boolean noLocal) throws JMSException JavaDoc
309    {
310       return (TopicSubscriber JavaDoc) createConsumer(topic, messageSelector, noLocal);
311    }
312
313    public TopicPublisher JavaDoc createPublisher(Topic JavaDoc topic) throws JMSException JavaDoc
314    {
315       return (TopicPublisher JavaDoc) createProducer(topic);
316    }
317
318    // XAQueueSession implementation ---------------------------------
319

320     public QueueSession JavaDoc getQueueSession() throws JMSException JavaDoc
321     {
322       return (QueueSession JavaDoc) getSession();
323     }
324
325    // XATopicSession implementation ---------------------------------
326

327     public TopicSession JavaDoc getTopicSession() throws JMSException JavaDoc
328     {
329       return (TopicSession JavaDoc) getSession();
330     }
331
332    // Protected ------------------------------------------------------
333

334    // Package Private ------------------------------------------------
335

336    // Private --------------------------------------------------------
337

338    // Inner Classes --------------------------------------------------
339
}
340
Popular Tags