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.region.group;
018    
019    import java.io.IOException;
020    import java.util.Map;
021    
022    import org.apache.activemq.util.FactoryFinder;
023    import org.apache.activemq.util.IOExceptionSupport;
024    import org.apache.activemq.util.IntrospectionSupport;
025    import org.apache.activemq.util.URISupport;
026    
027    public class GroupFactoryFinder {
028        private static final FactoryFinder GROUP_FACTORY_FINDER = new FactoryFinder("META-INF/services/org/apache/activemq/groups/");
029    
030        private GroupFactoryFinder() {
031        }
032    
033        public static MessageGroupMapFactory createMessageGroupMapFactory(String type) throws IOException {
034            try {
035                Map<String,String> properties = null;
036                String factoryType = type.trim();
037                int p = factoryType.indexOf('?');
038                if (p >= 0){
039                    String propertiesString = factoryType.substring(p+1);
040                    factoryType = factoryType.substring(0,p);
041                    properties = URISupport.parseQuery(propertiesString);
042                }
043                MessageGroupMapFactory result =  (MessageGroupMapFactory)GROUP_FACTORY_FINDER.newInstance(factoryType);
044                if (properties != null && result != null){
045                    IntrospectionSupport.setProperties(result,properties);
046                }
047                return result;
048    
049            } catch (Throwable e) {
050                throw IOExceptionSupport.create("Could not load " + type + " factory:" + e, e);
051            }
052        }
053    
054    
055    }