1
2
3
4
5
6
7
8
9
10
11 package org.mule.config.builders;
12
13 import org.mule.config.ConfigurationException;
14 import org.mule.config.ReaderResource;
15 import org.mule.config.i18n.CoreMessages;
16 import org.mule.umo.manager.UMOManager;
17 import org.mule.util.ObjectUtils;
18 import org.mule.util.StringUtils;
19
20 import java.io.IOException;
21 import java.io.InputStreamReader;
22 import java.net.URL;
23 import java.util.ArrayList;
24 import java.util.List;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 public class MuleClasspathConfigurationBuilder extends MuleXmlConfigurationBuilder
44 {
45
46
47
48 protected static final Log logger = LogFactory.getLog(MuleClasspathConfigurationBuilder.class);
49
50 public static final String MULE_CONFIGURATION_RESOURCE = "mule-config.xml";
51
52 public MuleClasspathConfigurationBuilder() throws ConfigurationException
53 {
54 super();
55 }
56
57
58
59
60
61
62
63
64
65
66
67 public UMOManager configure(String configResources, String startupPropertiesFile)
68 throws ConfigurationException
69 {
70 if (StringUtils.isBlank(configResources))
71 {
72 configResources = MULE_CONFIGURATION_RESOURCE;
73 }
74
75 URL url = null;
76 List list = new ArrayList();
77 String[] resString;
78 int i = 0;
79
80 try
81 {
82 resString = StringUtils.splitAndTrim(configResources, ",");
83 for (i = 0; i < resString.length; i++)
84 {
85 url = Thread.currentThread().getContextClassLoader().getResource(resString[i]);
86 if (url == null) break;
87 list.add(new ReaderResource(url.toExternalForm(), new InputStreamReader(url.openStream())));
88 }
89 }
90 catch (IOException ioe)
91 {
92 throw new ConfigurationException(
93 CoreMessages.failedToLoad("Config: " + ObjectUtils.toString(url, "null")), ioe);
94 }
95
96 if (list.size() != resString.length)
97 {
98 throw new ConfigurationException(
99 CoreMessages.failedToLoad("Not all resources specified loaded: " + resString[i]));
100 }
101
102 ReaderResource[] resources = new ReaderResource[list.size()];
103 resources = (ReaderResource[])list.toArray(resources);
104 configure(resources, null);
105 return manager;
106 }
107 }