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