1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.config.builders; |
8 | |
|
9 | |
import org.mule.api.MuleContext; |
10 | |
import org.mule.api.config.ConfigurationBuilder; |
11 | |
import org.mule.api.config.ConfigurationException; |
12 | |
import org.mule.config.ConfigResource; |
13 | |
import org.mule.config.i18n.CoreMessages; |
14 | |
import org.mule.util.StringUtils; |
15 | |
|
16 | |
import java.io.IOException; |
17 | |
|
18 | |
import org.apache.commons.logging.Log; |
19 | |
import org.apache.commons.logging.LogFactory; |
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
public abstract class AbstractResourceConfigurationBuilder extends AbstractConfigurationBuilder |
29 | |
{ |
30 | |
|
31 | 0 | protected static final Log logger = LogFactory.getLog(AutoConfigurationBuilder.class); |
32 | |
|
33 | |
protected ConfigResource[] configResources; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
public AbstractResourceConfigurationBuilder(String configResources) throws ConfigurationException |
41 | 0 | { |
42 | 0 | this.configResources = loadConfigResources(StringUtils.splitAndTrim(configResources, ",; ")); |
43 | 0 | } |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
public AbstractResourceConfigurationBuilder(String[] configResources) throws ConfigurationException |
51 | 0 | { |
52 | 0 | this.configResources = loadConfigResources(configResources); |
53 | 0 | } |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
public AbstractResourceConfigurationBuilder(ConfigResource[] configResources) |
59 | 0 | { |
60 | 0 | this.configResources = configResources; |
61 | 0 | } |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
public void configure(MuleContext muleContext) throws ConfigurationException |
68 | |
{ |
69 | 0 | if (configResources == null) |
70 | |
{ |
71 | 0 | throw new ConfigurationException(CoreMessages.objectIsNull("Configuration Resources")); |
72 | |
} |
73 | |
|
74 | 0 | super.configure(muleContext); |
75 | |
|
76 | 0 | logger.info(CoreMessages.configurationBuilderSuccess(this, createConfigResourcesString())); |
77 | 0 | } |
78 | |
|
79 | |
protected ConfigResource[] loadConfigResources(String[] configs) throws ConfigurationException |
80 | |
{ |
81 | |
try |
82 | |
{ |
83 | 0 | configResources = new ConfigResource[configs.length]; |
84 | 0 | for (int i = 0; i < configs.length; i++) |
85 | |
{ |
86 | 0 | configResources[i] = new ConfigResource(configs[i]); |
87 | |
} |
88 | 0 | return configResources; |
89 | |
} |
90 | 0 | catch (IOException e) |
91 | |
{ |
92 | 0 | throw new ConfigurationException(e); |
93 | |
} |
94 | |
} |
95 | |
|
96 | |
protected String createConfigResourcesString() |
97 | |
{ |
98 | 0 | StringBuffer configResourcesString = new StringBuffer(); |
99 | 0 | configResourcesString.append("["); |
100 | 0 | for (int i = 0; i < configResources.length; i++) |
101 | |
{ |
102 | 0 | configResourcesString.append(configResources[i]); |
103 | 0 | if (i < configResources.length - 1) |
104 | |
{ |
105 | 0 | configResourcesString.append(", "); |
106 | |
} |
107 | |
} |
108 | 0 | configResourcesString.append("]"); |
109 | 0 | return configResourcesString.toString(); |
110 | |
} |
111 | |
} |