1
2
3
4
5
6
7
8
9
10
11 package org.mule.extras.spring.config;
12
13 import java.io.IOException;
14
15 import org.springframework.beans.BeansException;
16 import org.springframework.beans.factory.support.DefaultListableBeanFactory;
17 import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
18 import org.springframework.context.support.AbstractXmlApplicationContext;
19 import org.springframework.core.io.Resource;
20
21
22
23
24
25
26
27
28 public class MuleApplicationContext extends AbstractXmlApplicationContext
29 {
30 private final Resource[] configResources;
31 private final String[] configLocations;
32
33 public MuleApplicationContext(Resource[] configResources)
34 {
35 this(configResources, true);
36 }
37
38 public MuleApplicationContext(Resource[] configResources, boolean refresh) throws BeansException
39 {
40 this.configResources = configResources;
41 this.configLocations = null;
42 if (refresh)
43 {
44 refresh();
45 }
46 }
47
48 public MuleApplicationContext(String[] configLocations)
49 {
50 this(configLocations, true);
51 }
52
53 public MuleApplicationContext(String[] configLocations, boolean refresh) throws BeansException
54 {
55 this.configLocations = configLocations;
56 this.configResources = null;
57 if (refresh)
58 {
59 refresh();
60 }
61 }
62
63
64 protected Resource[] getConfigResources()
65 {
66 return configResources;
67 }
68
69
70 protected String[] getConfigLocations()
71 {
72 return configLocations;
73 }
74
75
76 protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws IOException
77 {
78 XmlBeanDefinitionReader beanDefinitionReader = new MuleBeanDefinitionReader(beanFactory,
79 configResources != null ? configResources.length : configLocations.length);
80
81 initBeanDefinitionReader(beanDefinitionReader);
82 loadBeanDefinitions(beanDefinitionReader);
83 }
84 }