001    /** 
002     * 
003     * Copyright 2004 Protique Ltd
004     * 
005     * Licensed under the Apache License, Version 2.0 (the "License"); 
006     * you may not use this file except in compliance with the License. 
007     * You may obtain a copy of the License at 
008     * 
009     * http://www.apache.org/licenses/LICENSE-2.0
010     * 
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS, 
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
014     * See the License for the specific language governing permissions and 
015     * limitations under the License. 
016     * 
017     **/
018    package org.activemq.ra.jms;
019    
020    import javax.jms.Destination;
021    import javax.jms.JMSException;
022    import javax.jms.Message;
023    import javax.jms.MessageProducer;
024    import javax.jms.Queue;
025    import javax.jms.QueueSender;
026    import javax.jms.Topic;
027    import javax.jms.TopicPublisher;
028    
029    /**
030     * An implementation of {@link MessageProducer} which uses the ActiveMQ JCA ResourceAdapter's
031     * current thread's JMS {@link javax.jms.Session} to send messages.
032     *
033     * @version $Revision: 1.1.1.1 $
034     */
035    public class MessageProducerProxy implements MessageProducer, QueueSender, TopicPublisher {
036        
037        private MessageProducer messageProducer;
038        private Destination destination;
039        private int deliveryMode;
040        private boolean disableMessageID;
041        private boolean disableMessageTimestamp;
042        private int priority;
043        private long timeToLive;
044    
045        public MessageProducerProxy(MessageProducer messageProducer, Destination destination) throws JMSException {
046            this.messageProducer = messageProducer;
047            this.destination = destination;
048    
049            this.deliveryMode = messageProducer.getDeliveryMode();
050            this.disableMessageID = messageProducer.getDisableMessageID();
051            this.disableMessageTimestamp = messageProducer.getDisableMessageTimestamp();
052            this.priority = messageProducer.getPriority();
053            this.timeToLive = messageProducer.getTimeToLive();
054        }
055    
056        public void close() throws JMSException {
057            // do nothing as we just go back into the pool
058            // though lets reset the various settings which may have been changed
059            messageProducer.setDeliveryMode(deliveryMode);
060            messageProducer.setDisableMessageID(disableMessageID);
061            messageProducer.setDisableMessageTimestamp(disableMessageTimestamp);
062            messageProducer.setPriority(priority);
063            messageProducer.setTimeToLive(timeToLive);
064        }
065    
066        public Destination getDestination() throws JMSException {
067            return destination;
068        }
069    
070        public int getDeliveryMode() throws JMSException {
071            return messageProducer.getDeliveryMode();
072        }
073    
074        public boolean getDisableMessageID() throws JMSException {
075            return messageProducer.getDisableMessageID();
076        }
077    
078        public boolean getDisableMessageTimestamp() throws JMSException {
079            return messageProducer.getDisableMessageTimestamp();
080        }
081    
082        public int getPriority() throws JMSException {
083            return messageProducer.getPriority();
084        }
085    
086        public long getTimeToLive() throws JMSException {
087            return messageProducer.getTimeToLive();
088        }
089    
090        public void send(Destination destination, Message message) throws JMSException {
091            if (destination == null) {
092                destination = this.destination;
093            }
094            messageProducer.send(destination, message);
095        }
096    
097        public void send(Destination destination, Message message, int deliveryMode, int priority, long timeToLive) throws JMSException {
098            if (destination == null) {
099                destination = this.destination;
100            }
101            messageProducer.send(destination, message, deliveryMode, priority, timeToLive);
102        }
103    
104        public void send(Message message) throws JMSException {
105            messageProducer.send(destination, message);
106        }
107    
108        public void send(Message message, int deliveryMode, int priority, long timeToLive) throws JMSException {
109            messageProducer.send(destination, message, deliveryMode, priority, timeToLive);
110        }
111    
112        public void setDeliveryMode(int i) throws JMSException {
113            messageProducer.setDeliveryMode(i);
114        }
115    
116        public void setDisableMessageID(boolean b) throws JMSException {
117            messageProducer.setDisableMessageID(b);
118        }
119    
120        public void setDisableMessageTimestamp(boolean b) throws JMSException {
121            messageProducer.setDisableMessageTimestamp(b);
122        }
123    
124        public void setPriority(int i) throws JMSException {
125            messageProducer.setPriority(i);
126        }
127    
128        public void setTimeToLive(long l) throws JMSException {
129            messageProducer.setTimeToLive(l);
130        }
131    
132        public Queue getQueue() throws JMSException {
133            return (Queue) messageProducer.getDestination();
134        }
135    
136        public void send(Queue arg0, Message arg1) throws JMSException {
137            messageProducer.send(arg0, arg1);
138        }
139    
140        public void send(Queue arg0, Message arg1, int arg2, int arg3, long arg4) throws JMSException {
141            messageProducer.send(arg0, arg1, arg2, arg3, arg4);
142        }
143    
144        public Topic getTopic() throws JMSException {
145            return (Topic) messageProducer.getDestination();
146        }
147    
148        public void publish(Message arg0) throws JMSException {
149            messageProducer.send(arg0);
150        }
151    
152        public void publish(Message arg0, int arg1, int arg2, long arg3) throws JMSException {
153            messageProducer.send(arg0, arg1, arg2, arg3);
154        }
155    
156        public void publish(Topic arg0, Message arg1) throws JMSException {
157            messageProducer.send(arg0, arg1);
158        }
159    
160        public void publish(Topic arg0, Message arg1, int arg2, int arg3, long arg4) throws JMSException {
161            messageProducer.send(arg0, arg1, arg2, arg3, arg4);
162        }
163    }