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 {
33 this.appContext = appContext;
34 }
35
36 public SpringConfigurationBuilder(ConfigurableApplicationContext appContext, ApplicationContext parentContext)
37 {
38 this.appContext = appContext;
39 this.parentContext = parentContext;
40 }
41
42 protected void doConfigure(MuleContext muleContext) throws Exception
43 {
44 Registry registry;
45
46 if (parentContext != null)
47 {
48 if (appContext instanceof ConfigurableApplicationContext)
49 {
50 registry = new SpringRegistry((ConfigurableApplicationContext) appContext, parentContext, muleContext);
51 }
52 else
53 {
54 throw new ConfigurationException(MessageFactory.createStaticMessage("Cannot set a parent context if the ApplicationContext does not implement ConfigurableApplicationContext"));
55 }
56 }
57 else
58 {
59 registry = new SpringRegistry(appContext, muleContext);
60 }
61
62
63
64 muleContext.addRegistry(registry);
65 registry.initialise();
66 }
67
68 }