001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  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    package org.apache.activemq.transport.amqp;
018    
019    import javax.jms.BytesMessage;
020    import javax.jms.Destination;
021    import javax.jms.MapMessage;
022    import javax.jms.Message;
023    import javax.jms.ObjectMessage;
024    import javax.jms.Queue;
025    import javax.jms.StreamMessage;
026    import javax.jms.TemporaryQueue;
027    import javax.jms.TemporaryTopic;
028    import javax.jms.TextMessage;
029    import javax.jms.Topic;
030    import org.apache.activemq.command.ActiveMQBytesMessage;
031    import org.apache.activemq.command.ActiveMQDestination;
032    import org.apache.activemq.command.ActiveMQMapMessage;
033    import org.apache.activemq.command.ActiveMQMessage;
034    import org.apache.activemq.command.ActiveMQObjectMessage;
035    import org.apache.activemq.command.ActiveMQQueue;
036    import org.apache.activemq.command.ActiveMQStreamMessage;
037    import org.apache.activemq.command.ActiveMQTempQueue;
038    import org.apache.activemq.command.ActiveMQTempTopic;
039    import org.apache.activemq.command.ActiveMQTextMessage;
040    import org.apache.activemq.command.ActiveMQTopic;
041    import org.apache.qpid.proton.jms.JMSVendor;
042    
043    /**
044     * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
045     */
046    public class ActiveMQJMSVendor extends JMSVendor {
047    
048        final public static ActiveMQJMSVendor INSTANCE = new ActiveMQJMSVendor();
049    
050        private ActiveMQJMSVendor() {}
051    
052        @Override
053        public BytesMessage createBytesMessage() {
054            return new ActiveMQBytesMessage();
055        }
056    
057        @Override
058        public StreamMessage createStreamMessage() {
059            return new ActiveMQStreamMessage();
060        }
061    
062        @Override
063        public Message createMessage() {
064            return new ActiveMQMessage();
065        }
066    
067        @Override
068        public TextMessage createTextMessage() {
069            return new ActiveMQTextMessage();
070        }
071    
072        @Override
073        public ObjectMessage createObjectMessage() {
074            return new ActiveMQObjectMessage();
075        }
076    
077        @Override
078        public MapMessage createMapMessage() {
079            return new ActiveMQMapMessage();
080        }
081    
082        @Override
083        @SuppressWarnings("deprecation")
084        public Destination createDestination(String name) {
085            return super.createDestination(name, Destination.class);
086        }
087    
088        public <T extends Destination> T createDestination(String name, Class<T> kind) {
089            if( kind == Queue.class ) {
090                return kind.cast(new ActiveMQQueue(name));
091            }
092            if( kind == Topic.class ) {
093                return kind.cast(new ActiveMQTopic(name));
094            }
095            if( kind == TemporaryQueue.class ) {
096                return kind.cast(new ActiveMQTempQueue(name));
097            }
098            if( kind == TemporaryTopic.class ) {
099                return kind.cast(new ActiveMQTempTopic(name));
100            }
101            return kind.cast(ActiveMQDestination.createDestination(name, ActiveMQDestination.QUEUE_TYPE));
102        }
103    
104        @Override
105        public void setJMSXUserID(Message msg, String value) {
106            ((ActiveMQMessage)msg).setUserID(value);
107        }
108    
109        @Override
110        public void setJMSXGroupID(Message msg, String value) {
111            ((ActiveMQMessage)msg).setGroupID(value);
112        }
113    
114        @Override
115        public void setJMSXGroupSequence(Message msg, int value) {
116            ((ActiveMQMessage)msg).setGroupSequence(value);
117        }
118    
119        @Override
120        public void setJMSXDeliveryCount(Message msg, long value) {
121            ((ActiveMQMessage)msg).setRedeliveryCounter((int) value);
122        }
123    
124        @Override
125        public String toAddress(Destination dest) {
126            return ((ActiveMQDestination)dest).getQualifiedName();
127        }
128    }