1 45 package org.exolab.jms.config; 46 47 import java.io.File ; 48 49 import org.exolab.castor.xml.MarshalException; 50 import org.exolab.castor.xml.Unmarshaller; 51 import org.exolab.castor.xml.ValidationException; 52 import org.exolab.jms.config.types.SchemeType; 53 54 55 64 public class ConfigurationManager { 65 66 69 private static Configuration _config = null; 70 71 78 public static synchronized void setConfig(String path) 79 throws FileDoesNotExistException, ConfigurationFileException { 80 File config = new File (path); 81 82 if (config.exists()) { 83 ConfigurationLoader loader = new ConfigurationLoader(); 84 try { 85 _config = loader.load(path); 86 } catch (Exception exception) { 87 throw new ConfigurationFileException( 88 "Error occured in " + path + " " + exception); 89 } 90 } else { 91 throw new FileDoesNotExistException( 92 "Configuration file " + path + " does not exist."); 93 } 94 } 95 96 101 public static synchronized void setConfig(Configuration config) { 102 if (config == null) { 103 throw new IllegalArgumentException ("Argument 'config' is null"); 104 } 105 _config = config; 106 } 107 108 115 public static synchronized Configuration getConfig() { 116 if (_config == null) { 117 throw new IllegalStateException ( 118 "Configuration manager has not been initialised"); 119 } 120 return _config; 121 } 122 123 133 public static Connector getConnector(SchemeType scheme) { 134 if (scheme == null) { 135 throw new IllegalArgumentException ("Argument scheme is null"); 136 } 137 Connector result = null; 138 Configuration config = getConfig(); 139 Connector[] connectors = config.getConnectors().getConnector(); 140 for (int i = 0; i < connectors.length; ++i) { 141 if (connectors[i].getScheme().equals(scheme)) { 142 result = connectors[i]; 143 break; 144 } 145 } 146 return result; 147 } 148 149 159 public static Connector getConnector() { 160 Configuration config = getConfig(); 161 return config.getConnectors().getConnector(0); 162 } 163 164 } 165 | Popular Tags |