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.activemq.broker; 018 019 import java.net.URI; 020 import java.util.HashMap; 021 import java.util.Map; 022 023 import org.apache.activemq.util.IntrospectionSupport; 024 import org.apache.activemq.util.URISupport; 025 import org.apache.activemq.util.URISupport.CompositeData; 026 027 /** 028 * Simple BrokerFactorySPI which using the brokerURI to extract the 029 * configuration parameters for the broker service. This directly configures the 030 * pojo model so there is no dependency on spring for configuration. 031 * 032 * 033 */ 034 public class DefaultBrokerFactory implements BrokerFactoryHandler { 035 036 public BrokerService createBroker(URI brokerURI) throws Exception { 037 038 CompositeData compositeData = URISupport.parseComposite(brokerURI); 039 Map<String, String> params = new HashMap<String, String>(compositeData.getParameters()); 040 041 BrokerService brokerService = new BrokerService(); 042 IntrospectionSupport.setProperties(brokerService, params); 043 if (compositeData.getPath() != null) { 044 brokerService.setBrokerName(compositeData.getPath()); 045 } 046 047 URI[] components = compositeData.getComponents(); 048 for (int i = 0; i < components.length; i++) { 049 if ("network".equals(components[i].getScheme())) { 050 brokerService.addNetworkConnector(components[i].getSchemeSpecificPart()); 051 } else if ("proxy".equals(components[i].getScheme())) { 052 brokerService.addProxyConnector(components[i].getSchemeSpecificPart()); 053 } else { 054 brokerService.addConnector(components[i]); 055 } 056 } 057 return brokerService; 058 } 059 060 }