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.builders.AbstractConfigurationBuilder; |
17 | |
import org.mule.config.i18n.MessageFactory; |
18 | |
|
19 | |
import org.springframework.context.ApplicationContext; |
20 | |
import org.springframework.context.ConfigurableApplicationContext; |
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
public class SpringConfigurationBuilder extends AbstractConfigurationBuilder |
26 | |
{ |
27 | |
private ApplicationContext appContext; |
28 | |
|
29 | |
private ApplicationContext parentContext; |
30 | |
|
31 | |
public SpringConfigurationBuilder(ApplicationContext appContext) |
32 | 0 | { |
33 | 0 | this.appContext = appContext; |
34 | 0 | } |
35 | |
|
36 | |
public SpringConfigurationBuilder(ConfigurableApplicationContext appContext, ApplicationContext parentContext) |
37 | 0 | { |
38 | 0 | this.appContext = appContext; |
39 | 0 | this.parentContext = parentContext; |
40 | 0 | } |
41 | |
|
42 | |
protected void doConfigure(MuleContext muleContext) throws Exception |
43 | |
{ |
44 | |
Registry registry; |
45 | |
|
46 | 0 | if (parentContext != null) |
47 | |
{ |
48 | 0 | if (appContext instanceof ConfigurableApplicationContext) |
49 | |
{ |
50 | 0 | registry = new SpringRegistry((ConfigurableApplicationContext) appContext, parentContext, muleContext); |
51 | |
} |
52 | |
else |
53 | |
{ |
54 | 0 | throw new ConfigurationException(MessageFactory.createStaticMessage("Cannot set a parent context if the ApplicationContext does not implement ConfigurableApplicationContext")); |
55 | |
} |
56 | |
} |
57 | |
else |
58 | |
{ |
59 | 0 | registry = new SpringRegistry(appContext, muleContext); |
60 | |
} |
61 | |
|
62 | |
|
63 | |
|
64 | 0 | muleContext.addRegistry(registry); |
65 | 0 | registry.initialise(); |
66 | 0 | } |
67 | |
|
68 | |
} |