KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > jms > listener > SimpleMessageListenerContainer102


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.jms.listener;
18
19 import javax.jms.Connection JavaDoc;
20 import javax.jms.Destination JavaDoc;
21 import javax.jms.JMSException JavaDoc;
22 import javax.jms.MessageConsumer JavaDoc;
23 import javax.jms.Queue JavaDoc;
24 import javax.jms.QueueConnection JavaDoc;
25 import javax.jms.QueueConnectionFactory JavaDoc;
26 import javax.jms.QueueSession JavaDoc;
27 import javax.jms.Session JavaDoc;
28 import javax.jms.Topic JavaDoc;
29 import javax.jms.TopicConnection JavaDoc;
30 import javax.jms.TopicConnectionFactory JavaDoc;
31 import javax.jms.TopicSession JavaDoc;
32
33 /**
34  * A subclass of SimpleMessageListenerContainer that uses the JMS 1.0.2 specification,
35  * rather than the JMS 1.1 methods used by SimpleMessageListenerContainer itself.
36  * This class can be used for JMS 1.0.2 providers, offering the same facility as
37  * SimpleMessageListenerContainer does for JMS 1.1 providers.
38  *
39  * @author Juergen Hoeller
40  * @since 2.0
41  */

42 public class SimpleMessageListenerContainer102 extends SimpleMessageListenerContainer {
43
44     /**
45      * This implementation overrides the superclass method to use JMS 1.0.2 API.
46      */

47     protected Connection JavaDoc createConnection() throws JMSException JavaDoc {
48         if (isPubSubDomain()) {
49             return ((TopicConnectionFactory JavaDoc) getConnectionFactory()).createTopicConnection();
50         }
51         else {
52             return ((QueueConnectionFactory JavaDoc) getConnectionFactory()).createQueueConnection();
53         }
54     }
55
56     /**
57      * This implementation overrides the superclass method to use JMS 1.0.2 API.
58      */

59     protected Session JavaDoc createSession(Connection JavaDoc con) throws JMSException JavaDoc {
60         if (isPubSubDomain()) {
61             return ((TopicConnection JavaDoc) con).createTopicSession(isSessionTransacted(), getSessionAcknowledgeMode());
62         }
63         else {
64             return ((QueueConnection JavaDoc) con).createQueueSession(isSessionTransacted(), getSessionAcknowledgeMode());
65         }
66     }
67
68     /**
69      * This implementation overrides the superclass method to use JMS 1.0.2 API.
70      */

71     protected MessageConsumer JavaDoc createConsumer(Session JavaDoc session, Destination JavaDoc destination) throws JMSException JavaDoc {
72         if (isPubSubDomain()) {
73             if (isSubscriptionDurable()) {
74                 return ((TopicSession JavaDoc) session).createDurableSubscriber(
75                         (Topic JavaDoc) destination, getDurableSubscriptionName(), getMessageSelector(), isPubSubNoLocal());
76             }
77             else {
78                 return ((TopicSession JavaDoc) session).createSubscriber(
79                         (Topic JavaDoc) destination, getMessageSelector(), isPubSubNoLocal());
80             }
81         }
82         else {
83             return ((QueueSession JavaDoc) session).createReceiver((Queue JavaDoc) destination, getMessageSelector());
84         }
85     }
86
87     /**
88      * This implementation overrides the superclass method to avoid using
89      * JMS 1.1's Session <code>getAcknowledgeMode()</code> method.
90      * The best we can do here is to check the setting on the listener container.
91      */

92     protected boolean isClientAcknowledge(Session JavaDoc session) throws JMSException JavaDoc {
93         return (getSessionAcknowledgeMode() == Session.CLIENT_ACKNOWLEDGE);
94     }
95
96 }
97
Popular Tags