Source code for /engineering/autohit-2003/src/autohit/server/BasicBootstrap.javaOriginal file BasicBootstrap.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.server;
  22 
  23 import org.apache.commons.collections.ExtendedProperties;
  24 
  25 import autohit.common.AutohitProperties;
  26 import autohit.common.Utils;
  27 import java.util.HashSet;
  28 import autohit.server.service.Service;
  29 import autohit.vm.VMProcess;
  30 
  31 /**
  32  * Bootstrap the System Context
  33  *
  34  * @author Erich P. Gatejen
  35  * @version 1.0
  36  * <i>Version History</i>
  37  * <code>EPG - Initial - 19Jul03</code> 
  38  */
  39 public class BasicBootstrap {
  40 
  41 	/**
  42 	 * System
  43 	 */
  44 	public SystemContext sc;
  45 
  46 	/**
  47 	 * Services loaded (as VMProcess')
  48 	 */
  49 	public HashSet services;
  50 
  51 	/**
  52 	 *  Default constructor. 
  53 	 */
  54 	public BasicBootstrap() throws Exception {
  55 		throw new Exception("Dont use the default constructor!");
  56 	}
  57 
  58 	/**
  59 	 * Properties constructor.  Give it a full path to the 
  60 	 * properties file.
  61 	 * @param rootProps path to properties for System Context
  62 	 */
  63 	public BasicBootstrap(String rootProps) throws Exception {
  64 
  65 		// Build the properties
  66 		ExtendedProperties ep = new ExtendedProperties(rootProps);
  67 
  68 		// Build a context
  69 		String logprop =
  70 			(String) Utils.testGetProperty(
  71 				AutohitProperties.BOOTSTRAP_CONTEXT_CLASS,
  72 				ep);
  73 		if (logprop == null) {
  74 			throw new Exception("SystemContext class for bootstrap not specified in properties.");
  75 		}
  76 		try {
  77 			Class t = Class.forName(logprop);
  78 			sc = (SystemContext) t.newInstance();
  79 		} catch (Exception ec) {
  80 			throw new Exception(
  81 				"Specified SystemContext class for bootstrap not found.  class name="
  82 					+ logprop
  83 					+ ".  message="
  84 					+ ec.getMessage());
  85 		}
  86 		sc.init(ep);
  87 		
  88 		// Services set
  89 		services = new HashSet();
  90 	}
  91 	
  92 	/**
  93 	 *  Run service
  94 	 */
  95 	public VMProcess runService(Service s) throws Exception {
  96 		
  97 		// build the process and unleash
  98 		VMProcess pcb = (sc.getKernel()).get();
  99 		pcb.execute(s);
 100 
 101 		services.add(pcb);
 102 
 103 		sc.getRootLogger().info("Service " + s.rootProgram +  " started with session name=" + s.sname);
 104 		
 105 		return pcb;
 106 	}
 107 	
 108 }