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