1
2
3
4
5
6
7
8
9
10
11 package org.mule.config.spring;
12
13 import org.mule.api.MuleContext;
14 import org.mule.api.config.ConfigurationException;
15 import org.mule.api.registry.Registry;
16 import org.mule.config.ConfigResource;
17 import org.mule.config.builders.AbstractResourceConfigurationBuilder;
18
19 import org.springframework.beans.BeansException;
20 import org.springframework.context.ApplicationContext;
21
22
23
24
25
26
27 public class SpringXmlConfigurationBuilder extends AbstractResourceConfigurationBuilder
28 {
29 protected String defaultConfigResourceName = "default-mule-config.xml";
30
31 protected ApplicationContext parentContext;
32
33 public SpringXmlConfigurationBuilder(String configResources, ApplicationContext parentContext) throws ConfigurationException
34 {
35 super(configResources);
36 this.parentContext = parentContext;
37 }
38
39 public SpringXmlConfigurationBuilder(String[] configResources, ApplicationContext parentContext) throws ConfigurationException
40 {
41 super(configResources);
42 this.parentContext = parentContext;
43 }
44
45 public SpringXmlConfigurationBuilder(String[] configResources) throws ConfigurationException
46 {
47 this(configResources, null);
48 }
49
50 public SpringXmlConfigurationBuilder(String configResources) throws ConfigurationException
51 {
52 this(configResources, null);
53 }
54
55 public SpringXmlConfigurationBuilder(ConfigResource[] configResources, ApplicationContext parentContext)
56 {
57 super(configResources);
58 this.parentContext = parentContext;
59 }
60
61 public SpringXmlConfigurationBuilder(ConfigResource[] configResources)
62 {
63 this(configResources, null);
64 }
65
66 protected void doConfigure(MuleContext muleContext) throws Exception
67 {
68 ConfigResource[] all = new ConfigResource[configResources.length + 1];
69 all[0] = new ConfigResource(defaultConfigResourceName);
70 System.arraycopy(configResources, 0, all, 1, configResources.length);
71 createSpringParentRegistry(muleContext, muleContext.getRegistry(), all);
72 }
73
74
75
76
77
78
79
80
81
82
83
84
85 protected void createSpringParentRegistry(MuleContext muleContext, Registry registry, ConfigResource[] all)
86 {
87 try
88 {
89 if (parentContext != null)
90 {
91 new MuleApplicationContext(muleContext, registry, all, parentContext);
92 }
93 else
94 {
95 new MuleApplicationContext(muleContext, registry, all);
96 }
97 }
98 catch (BeansException e)
99 {
100
101
102 registry.setParent(null);
103 throw e;
104 }
105 }
106
107 public void setDefaultConfigResourceName(String defaultConfigResourceName)
108 {
109 this.defaultConfigResourceName = defaultConfigResourceName;
110 }
111
112 public void setParentContext(ApplicationContext parentContext)
113 {
114 this.parentContext = parentContext;
115 }
116
117 }