01: /*
02: * Copyright 2002-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.adapter;
18:
19: import javax.jms.Destination;
20: import javax.jms.JMSException;
21: import javax.jms.Message;
22: import javax.jms.MessageProducer;
23: import javax.jms.Queue;
24: import javax.jms.QueueSender;
25: import javax.jms.QueueSession;
26: import javax.jms.Session;
27: import javax.jms.Topic;
28: import javax.jms.TopicPublisher;
29: import javax.jms.TopicSession;
30:
31: import org.springframework.jms.support.JmsUtils;
32: import org.springframework.jms.support.converter.SimpleMessageConverter102;
33:
34: /**
35: * A {@link MessageListenerAdapter} subclass that uses the JMS 1.0.2 specification,
36: * rather than the JMS 1.1 methods used by MessageListenerAdapter itself.
37: *
38: * <p>This class can be used for JMS 1.0.2 providers, offering the same facility
39: * as MessageListenerAdapter does for JMS 1.1 providers.
40: * @author Juergen Hoeller
41: * @author Rick Evans
42: * @since 2.0
43: */
44: public class MessageListenerAdapter102 extends MessageListenerAdapter {
45:
46: /**
47: * Create a new instance of the {@link MessageListenerAdapter102} class
48: * with the default settings.
49: */
50: public MessageListenerAdapter102() {
51: }
52:
53: /**
54: * Create a new instance of the {@link MessageListenerAdapter102} class
55: * for the given delegate.
56: * @param delegate the target object to delegate message listening to
57: */
58: public MessageListenerAdapter102(Object delegate) {
59: super (delegate);
60: }
61:
62: /**
63: * Initialize the default implementations for the adapter's strategies:
64: * SimpleMessageConverter102.
65: * @see #setMessageConverter
66: * @see org.springframework.jms.support.converter.SimpleMessageConverter102
67: */
68: protected void initDefaultStrategies() {
69: setMessageConverter(new SimpleMessageConverter102());
70: }
71:
72: /**
73: * Overrides the superclass method to use the JMS 1.0.2 API to send a response.
74: * <p>Uses the JMS pub-sub API if the given destination is a topic,
75: * else uses the JMS queue API.
76: */
77: protected void sendResponse(Session session,
78: Destination destination, Message response)
79: throws JMSException {
80: MessageProducer producer = null;
81: try {
82: if (destination instanceof Topic) {
83: producer = ((TopicSession) session)
84: .createPublisher((Topic) destination);
85: postProcessProducer(producer, response);
86: ((TopicPublisher) producer).publish(response);
87: } else {
88: producer = ((QueueSession) session)
89: .createSender((Queue) destination);
90: postProcessProducer(producer, response);
91: ((QueueSender) producer).send(response);
92: }
93: } finally {
94: JmsUtils.closeMessageProducer(producer);
95: }
96: }
97:
98: }
|