Home » activemq-parent-5.3.1-source-release » org.apache.activemq.web.config » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  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   package org.apache.activemq.web.config;
   18   
   19   import java.net.MalformedURLException;
   20   import java.util.ArrayList;
   21   import java.util.Collection;
   22   
   23   import javax.jms.ConnectionFactory;
   24   import javax.management.remote.JMXServiceURL;
   25   
   26   import org.apache.activemq.ActiveMQConnectionFactory;
   27   
   28   /**
   29    * Base class for configurations.
   30    * 
   31    * @version $Revision: $
   32    */
   33   public abstract class AbstractConfiguration implements WebConsoleConfiguration {
   34   
   35   	public ConnectionFactory getConnectionFactory() {
   36   		return null;
   37   	}
   38   
   39   	public String getJmxPassword() {
   40   		return null;
   41   	}
   42   
   43   	public Collection<JMXServiceURL> getJmxUrls() {
   44   		return null;
   45   	}
   46   
   47   	public String getJmxUser() {
   48   		return null;
   49   	}
   50   
   51   	/**
   52   	 * Creates the ActiveMQ-ConnectionFactory.
   53   	 * 
   54   	 * @param jmsUrl
   55   	 *            not <code>null</code>
   56   	 * @param jmsUser
   57   	 *            <code>null</code> if no authentication
   58   	 * @param jmsPassword
   59   	 *            <code>null</code> is ok
   60   	 * @return not <code>null</code>
   61   	 */
   62   	protected ConnectionFactory makeConnectionFactory(String jmsUrl, String jmsUser,
   63   			String jmsPassword) {
   64   				if (jmsUser != null && jmsUser.length() > 0)
   65   					return new ActiveMQConnectionFactory(jmsUser, jmsPassword, jmsUrl);
   66   				else
   67   					return new ActiveMQConnectionFactory(jmsUrl);
   68   			}
   69   
   70   	/**
   71   	 * Splits the JMX-Url string into a series of JMSServiceURLs.
   72   	 * 
   73   	 * @param jmxUrls
   74   	 *            the JMX-url, multiple URLs are separated by commas.
   75   	 * @return not <code>null</code>, contains at least one element.
   76   	 */
   77   	protected Collection<JMXServiceURL> makeJmxUrls(String jmxUrls) {
   78   		String[] urls = jmxUrls.split(",");
   79   		if (urls == null || urls.length == 0) {
   80   			urls = new String[] { jmxUrls };
   81   		}
   82   	
   83   		try {
   84   			Collection<JMXServiceURL> result = new ArrayList<JMXServiceURL>(
   85   					jmxUrls.length());
   86   			for (String url : urls) {
   87   				result.add(new JMXServiceURL(url));
   88   			}
   89   			return result;
   90   		} catch (MalformedURLException e) {
   91   			throw new IllegalArgumentException("Invalid JMX-url", e);
   92   		}
   93   	}
   94   
   95   }

Home » activemq-parent-5.3.1-source-release » org.apache.activemq.web.config » [javadoc | source]