1 /*** 2 * Redistribution and use of this software and associated documentation 3 * ("Software"), with or without modification, are permitted provided 4 * that the following conditions are met: 5 * 6 * 1. Redistributions of source code must retain copyright 7 * statements and notices. Redistributions must also contain a 8 * copy of this document. 9 * 10 * 2. Redistributions in binary form must reproduce the 11 * above copyright notice, this list of conditions and the 12 * following disclaimer in the documentation and/or other 13 * materials provided with the distribution. 14 * 15 * 3. The name "Exolab" must not be used to endorse or promote 16 * products derived from this Software without prior written 17 * permission of Exoffice Technologies. For written permission, 18 * please contact info@exolab.org. 19 * 20 * 4. Products derived from this Software may not be called "Exolab" 21 * nor may "Exolab" appear in their names without prior written 22 * permission of Exoffice Technologies. Exolab is a registered 23 * trademark of Exoffice Technologies. 24 * 25 * 5. Due credit should be given to the Exolab Project 26 * (http://www.exolab.org/). 27 * 28 * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS 29 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT 30 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 31 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 32 * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 33 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 39 * OF THE POSSIBILITY OF SUCH DAMAGE. 40 * 41 * Copyright 2000-2004 (C) Exoffice Technologies Inc. All Rights Reserved. 42 * 43 * $Id: ConfigurationManager.java,v 1.2 2005/08/30 05:07:11 tanderson Exp $ 44 */ 45 package org.exolab.jms.config; 46 47 import java.io.File; 48 49 import org.exolab.jms.config.types.SchemeType; 50 51 52 /*** 53 * The ConfigurationManager manages provides class methods for setting and 54 * getting the configuration file. It should be set by the application main line 55 * through {@link #setConfig} and subsequently accessed by other components 56 * through {@link #getConfig}. 57 * 58 * @author <a href="mailto:jima@comware.com.au">Jim Alateras</a> 59 * @version $Revision: 1.2 $ $Date: 2005/08/30 05:07:11 $ 60 * @deprecated no replacement 61 */ 62 public class ConfigurationManager { 63 64 /*** 65 * The loaded configuration 66 */ 67 private static Configuration _config = null; 68 69 /*** 70 * Load the configuration file 71 * 72 * @param path xml config file conforming to openjms.xsd schema 73 * @throws FileDoesNotExistException if the file does not exist 74 * @throws ConfigurationFileException if the file is not well-formed 75 */ 76 public static synchronized void setConfig(String path) 77 throws FileDoesNotExistException, ConfigurationFileException { 78 File config = new File(path); 79 80 if (config.exists()) { 81 ConfigurationLoader loader = new ConfigurationLoader(); 82 try { 83 _config = loader.load(path); 84 } catch (Exception exception) { 85 throw new ConfigurationFileException( 86 "Error occured in " + path + " " + exception); 87 } 88 } else { 89 throw new FileDoesNotExistException( 90 "Configuration file " + path + " does not exist."); 91 } 92 } 93 94 /*** 95 * Set the configuration 96 * 97 * @param config the configuration 98 */ 99 public static synchronized void setConfig(Configuration config) { 100 if (config == null) { 101 throw new IllegalArgumentException("Argument 'config' is null"); 102 } 103 _config = config; 104 } 105 106 /*** 107 * Returns the configuration 108 * 109 * @return the configuration 110 * @throws IllegalStateException if the configuration has not been 111 * initialised 112 */ 113 public static synchronized Configuration getConfig() { 114 if (_config == null) { 115 throw new IllegalStateException( 116 "Configuration manager has not been initialised"); 117 } 118 return _config; 119 } 120 121 /*** 122 * Returns the connector configuration for the supplied scheme 123 * 124 * @param scheme the connector scheme 125 * @return the connector configuration for the supplied scheme, or null, if 126 * no configuration exists 127 * @throws IllegalArgumentException if scheme is null 128 * @throws IllegalStateException if the configuration is not initialised 129 * @deprecated 130 */ 131 public static Connector getConnector(SchemeType scheme) { 132 if (scheme == null) { 133 throw new IllegalArgumentException("Argument scheme is null"); 134 } 135 Connector result = null; 136 Configuration config = getConfig(); 137 Connector[] connectors = config.getConnectors().getConnector(); 138 for (int i = 0; i < connectors.length; ++i) { 139 if (connectors[i].getScheme().equals(scheme)) { 140 result = connectors[i]; 141 break; 142 } 143 } 144 return result; 145 } 146 147 /*** 148 * Returns the default connector. This is the first configured connector in 149 * the configuration. 150 * 151 * @return the default connector 152 * @throws IllegalStateException if the configuration is not initialised 153 * @see #getConnector(SchemeType) 154 * @deprecated This method relies on users knowing that the first connector 155 * is the one that will be used. 156 */ 157 public static Connector getConnector() { 158 Configuration config = getConfig(); 159 return config.getConnectors().getConnector(0); 160 } 161 162 }