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 | 0 | public class SpringConfigurationBuilder implements ConfigurationBuilder |
41 | |
{ |
42 | 0 | protected transient final Log logger = LogFactory.getLog(getClass()); |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
public UMOManager configure(ReaderResource[] configResources) throws ConfigurationException |
53 | |
{ |
54 | |
|
55 | 0 | return configure(configResources, null); |
56 | |
} |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
public UMOManager configure(ReaderResource[] configResources, Properties startupProperties) |
67 | |
throws ConfigurationException |
68 | |
{ |
69 | 0 | throw new UnsupportedOperationException("Not implemented"); |
70 | |
} |
71 | |
|
72 | |
public UMOManager configure(String configResources) throws ConfigurationException |
73 | |
{ |
74 | 0 | return configure(configResources, null); |
75 | |
} |
76 | |
|
77 | |
public UMOManager configure(String configResources, String startupPropertiesFile) |
78 | |
throws ConfigurationException |
79 | |
{ |
80 | |
|
81 | 0 | if (StringUtils.isNotBlank(startupPropertiesFile)) |
82 | |
{ |
83 | |
try |
84 | |
{ |
85 | 0 | startupPropertiesFile = StringUtils.trimToEmpty(startupPropertiesFile); |
86 | 0 | Properties startupProperties = PropertiesUtils.loadProperties(startupPropertiesFile, |
87 | |
getClass()); |
88 | 0 | ((MuleManager)MuleManager.getInstance()).addProperties(startupProperties); |
89 | |
} |
90 | 0 | catch (IOException e) |
91 | |
{ |
92 | 0 | throw new ConfigurationException( |
93 | |
CoreMessages.failedToStart("Mule server from builder"), e); |
94 | 0 | } |
95 | |
} |
96 | |
|
97 | 0 | String[] resources = StringUtils.splitAndTrim(configResources, ","); |
98 | 0 | if (logger.isDebugEnabled()) |
99 | |
{ |
100 | 0 | logger.debug("There is/are " + resources.length + " configuration resource(s): " + ArrayUtils.toString(resources)); |
101 | |
} |
102 | 0 | MuleManager.getConfiguration().setConfigResources(resources); |
103 | |
|
104 | 0 | new MuleApplicationContext(resources); |
105 | |
try |
106 | |
{ |
107 | 0 | if (System.getProperty(MuleProperties.MULE_START_AFTER_CONFIG_SYSTEM_PROPERTY, "true") |
108 | |
.equalsIgnoreCase("true")) |
109 | |
{ |
110 | 0 | MuleManager.getInstance().start(); |
111 | |
} |
112 | |
} |
113 | 0 | catch (UMOException e) |
114 | |
{ |
115 | 0 | throw new ConfigurationException(CoreMessages.failedToStart("Mule server from builder"), e); |
116 | 0 | } |
117 | 0 | return MuleManager.getInstance(); |
118 | |
} |
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
public boolean isConfigured() |
126 | |
{ |
127 | 0 | return MuleManager.isInstanciated(); |
128 | |
} |
129 | |
} |