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.camel.component.activemq;
018    
019    import org.apache.activemq.pool.PooledConnectionFactory;
020    import org.apache.activemq.spring.ActiveMQConnectionFactory;
021    import org.apache.camel.component.jms.JmsConfiguration;
022    
023    import javax.jms.ConnectionFactory;
024    
025    /**
026     * @version $Revision: 1.1 $
027     */
028    public class ActiveMQConfiguration extends JmsConfiguration {
029        private String brokerURL = ActiveMQConnectionFactory.DEFAULT_BROKER_URL;
030    
031        public ActiveMQConfiguration() {
032        }
033    
034        public String getBrokerURL() {
035            return brokerURL;
036        }
037    
038        /**
039         * Sets the broker URL to use to connect to ActiveMQ using the
040         * <a href="http://activemq.apache.org/configuring-transports.html">ActiveMQ URI format</a>
041         *
042         * @param brokerURL the URL of the broker.
043         */
044        public void setBrokerURL(String brokerURL) {
045            this.brokerURL = brokerURL;
046        }
047    
048        @Override
049        public ActiveMQConnectionFactory getListenerConnectionFactory() {
050            return (ActiveMQConnectionFactory) super.getListenerConnectionFactory();
051        }
052    
053        @Override
054        public void setListenerConnectionFactory(ConnectionFactory listenerConnectionFactory) {
055            if (listenerConnectionFactory instanceof ActiveMQConnectionFactory) {
056                super.setListenerConnectionFactory(listenerConnectionFactory);
057            }
058            else {
059                throw new IllegalArgumentException("ConnectionFactory " + listenerConnectionFactory
060                        + " is not an instanceof " + ActiveMQConnectionFactory.class.getName());
061            }
062        }
063    
064        @Override
065        protected ConnectionFactory createListenerConnectionFactory() {
066            ActiveMQConnectionFactory answer = new ActiveMQConnectionFactory();
067            answer.setBrokerURL(getBrokerURL());
068            return answer;
069        }
070    
071        @Override
072        protected ConnectionFactory createTemplateConnectionFactory() {
073            return new PooledConnectionFactory(getListenerConnectionFactory());
074        }
075    }