Source code for /engineering/autohit-2003/src/autohit/call/Call_GET_SPROP.javaOriginal file Call_GET_SPROP.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.call;
  22 
  23 import org.apache.commons.collections.ExtendedProperties;
  24 
  25 import autohit.common.Constants;
  26 import autohit.universe.Universe;
  27 
  28 /**
  29  * GET_SPROP call.Returns a system property.If there is no system
  30  * property with the passed name, then return an empty string.
  31  * <pre> 
  32  * REQURIES : logger, core,	sc 
  33  * IGNORES : uni 
  34  * PARAMETERS(INPUT) : 
  35  * name = name of entry 
  36  * </pre>
  37  *
  38  * @author Erich P. Gatejen
  39  * @version 1.0
  40  * <i>Version History</i>
  41  * <code>EPG - Initial - 5Aug03</code>
  42  */
  43 public class Call_GET_SPROP extends Call {
  44 
  45 	/**
  46 	 * Implement this to handle load time initialization.  The 
  47 	 * four main fields will already be set--vmc, sc, log, and u.
  48 	 * You must implement this, but you don't have to do anything.
  49 	 * Remember that calls are cached per VM and reused as often
  50 	 * as possible.  There will be no thread-safety issues with the
  51 	 * VMCore or log, but the SystemContecxt and Universe may be shared.
  52 	 * @throws CallException
  53 	 */
  54 	public void load_chain() throws CallException {
  55 		// Nothing to do.
  56 	}
  57 
  58 	/**
  59 	 * Implement this to return the name of the CALL
  60 	 * @return name of the CALL
  61 	 */
  62 	public String name() {
  63 		return "GET_SPROP";
  64 	}
  65 
  66 	/**
  67 	 * Execute it.
  68 	 * @return the result or null if there is no result
  69 	 */
  70 	public String call() throws CallException {
  71 
  72 		String name;
  73 		String result = Constants.EMPTY_LEFT;
  74 
  75 		try {
  76 			
  77 			name = this.requiredString("name");
  78 			ExtendedProperties ep = sc.getPropertiesSet();
  79 			if (ep.containsKey(name)) {
  80 				result = ep.getString(name);
  81 			}
  82 
  83 		} catch (CallException e) {
  84 			throw e;
  85 		} catch (Exception ex) {
  86 			//any other is REAL bad
  87 			throw new CallException(
  88 				this.format("Serious fault.  error=" + ex.getMessage()),
  89 				CallException.CODE_CALL_UNRECOVERABLE_FAULT,
  90 				ex);
  91 		}
  92 		return result;
  93 	}
  94 
  95 	/**
  96 	 * Execute using the passed universe, rather than the loaded.
  97 	 * @param uni a universe
  98 	 * @return the result or null if there is no result
  99 	 * @see autohit.universe.Universe
 100 	 */
 101 	public String call(Universe uni) throws CallException {
 102 		return this.call();
 103 	}
 104 }