1 18 package sync4j.framework.config; 19 20 import java.io.File ; 21 import java.io.IOException ; 22 import java.net.URL ; 23 import java.net.MalformedURLException ; 24 25 import sync4j.framework.config.ConfigurationException; 26 import sync4j.framework.tools.beans.BeanFactory; 27 28 import org.apache.commons.lang.StringUtils; 29 30 36 public class ConfigTools { 37 49 public static Object getBeanInstance(ClassLoader configLoader, String name) 50 throws ConfigurationException { 51 try { 52 return BeanFactory.getBeanInstance(configLoader, name); 53 } catch (Exception e) { 54 throw new ConfigurationException( "Error in creating an instance of " 55 + name 56 , e ); 57 } 58 } 59 60 69 public static Object [] getBeanArray(ClassLoader configLoader, String names, char separator) 70 throws ConfigurationException { 71 String [] values = StringUtils.split(names, String.valueOf(separator)); 72 73 Object [] ret = new Object [values.length]; 74 75 int i = 0; 76 try { 77 for (; i<ret.length; ++i) { 78 ret[i] = BeanFactory.getBeanInstance(configLoader, values[i]); 79 } 80 } catch (Exception e) { 81 throw new ConfigurationException ( "Error in creating the bean " 82 + values[i] 83 , e ); 84 } 85 86 return ret; 87 } 88 89 102 public static URL fixURL(final String s) 103 throws MalformedURLException { 104 105 try { 106 return new URL (s); 107 } catch (MalformedURLException e) { 108 } 112 113 try { 114 return new File (new File (s).getCanonicalPath()).toURL(); 115 } catch (IOException e) { 116 throw new MalformedURLException ("Unable to convert" + s + " to a URL"); 117 } 118 } 119 120 } 121 | Popular Tags |