1 10 11 package org.mule.config.builders; 12 13 import java.io.IOException ; 14 import java.io.InputStreamReader ; 15 import java.net.URL ; 16 import java.util.ArrayList ; 17 import java.util.List ; 18 19 import org.apache.commons.lang.ObjectUtils; 20 import org.apache.commons.logging.Log; 21 import org.apache.commons.logging.LogFactory; 22 import org.mule.config.ConfigurationException; 23 import org.mule.config.ReaderResource; 24 import org.mule.config.i18n.Message; 25 import org.mule.config.i18n.Messages; 26 import org.mule.umo.manager.UMOManager; 27 import org.mule.util.StringUtils; 28 29 45 public class MuleClasspathConfigurationBuilder extends MuleXmlConfigurationBuilder 46 { 47 50 protected static Log logger = LogFactory.getLog(MuleClasspathConfigurationBuilder.class); 51 52 public static final String MULE_CONFIGURATION_RESOURCE = "mule-config.xml"; 53 54 public MuleClasspathConfigurationBuilder() throws ConfigurationException 55 { 56 super(); 57 } 58 59 69 public UMOManager configure(String configResources, String startupPropertiesFile) 70 throws ConfigurationException 71 { 72 if (StringUtils.isBlank(configResources)) 73 { 74 configResources = MULE_CONFIGURATION_RESOURCE; 75 } 76 77 URL url = null; 78 List list = new ArrayList (); 79 String [] resString; 80 int i = 0; 81 82 try 83 { 84 resString = StringUtils.splitAndTrim(configResources, ","); 85 for (i = 0; i < resString.length; i++) 86 { 87 url = Thread.currentThread().getContextClassLoader().getResource(resString[i]); 88 if (url == null) break; 89 list.add(new ReaderResource(url.toExternalForm(), new InputStreamReader (url.openStream()))); 90 } 91 } 92 catch (IOException ioe) 93 { 94 throw new ConfigurationException(new Message(Messages.FAILED_LOAD_X, "Config: " 95 + ObjectUtils.toString(url, 96 "null")), ioe); 97 } 98 99 if (list.size() != resString.length) 100 { 101 throw new ConfigurationException(new Message(Messages.FAILED_LOAD_X, 102 "Not all resources specified loaded: " + resString[i])); 103 } 104 105 ReaderResource[] resources = new ReaderResource[list.size()]; 106 resources = (ReaderResource[])list.toArray(resources); 107 configure(resources, null); 108 return manager; 109 } 110 } 111 | Popular Tags |