001: /*
002: * Copyright 2002-2006 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.springframework.jms.listener;
018:
019: import javax.jms.Connection;
020: import javax.jms.Destination;
021: import javax.jms.JMSException;
022: import javax.jms.MessageConsumer;
023: import javax.jms.Queue;
024: import javax.jms.QueueConnection;
025: import javax.jms.QueueConnectionFactory;
026: import javax.jms.QueueSession;
027: import javax.jms.Session;
028: import javax.jms.Topic;
029: import javax.jms.TopicConnection;
030: import javax.jms.TopicConnectionFactory;
031: import javax.jms.TopicSession;
032:
033: /**
034: * A subclass of SimpleMessageListenerContainer that uses the JMS 1.0.2 specification,
035: * rather than the JMS 1.1 methods used by SimpleMessageListenerContainer itself.
036: * This class can be used for JMS 1.0.2 providers, offering the same facility as
037: * SimpleMessageListenerContainer does for JMS 1.1 providers.
038: *
039: * @author Juergen Hoeller
040: * @since 2.0
041: */
042: public class SimpleMessageListenerContainer102 extends
043: SimpleMessageListenerContainer {
044:
045: /**
046: * This implementation overrides the superclass method to use JMS 1.0.2 API.
047: */
048: protected Connection createConnection() throws JMSException {
049: if (isPubSubDomain()) {
050: return ((TopicConnectionFactory) getConnectionFactory())
051: .createTopicConnection();
052: } else {
053: return ((QueueConnectionFactory) getConnectionFactory())
054: .createQueueConnection();
055: }
056: }
057:
058: /**
059: * This implementation overrides the superclass method to use JMS 1.0.2 API.
060: */
061: protected Session createSession(Connection con) throws JMSException {
062: if (isPubSubDomain()) {
063: return ((TopicConnection) con).createTopicSession(
064: isSessionTransacted(), getSessionAcknowledgeMode());
065: } else {
066: return ((QueueConnection) con).createQueueSession(
067: isSessionTransacted(), getSessionAcknowledgeMode());
068: }
069: }
070:
071: /**
072: * This implementation overrides the superclass method to use JMS 1.0.2 API.
073: */
074: protected MessageConsumer createConsumer(Session session,
075: Destination destination) throws JMSException {
076: if (isPubSubDomain()) {
077: if (isSubscriptionDurable()) {
078: return ((TopicSession) session)
079: .createDurableSubscriber((Topic) destination,
080: getDurableSubscriptionName(),
081: getMessageSelector(), isPubSubNoLocal());
082: } else {
083: return ((TopicSession) session).createSubscriber(
084: (Topic) destination, getMessageSelector(),
085: isPubSubNoLocal());
086: }
087: } else {
088: return ((QueueSession) session).createReceiver(
089: (Queue) destination, getMessageSelector());
090: }
091: }
092:
093: /**
094: * This implementation overrides the superclass method to avoid using
095: * JMS 1.1's Session <code>getAcknowledgeMode()</code> method.
096: * The best we can do here is to check the setting on the listener container.
097: */
098: protected boolean isClientAcknowledge(Session session)
099: throws JMSException {
100: return (getSessionAcknowledgeMode() == Session.CLIENT_ACKNOWLEDGE);
101: }
102:
103: }
|