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 | 0 | protected String defaultConfigResourceName = "default-mule-config.xml"; |
30 | |
|
31 | |
protected ApplicationContext parentContext; |
32 | |
|
33 | |
public SpringXmlConfigurationBuilder(String configResources, ApplicationContext parentContext) throws ConfigurationException |
34 | |
{ |
35 | 0 | super(configResources); |
36 | 0 | this.parentContext = parentContext; |
37 | 0 | } |
38 | |
|
39 | |
public SpringXmlConfigurationBuilder(String[] configResources, ApplicationContext parentContext) throws ConfigurationException |
40 | |
{ |
41 | 0 | super(configResources); |
42 | 0 | this.parentContext = parentContext; |
43 | 0 | } |
44 | |
|
45 | |
public SpringXmlConfigurationBuilder(String[] configResources) throws ConfigurationException |
46 | |
{ |
47 | 0 | this(configResources, null); |
48 | 0 | } |
49 | |
|
50 | |
public SpringXmlConfigurationBuilder(String configResources) throws ConfigurationException |
51 | |
{ |
52 | 0 | this(configResources, null); |
53 | 0 | } |
54 | |
|
55 | |
public SpringXmlConfigurationBuilder(ConfigResource[] configResources, ApplicationContext parentContext) |
56 | |
{ |
57 | 0 | super(configResources); |
58 | 0 | this.parentContext = parentContext; |
59 | 0 | } |
60 | |
|
61 | |
public SpringXmlConfigurationBuilder(ConfigResource[] configResources) |
62 | |
{ |
63 | 0 | this(configResources, null); |
64 | 0 | } |
65 | |
|
66 | |
protected void doConfigure(MuleContext muleContext) throws Exception |
67 | |
{ |
68 | 0 | ConfigResource[] all = new ConfigResource[configResources.length + 1]; |
69 | 0 | all[0] = new ConfigResource(defaultConfigResourceName); |
70 | 0 | System.arraycopy(configResources, 0, all, 1, configResources.length); |
71 | 0 | createSpringParentRegistry(muleContext, muleContext.getRegistry(), all); |
72 | 0 | } |
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 | 0 | if (parentContext != null) |
90 | |
{ |
91 | 0 | new MuleApplicationContext(muleContext, registry, all, parentContext); |
92 | |
} |
93 | |
else |
94 | |
{ |
95 | 0 | new MuleApplicationContext(muleContext, registry, all); |
96 | |
} |
97 | |
} |
98 | 0 | catch (BeansException e) |
99 | |
{ |
100 | |
|
101 | |
|
102 | 0 | registry.setParent(null); |
103 | 0 | throw e; |
104 | 0 | } |
105 | 0 | } |
106 | |
|
107 | |
public void setDefaultConfigResourceName(String defaultConfigResourceName) |
108 | |
{ |
109 | 0 | this.defaultConfigResourceName = defaultConfigResourceName; |
110 | 0 | } |
111 | |
|
112 | |
public void setParentContext(ApplicationContext parentContext) |
113 | |
{ |
114 | 0 | this.parentContext = parentContext; |
115 | 0 | } |
116 | |
|
117 | |
} |