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.axis; 018 019 import java.util.HashMap; 020 021 import javax.jms.ConnectionFactory; 022 import javax.jms.QueueConnectionFactory; 023 import javax.jms.TopicConnectionFactory; 024 025 import org.apache.activemq.ActiveMQConnectionFactory; 026 import org.apache.axis.components.jms.BeanVendorAdapter; 027 import org.apache.axis.transport.jms.JMSURLHelper; 028 029 /** 030 * An adapter for using ActiveMQ inside <a 031 * href="http://ws.apache.org/axis/">Apache Axis</a> 032 * 033 * @version $Revision$ 034 */ 035 public class ActiveMQVendorAdapter extends BeanVendorAdapter { 036 037 /** 038 * The URL to connect to the broker 039 */ 040 public static final String BROKER_URL = "brokerURL"; 041 042 /** 043 * Specifies the default user name 044 */ 045 public static final String DEFAULT_USERNAME = "defaultUser"; 046 047 /** 048 * Specifies the default password 049 */ 050 public static final String DEFAULT_PASSWORD = "defaultPassword"; 051 052 protected static final String QCF_CLASS = ActiveMQConnectionFactory.class.getName(); 053 protected static final String TCF_CLASS = QCF_CLASS; 054 055 056 public QueueConnectionFactory getQueueConnectionFactory(HashMap properties) throws Exception { 057 properties = (HashMap)properties.clone(); 058 properties.put(CONNECTION_FACTORY_CLASS, QCF_CLASS); 059 return super.getQueueConnectionFactory(properties); 060 } 061 062 public TopicConnectionFactory getTopicConnectionFactory(HashMap properties) throws Exception { 063 properties = (HashMap)properties.clone(); 064 properties.put(CONNECTION_FACTORY_CLASS, TCF_CLASS); 065 return super.getTopicConnectionFactory(properties); 066 } 067 068 public void addVendorConnectionFactoryProperties(JMSURLHelper jmsUrl, HashMap properties) { 069 if (jmsUrl.getPropertyValue(BROKER_URL) != null) { 070 properties.put(BROKER_URL, jmsUrl.getPropertyValue(BROKER_URL)); 071 } 072 073 if (jmsUrl.getPropertyValue(DEFAULT_USERNAME) != null) { 074 properties.put(DEFAULT_USERNAME, jmsUrl.getPropertyValue(DEFAULT_USERNAME)); 075 } 076 if (jmsUrl.getPropertyValue(DEFAULT_PASSWORD) != null) { 077 properties.put(DEFAULT_PASSWORD, jmsUrl.getPropertyValue(DEFAULT_PASSWORD)); 078 } 079 } 080 081 public boolean isMatchingConnectionFactory(ConnectionFactory connectionFactory, JMSURLHelper jmsURL, HashMap properties) { 082 String brokerURL = null; 083 084 if (connectionFactory instanceof ActiveMQConnectionFactory) { 085 ActiveMQConnectionFactory amqConnectionFactory = (ActiveMQConnectionFactory)connectionFactory; 086 087 // get existing queue connection factory properties 088 brokerURL = amqConnectionFactory.getBrokerURL(); 089 } 090 091 // compare broker url 092 String propertyBrokerURL = (String)properties.get(BROKER_URL); 093 if (brokerURL == null || !brokerURL.equals(propertyBrokerURL)) { 094 return false; 095 } 096 return true; 097 } 098 }