View Javadoc

    1   /***
    2    *
    3    * Copyright 2004 Protique Ltd
    4    *
    5    * Licensed under the Apache License, Version 2.0 (the "License");
    6    * you may not use this file except in compliance with the License.
    7    * You may obtain a copy of the License at
    8    *
    9    * http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   *
    17   **/
    18  package org.codehaus.activemq.axis;
    19
    20  import org.apache.axis.components.jms.BeanVendorAdapter;
    21  import org.apache.axis.transport.jms.JMSURLHelper;
    22  import org.codehaus.activemq.ActiveMQConnectionFactory;
    23
    24  import javax.jms.ConnectionFactory;
    25  import javax.jms.QueueConnectionFactory;
    26  import javax.jms.TopicConnectionFactory;
    27  import java.util.HashMap;
    28
    29  /***
    30   * An adapter for using ActiveMQ inside <a href="http://ws.apache.org/axis/">Apache Axis</a>
    31   *
    32   * @version $Revision: 1.3 $
    33   */
    34  public class ActiveMQVendorAdapter extends BeanVendorAdapter {
    35
    36      protected final static String QCF_CLASS = ActiveMQConnectionFactory.class.getName();
    37      protected final static String TCF_CLASS = QCF_CLASS;
    38
    39
    40      /***
    41       * The URL to connect to the broker
    42       */
    43      public final static String BROKER_URL = "brokerURL";
    44
    45      /***
    46       * Specifies the default user name
    47       */
    48      public final static String DEFAULT_USERNAME = "defaultUser";
    49
    50      /***
    51       * Specifies the default password
    52       */
    53      public final static String DEFAULT_PASSWORD = "defaultPassword";
    54
    55      /***
    56       * Specifies whether the broker is embedded
    57       */
    58      public final static String EMBEDDED_BROKER = "embeddedBroker";
    59
    60
    61      public QueueConnectionFactory getQueueConnectionFactory(HashMap properties)
    62              throws Exception {
    63          properties = (HashMap) properties.clone();
    64          properties.put(CONNECTION_FACTORY_CLASS, QCF_CLASS);
    65          return super.getQueueConnectionFactory(properties);
    66      }
    67
    68      public TopicConnectionFactory getTopicConnectionFactory(HashMap properties)
    69              throws Exception {
    70          properties = (HashMap) properties.clone();
    71          properties.put(CONNECTION_FACTORY_CLASS, TCF_CLASS);
    72          return super.getTopicConnectionFactory(properties);
    73      }
    74
    75
    76      public void addVendorConnectionFactoryProperties(JMSURLHelper jmsUrl, HashMap properties) {
    77          if (jmsUrl.getPropertyValue(BROKER_URL) != null) {
    78              properties.put(BROKER_URL, jmsUrl.getPropertyValue(BROKER_URL));
    79          }
    80
    81          if (jmsUrl.getPropertyValue(DEFAULT_USERNAME) != null) {
    82              properties.put(DEFAULT_USERNAME, jmsUrl.getPropertyValue(DEFAULT_USERNAME));
    83          }
    84          if (jmsUrl.getPropertyValue(DEFAULT_PASSWORD) != null) {
    85              properties.put(DEFAULT_PASSWORD, jmsUrl.getPropertyValue(DEFAULT_PASSWORD));
    86          }
    87          if (jmsUrl.getPropertyValue(EMBEDDED_BROKER) != null) {
    88              properties.put(EMBEDDED_BROKER, jmsUrl.getPropertyValue(EMBEDDED_BROKER));
    89          }
    90      }
    91
    92      public boolean isMatchingConnectionFactory(ConnectionFactory connectionFactory, JMSURLHelper jmsURL, HashMap properties) {
    93          String brokerURL = null;
    94          boolean embeddedBroker = false;
    95
    96          if (connectionFactory instanceof ActiveMQConnectionFactory) {
    97              ActiveMQConnectionFactory amqConnectionFactory =
    98                      (ActiveMQConnectionFactory) connectionFactory;
    99
    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 }