Source code for /engineering/autohit-2003/src/autohit/universe/UniverseProperties.javaOriginal file UniverseProperties.java
   1 /**
   2  * AUTOHIT 2003
   3  * Copyright Erich P Gatejen (c) 1989,1997,2003,2004
   4  * 
   5  * This program is free software; you can redistribute it and/or modify 
   6  * it under the terms of the GNU General Public License as published by 
   7  * the Free Software Foundation; either version 2 of the License, or (at
   8  * your option) any later version.
   9  * This program is distributed in the hope that it will be useful, but
  10  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12  * more details.
  13  * 
  14  * You should have received a copy of the GNU General Public License along
  15  * with this program; if not, write to the Free Software Foundation, Inc.,
  16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17  *
  18  * Additional license information can be found in the documentation.
  19  * @author Erich P Gatejen
  20  */
  21 package autohit.universe;
  22 
  23 import java.io.InputStream;
  24 
  25 import org.apache.commons.collections.ExtendedProperties;
  26 
  27 /**
  28 * Universe properties set.
  29 * 
  30 * There are four types of universes:
  31 *	UNI_LOCAL   	Local file system
  32 *	UNI_MASTER 		NOT IMPLIMENTED!
  33 *	UNI_MIRROR		NOT IMPLIMENTED!
  34 *	UNI_REMOTE		NOT IMPLIMENTED!
  35 *   UNI_EXTENDED	NOT IMPLIMENTED!
  36 *
  37 * Regardless of what kind of universe, there must be a local property file
  38 * that describes the universe.  The factory will use it to build a
  39 * server for that universe.
  40 *
  41 * PROPERTIES PROCESSED
  42 * name		: string name discriptor
  43 * type		: "local" only now
  44 *
  45 * @author Erich P. Gatejen
  46 * @version 1.0
  47 * <i>Version History</i>
  48 * <code>EPG - New - 23Apr03</code> 
  49 * 
  50 */
  51 public class UniverseProperties {
  52 
  53 	/**
  54 	 * Types of universe
  55 	 */
  56 	public static final int UNI_INVALID = 0;
  57 	public static final int UNI_LOCAL = 1;
  58 	public static final int UNI_MASTER = 2;
  59 	public static final int UNI_MIRROR = 3;
  60 	public static final int UNI_REMOTE = 4;
  61 	public static final int UNI_EXTENDED = 5;
  62 
  63 	/**
  64 	 * type of universe
  65 	 */
  66 	private int type;
  67 
  68 	/**
  69 	 * name of universe
  70 	 */
  71 	private String name;
  72 
  73 	/**
  74 	 * name of universe
  75 	 */
  76 	private String root;
  77 
  78 	/**
  79 	 * name of extended class
  80 	 */
  81 	private String extendedClass;
  82 
  83 	/**
  84 	 * The internal properties set
  85 	 */
  86 	private ExtendedProperties prop;
  87 
  88 	/**
  89 	 *  Constructor.  Do not allow this!
  90 	 */
  91 	public UniverseProperties() throws Exception {
  92 		throw new Exception("BAD PROGRAMMER!  Don't use me--ever.");
  93 	}
  94 
  95 	/**
  96 	 *  Constructor.  Build from a file.  We will propagate any exception.
  97 	 * @param propsPath path to properties file
  98 	 */
  99 	public UniverseProperties(String propsPath) throws Exception {
 100 		try {
 101 			prop = new ExtendedProperties(propsPath);
 102 			completeConstruction();
 103 		} catch (Exception e) {
 104 			// FUBAR.  kill the properties.
 105 			prop = null;
 106 			throw e;
 107 		}
 108 	}
 109 
 110 	/**
 111 	 *  Constructor.  Build from an input stream.  We will propagate any exception.
 112 	 * @param props input stream to the properties file
 113 	 */
 114 	public UniverseProperties(InputStream props) throws Exception {
 115 		try {
 116 			prop = new ExtendedProperties();
 117 			prop.load(props);
 118 			completeConstruction();
 119 		} catch (Exception e) {
 120 			// FUBAR
 121 			prop = null;
 122 			throw e;
 123 		}
 124 	}
 125 
 126 	/**
 127 	 *  Get type accessor
 128 	 * @return type
 129 	 */
 130 	public int getType() {
 131 		return type;
 132 	}
 133 
 134 	/**
 135 	 *  Get name accessor
 136 	 * @return type
 137 	 */
 138 	public String getName() {
 139 		return name;
 140 	}
 141 
 142 	/**
 143 	 *  Get root accessor
 144 	 * @return type
 145 	 */
 146 	public String getRoot() {
 147 		return root;
 148 	}
 149 
 150 	/**
 151 	 *  Get extended class
 152 	 * @return extended class string 
 153 	 */
 154 	public String getExtendedClass() {
 155 		return extendedClass;
 156 	}
 157 
 158 	/**
 159 	 *  Helper
 160 	 */
 161 	private void completeConstruction() throws Exception {
 162 		String temp;
 163 
 164 		// Process type
 165 		if (!prop.containsKey("type")) {
 166 			throw new UniverseException(
 167 				"type property missing",
 168 				UniverseException.UE_REQUIRED_PROPERTY_MISSING);
 169 		}
 170 		temp = prop.getString("type");
 171 		if (temp.startsWith("local")) {
 172 			type = UNI_LOCAL;
 173 		} else {
 174 			type = UNI_INVALID;
 175 			throw new UniverseException(
 176 				"type " + temp + " not supported in this version.",
 177 				UniverseException.UE_NOT_SUPPORTED);
 178 		}
 179 
 180 		// Process the name
 181 		if (!prop.containsKey("name")) {
 182 			throw new UniverseException(
 183 				"name property missing",
 184 				UniverseException.UE_REQUIRED_PROPERTY_MISSING);
 185 		}
 186 		name = prop.getString("name");
 187 
 188 		// Process the root
 189 		if (!prop.containsKey("root")) {
 190 			throw new UniverseException(
 191 				"root property missing",
 192 				UniverseException.UE_REQUIRED_PROPERTY_MISSING);
 193 		}
 194 		root = prop.getString("root");
 195 
 196 		// Process the root
 197 		if (!prop.containsKey("root")) {
 198 			throw new UniverseException(
 199 				"root property missing",
 200 				UniverseException.UE_REQUIRED_PROPERTY_MISSING);
 201 		}
 202 		root = prop.getString("root");
 203 	}
 204 
 205 }