1 10 11 package org.mule.extras.spring.config; 12 13 import java.io.IOException ; 14 import java.util.Properties ; 15 16 import org.mule.MuleManager; 17 import org.mule.config.ConfigurationBuilder; 18 import org.mule.config.ConfigurationException; 19 import org.mule.config.MuleProperties; 20 import org.mule.config.ReaderResource; 21 import org.mule.config.i18n.Message; 22 import org.mule.config.i18n.Messages; 23 import org.mule.umo.UMOException; 24 import org.mule.umo.manager.UMOManager; 25 import org.mule.util.PropertiesUtils; 26 import org.mule.util.StringUtils; 27 28 37 public class SpringConfigurationBuilder implements ConfigurationBuilder 38 { 39 47 public UMOManager configure(ReaderResource[] configResources) throws ConfigurationException 48 { 49 return configure(configResources, null); 51 } 52 53 61 public UMOManager configure(ReaderResource[] configResources, Properties startupProperties) 62 throws ConfigurationException 63 { 64 throw new UnsupportedOperationException ("Not implemented"); 65 } 66 67 public UMOManager configure(String configResources) throws ConfigurationException 68 { 69 return configure(configResources, null); 70 } 71 72 public UMOManager configure(String configResource, String startupPropertiesFile) 73 throws ConfigurationException 74 { 75 if (StringUtils.isNotBlank(startupPropertiesFile)) 77 { 78 try 79 { 80 startupPropertiesFile = StringUtils.trimToEmpty(startupPropertiesFile); 81 Properties startupProperties = PropertiesUtils.loadProperties(startupPropertiesFile, 82 getClass()); 83 ((MuleManager)MuleManager.getInstance()).addProperties(startupProperties); 84 } 85 catch (IOException e) 86 { 87 throw new ConfigurationException(new Message(Messages.FAILED_TO_START_X, 88 "Mule server from builder"), e); 89 } 90 } 91 92 if (configResource == null) 93 { 94 throw new ConfigurationException(new Message(Messages.X_IS_NULL, "Configuration Resource")); 95 } 96 String [] resources = org.springframework.util.StringUtils.tokenizeToStringArray(configResource, ",;", 97 true, true); 98 99 MuleManager.getConfiguration().setConfigResources(resources); 100 new MuleApplicationContext(resources); 101 try 102 { 103 if (System.getProperty(MuleProperties.MULE_START_AFTER_CONFIG_SYSTEM_PROPERTY, "true") 104 .equalsIgnoreCase("true")) 105 { 106 MuleManager.getInstance().start(); 107 } 108 } 109 catch (UMOException e) 110 { 111 throw new ConfigurationException(new Message(Messages.FAILED_TO_START_X, 112 "Mule server from builder"), e); 113 } 114 return MuleManager.getInstance(); 115 } 116 117 122 public boolean isConfigured() 123 { 124 return MuleManager.isInstanciated(); 125 } 126 } 127 | Popular Tags |