KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > broker > DefaultBrokerFactory


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.broker;
19
20 import org.apache.activemq.broker.BrokerFactoryHandler;
21 import org.apache.activemq.util.IntrospectionSupport;
22 import org.apache.activemq.util.URISupport;
23 import org.apache.activemq.util.URISupport.CompositeData;
24
25 import java.net.URI JavaDoc;
26 import java.util.HashMap JavaDoc;
27 import java.util.Map JavaDoc;
28
29 /**
30  * Simple BrokerFactorySPI which using the brokerURI to extract the configuration
31  * parameters for the broker service. This directly configures the pojo model
32  * so there is no dependency on spring for configuration.
33  *
34  * @version $Revision$
35  */

36 public class DefaultBrokerFactory implements BrokerFactoryHandler {
37
38     public BrokerService createBroker(URI JavaDoc brokerURI) throws Exception JavaDoc {
39
40         CompositeData compositeData = URISupport.parseComposite(brokerURI);
41         Map JavaDoc params = new HashMap JavaDoc(compositeData.getParameters());
42                 
43         BrokerService brokerService = new BrokerService();
44         IntrospectionSupport.setProperties(brokerService, params);
45         if( compositeData.getPath()!=null )
46             brokerService.setBrokerName(compositeData.getPath());
47         
48         URI JavaDoc[] components = compositeData.getComponents();
49         for (int i = 0; i < components.length; i++) {
50             if( "network".equals(components[i].getScheme()) ) {
51                 brokerService.addNetworkConnector(components[i].getSchemeSpecificPart());
52             } else if( "proxy".equals(components[i].getScheme()) ) {
53                 brokerService.addProxyConnector(components[i].getSchemeSpecificPart());
54             } else {
55                 brokerService.addConnector(components[i]);
56             }
57         }
58         return brokerService;
59     }
60
61 }
62
Popular Tags