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 */ 017package org.apache.activemq.transport.amqp; 018 019import javax.jms.BytesMessage; 020import javax.jms.Destination; 021import javax.jms.MapMessage; 022import javax.jms.Message; 023import javax.jms.ObjectMessage; 024import javax.jms.Queue; 025import javax.jms.StreamMessage; 026import javax.jms.TemporaryQueue; 027import javax.jms.TemporaryTopic; 028import javax.jms.TextMessage; 029import javax.jms.Topic; 030 031import org.apache.activemq.command.ActiveMQBytesMessage; 032import org.apache.activemq.command.ActiveMQDestination; 033import org.apache.activemq.command.ActiveMQMapMessage; 034import org.apache.activemq.command.ActiveMQMessage; 035import org.apache.activemq.command.ActiveMQObjectMessage; 036import org.apache.activemq.command.ActiveMQQueue; 037import org.apache.activemq.command.ActiveMQStreamMessage; 038import org.apache.activemq.command.ActiveMQTempQueue; 039import org.apache.activemq.command.ActiveMQTempTopic; 040import org.apache.activemq.command.ActiveMQTextMessage; 041import org.apache.activemq.command.ActiveMQTopic; 042import org.apache.qpid.proton.jms.JMSVendor; 043 044/** 045 */ 046public class ActiveMQJMSVendor extends JMSVendor { 047 048 final public static ActiveMQJMSVendor INSTANCE = new ActiveMQJMSVendor(); 049 050 private static final String PREFIX_MARKER = "://"; 051 052 private ActiveMQJMSVendor() { 053 } 054 055 @Override 056 public BytesMessage createBytesMessage() { 057 return new ActiveMQBytesMessage(); 058 } 059 060 @Override 061 public StreamMessage createStreamMessage() { 062 return new ActiveMQStreamMessage(); 063 } 064 065 @Override 066 public Message createMessage() { 067 return new ActiveMQMessage(); 068 } 069 070 @Override 071 public TextMessage createTextMessage() { 072 return new ActiveMQTextMessage(); 073 } 074 075 @Override 076 public ObjectMessage createObjectMessage() { 077 return new ActiveMQObjectMessage(); 078 } 079 080 @Override 081 public MapMessage createMapMessage() { 082 return new ActiveMQMapMessage(); 083 } 084 085 @Override 086 public Destination createDestination(String name) { 087 return super.createDestination(name, Destination.class); 088 } 089 090 @Override 091 public <T extends Destination> T createDestination(String name, Class<T> kind) { 092 String destinationName = name; 093 int prefixEnd = name.lastIndexOf(PREFIX_MARKER); 094 095 if (prefixEnd >= 0) { 096 destinationName = name.substring(prefixEnd + PREFIX_MARKER.length()); 097 } 098 099 if (kind == Queue.class) { 100 return kind.cast(new ActiveMQQueue(destinationName)); 101 } 102 if (kind == Topic.class) { 103 return kind.cast(new ActiveMQTopic(destinationName)); 104 } 105 if (kind == TemporaryQueue.class) { 106 return kind.cast(new ActiveMQTempQueue(destinationName)); 107 } 108 if (kind == TemporaryTopic.class) { 109 return kind.cast(new ActiveMQTempTopic(destinationName)); 110 } 111 112 return kind.cast(ActiveMQDestination.createDestination(name, ActiveMQDestination.QUEUE_TYPE)); 113 } 114 115 @Override 116 public void setJMSXUserID(Message msg, String value) { 117 ((ActiveMQMessage) msg).setUserID(value); 118 } 119 120 @Override 121 public void setJMSXGroupID(Message msg, String value) { 122 ((ActiveMQMessage) msg).setGroupID(value); 123 } 124 125 @Override 126 public void setJMSXGroupSequence(Message msg, int value) { 127 ((ActiveMQMessage) msg).setGroupSequence(value); 128 } 129 130 @Override 131 public void setJMSXDeliveryCount(Message msg, long value) { 132 ((ActiveMQMessage) msg).setRedeliveryCounter((int) value); 133 } 134 135 @Override 136 public String toAddress(Destination dest) { 137 return ((ActiveMQDestination) dest).getQualifiedName(); 138 } 139}