1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.config.spring; |
8 | |
|
9 | |
import org.mule.api.MuleContext; |
10 | |
import org.mule.api.config.ConfigurationException; |
11 | |
import org.mule.api.registry.Registry; |
12 | |
import org.mule.config.builders.AbstractConfigurationBuilder; |
13 | |
import org.mule.config.i18n.MessageFactory; |
14 | |
|
15 | |
import org.springframework.context.ApplicationContext; |
16 | |
import org.springframework.context.ConfigurableApplicationContext; |
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
public class SpringConfigurationBuilder extends AbstractConfigurationBuilder |
22 | |
{ |
23 | |
private ApplicationContext appContext; |
24 | |
|
25 | |
private ApplicationContext parentContext; |
26 | |
|
27 | |
public SpringConfigurationBuilder(ApplicationContext appContext) |
28 | 0 | { |
29 | 0 | this.appContext = appContext; |
30 | 0 | } |
31 | |
|
32 | |
public SpringConfigurationBuilder(ConfigurableApplicationContext appContext, ApplicationContext parentContext) |
33 | 0 | { |
34 | 0 | this.appContext = appContext; |
35 | 0 | this.parentContext = parentContext; |
36 | 0 | } |
37 | |
|
38 | |
protected void doConfigure(MuleContext muleContext) throws Exception |
39 | |
{ |
40 | |
Registry registry; |
41 | |
|
42 | 0 | if (parentContext != null) |
43 | |
{ |
44 | 0 | if (appContext instanceof ConfigurableApplicationContext) |
45 | |
{ |
46 | 0 | registry = new SpringRegistry((ConfigurableApplicationContext) appContext, parentContext, muleContext); |
47 | |
} |
48 | |
else |
49 | |
{ |
50 | 0 | throw new ConfigurationException(MessageFactory.createStaticMessage("Cannot set a parent context if the ApplicationContext does not implement ConfigurableApplicationContext")); |
51 | |
} |
52 | |
} |
53 | |
else |
54 | |
{ |
55 | 0 | registry = new SpringRegistry(appContext, muleContext); |
56 | |
} |
57 | |
|
58 | |
|
59 | |
|
60 | 0 | muleContext.addRegistry(registry); |
61 | 0 | registry.initialise(); |
62 | 0 | } |
63 | |
|
64 | |
} |