1 /***
2 *
3 * Copyright 2004 Protique Ltd
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * 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 **/
18 package org.codehaus.activemq.spring;
19
20 import org.codehaus.activemq.broker.BrokerContainer;
21 import org.codehaus.activemq.broker.BrokerContainerFactory;
22 import org.springframework.core.io.Resource;
23
24 /***
25 * A Spring implementatation of {@link BrokerContainerFactory} which uses an XML
26 * deployment configuration file to load and configure a {@link BrokerContainer}
27 *
28 * @version $Revision: 1.1 $
29 */
30 public class SpringBrokerContainerFactory implements BrokerContainerFactory {
31 private Resource resource;
32
33
34 /***
35 * A static factory method that can be used in Spring config files using a factory method
36 * mechanism to create a broker container easily.
37 */
38 public static BrokerContainer newInstance(Resource resource, String brokerName) {
39 SpringBrokerContainerFactory factory = new SpringBrokerContainerFactory(resource);
40 return factory.createBrokerContainer(brokerName);
41 }
42
43 public SpringBrokerContainerFactory() {
44 }
45
46 public SpringBrokerContainerFactory(Resource resource) {
47 this.resource = resource;
48 }
49
50 public BrokerContainer createBrokerContainer(String brokerName) {
51 ActiveMQBeanFactory beanFactory = new ActiveMQBeanFactory(brokerName, resource);
52 return (BrokerContainer) beanFactory.getBean("broker");
53 }
54
55
56
57 public Resource getResource() {
58 return resource;
59 }
60
61 public void setResource(Resource resource) {
62 this.resource = resource;
63 }
64 }