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