1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.extras.spring.config; |
12 | |
|
13 | |
import org.mule.MuleManager; |
14 | |
import org.mule.config.ConfigurationBuilder; |
15 | |
import org.mule.config.ConfigurationException; |
16 | |
import org.mule.config.MuleProperties; |
17 | |
import org.mule.config.ReaderResource; |
18 | |
import org.mule.config.i18n.CoreMessages; |
19 | |
import org.mule.umo.UMOException; |
20 | |
import org.mule.umo.manager.UMOManager; |
21 | |
import org.mule.util.ArrayUtils; |
22 | |
import org.mule.util.PropertiesUtils; |
23 | |
import org.mule.util.StringUtils; |
24 | |
|
25 | |
import java.io.IOException; |
26 | |
import java.util.Properties; |
27 | |
|
28 | |
import org.apache.commons.logging.Log; |
29 | |
import org.apache.commons.logging.LogFactory; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | 24 | public class SpringConfigurationBuilder implements ConfigurationBuilder |
41 | |
{ |
42 | 24 | protected transient final Log logger = LogFactory.getLog(getClass()); |
43 | |
private MuleApplicationContext muleApplicationContext; |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
public UMOManager configure(ReaderResource[] configResources) throws ConfigurationException |
54 | |
{ |
55 | |
|
56 | 0 | return configure(configResources, null); |
57 | |
} |
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
public UMOManager configure(ReaderResource[] configResources, Properties startupProperties) |
68 | |
throws ConfigurationException |
69 | |
{ |
70 | 0 | throw new UnsupportedOperationException("Not implemented"); |
71 | |
} |
72 | |
|
73 | |
public UMOManager configure(String configResources) throws ConfigurationException |
74 | |
{ |
75 | 0 | return configure(configResources, null); |
76 | |
} |
77 | |
|
78 | |
public UMOManager configure(String configResources, String startupPropertiesFile) |
79 | |
throws ConfigurationException |
80 | |
{ |
81 | |
|
82 | 24 | if (StringUtils.isNotBlank(startupPropertiesFile)) |
83 | |
{ |
84 | |
try |
85 | |
{ |
86 | 0 | startupPropertiesFile = StringUtils.trimToEmpty(startupPropertiesFile); |
87 | 0 | Properties startupProperties = PropertiesUtils.loadProperties(startupPropertiesFile, |
88 | |
getClass()); |
89 | 0 | ((MuleManager)MuleManager.getInstance()).addProperties(startupProperties); |
90 | |
} |
91 | 0 | catch (IOException e) |
92 | |
{ |
93 | 0 | throw new ConfigurationException( |
94 | |
CoreMessages.failedToStart("Mule server from builder"), e); |
95 | 0 | } |
96 | |
} |
97 | |
|
98 | 24 | String[] resources = StringUtils.splitAndTrim(configResources, ","); |
99 | 24 | if (logger.isDebugEnabled()) |
100 | |
{ |
101 | 0 | logger.debug("There is/are " + resources.length + " configuration resource(s): " + ArrayUtils.toString(resources)); |
102 | |
} |
103 | 24 | MuleManager.getConfiguration().setConfigResources(resources); |
104 | |
|
105 | 24 | muleApplicationContext = new MuleApplicationContext(resources); |
106 | |
|
107 | |
try |
108 | |
{ |
109 | 24 | if (System.getProperty(MuleProperties.MULE_START_AFTER_CONFIG_SYSTEM_PROPERTY, "true") |
110 | |
.equalsIgnoreCase("true")) |
111 | |
{ |
112 | 24 | MuleManager.getInstance().start(); |
113 | |
} |
114 | |
} |
115 | 0 | catch (UMOException e) |
116 | |
{ |
117 | 0 | throw new ConfigurationException(CoreMessages.failedToStart("Mule server from builder"), e); |
118 | 24 | } |
119 | 24 | return MuleManager.getInstance(); |
120 | |
} |
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
public boolean isConfigured() |
128 | |
{ |
129 | 0 | return MuleManager.isInstanciated(); |
130 | |
} |
131 | |
|
132 | |
public MuleApplicationContext getMuleApplicationContext() |
133 | |
{ |
134 | 0 | return muleApplicationContext; |
135 | |
} |
136 | |
|
137 | |
} |