1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.config; |
12 | |
|
13 | |
import org.mule.MuleManager; |
14 | |
import org.mule.util.IOUtils; |
15 | |
import org.mule.util.StringUtils; |
16 | |
|
17 | |
import java.io.IOException; |
18 | |
import java.io.InputStream; |
19 | |
import java.io.InputStreamReader; |
20 | |
import java.io.Reader; |
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
public class ReaderResource |
28 | |
{ |
29 | |
|
30 | |
private String description; |
31 | |
private Reader reader; |
32 | |
|
33 | |
public ReaderResource(String description, Reader reader) |
34 | 0 | { |
35 | 0 | this.description = description; |
36 | 0 | this.reader = reader; |
37 | 0 | } |
38 | |
|
39 | |
public String getDescription() |
40 | |
{ |
41 | 0 | return description; |
42 | |
} |
43 | |
|
44 | |
public Reader getReader() |
45 | |
{ |
46 | 0 | return reader; |
47 | |
} |
48 | |
|
49 | |
public static ReaderResource[] parseResources(String configResources, String encoding) throws IOException |
50 | |
{ |
51 | 0 | String[] resources = StringUtils.splitAndTrim(configResources, ","); |
52 | 0 | MuleManager.getConfiguration().setConfigResources(resources); |
53 | 0 | ReaderResource[] readers = new ReaderResource[resources.length]; |
54 | 0 | for (int i = 0; i < resources.length; i++) |
55 | |
{ |
56 | 0 | InputStream is = IOUtils.getResourceAsStream(resources[i].trim(), ReaderResource.class); |
57 | 0 | if (is == null) |
58 | |
{ |
59 | 0 | throw new IOException("could not load resource: " + resources[i].trim()); |
60 | |
} |
61 | 0 | readers[i] = new ReaderResource(resources[i].trim(), new InputStreamReader(is, encoding)); |
62 | |
} |
63 | 0 | return readers; |
64 | |
} |
65 | |
|
66 | |
public static ReaderResource[] parseResources(String configResources) throws IOException |
67 | |
{ |
68 | 0 | return parseResources(configResources, MuleManager.getConfiguration().getEncoding()); |
69 | |
} |
70 | |
} |