KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > axis > ActiveMQVendorAdapter


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.axis;
19
20 import org.apache.activemq.ActiveMQConnectionFactory;
21 import org.apache.axis.components.jms.BeanVendorAdapter;
22 import org.apache.axis.transport.jms.JMSURLHelper;
23
24 import javax.jms.ConnectionFactory JavaDoc;
25 import javax.jms.QueueConnectionFactory JavaDoc;
26 import javax.jms.TopicConnectionFactory JavaDoc;
27 import java.util.HashMap JavaDoc;
28
29 /**
30  * An adapter for using ActiveMQ inside <a HREF="http://ws.apache.org/axis/">Apache Axis</a>
31  *
32  * @version $Revision$
33  */

34 public class ActiveMQVendorAdapter extends BeanVendorAdapter {
35
36     protected final static String JavaDoc QCF_CLASS = ActiveMQConnectionFactory.class.getName();
37     protected final static String JavaDoc TCF_CLASS = QCF_CLASS;
38
39
40     /**
41      * The URL to connect to the broker
42      */

43     public final static String JavaDoc BROKER_URL = "brokerURL";
44
45     /**
46      * Specifies the default user name
47      */

48     public final static String JavaDoc DEFAULT_USERNAME = "defaultUser";
49
50     /**
51      * Specifies the default password
52      */

53     public final static String JavaDoc DEFAULT_PASSWORD = "defaultPassword";
54
55
56     public QueueConnectionFactory JavaDoc getQueueConnectionFactory(HashMap JavaDoc properties)
57             throws Exception JavaDoc {
58         properties = (HashMap JavaDoc) properties.clone();
59         properties.put(CONNECTION_FACTORY_CLASS, QCF_CLASS);
60         return super.getQueueConnectionFactory(properties);
61     }
62
63     public TopicConnectionFactory JavaDoc getTopicConnectionFactory(HashMap JavaDoc properties)
64             throws Exception JavaDoc {
65         properties = (HashMap JavaDoc) properties.clone();
66         properties.put(CONNECTION_FACTORY_CLASS, TCF_CLASS);
67         return super.getTopicConnectionFactory(properties);
68     }
69
70
71     public void addVendorConnectionFactoryProperties(JMSURLHelper jmsUrl, HashMap JavaDoc properties) {
72         if (jmsUrl.getPropertyValue(BROKER_URL) != null) {
73             properties.put(BROKER_URL, jmsUrl.getPropertyValue(BROKER_URL));
74         }
75
76         if (jmsUrl.getPropertyValue(DEFAULT_USERNAME) != null) {
77             properties.put(DEFAULT_USERNAME, jmsUrl.getPropertyValue(DEFAULT_USERNAME));
78         }
79         if (jmsUrl.getPropertyValue(DEFAULT_PASSWORD) != null) {
80             properties.put(DEFAULT_PASSWORD, jmsUrl.getPropertyValue(DEFAULT_PASSWORD));
81         }
82     }
83
84     public boolean isMatchingConnectionFactory(ConnectionFactory connectionFactory, JMSURLHelper jmsURL, HashMap JavaDoc properties) {
85         String JavaDoc brokerURL = null;
86
87         if (connectionFactory instanceof ActiveMQConnectionFactory) {
88             ActiveMQConnectionFactory amqConnectionFactory =
89                     (ActiveMQConnectionFactory) connectionFactory;
90
91             // get existing queue connection factory properties
92
brokerURL = amqConnectionFactory.getBrokerURL();
93         }
94
95         // compare broker url
96
String JavaDoc propertyBrokerURL = (String JavaDoc) properties.get(BROKER_URL);
97         if (!brokerURL.equals(propertyBrokerURL)) {
98             return false;
99         }
100         return true;
101     }
102 }
103
Popular Tags