Source code for /engineering/autohit-2003/src/autohit/call/Call_EVALSTRING.javaOriginal file Call_EVALSTRING.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 autohit.common.Constants;
  24 import autohit.universe.Universe;
  25 import autohit.vm.process.StringProcessors;
  26 
  27 /**
  28  * EVALSTRING call.  Run an eval on string.
  29  * <pre>
  30  * REQURIES: logger, core
  31  * IGNORES: uni
  32  * PARAMETERS (INPUT):
  33  	string= string to eval
  34  * </pre>
  35  * RETURNS: evaluated string.
  36  *
  37  * @author Erich P. Gatejen
  38  * @version 1.0
  39  * <i>Version History</i>
  40  * <code>EPG - Initial - 13SEP03</code>
  41  * 
  42  */
  43 public class Call_EVALSTRING 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 "EVALSTRING";
  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 result = Constants.EMPTY_LEFT;
  73 
  74 		try {
  75 
  76 			// Find the table object.  Make sure it is a Hashtable
  77 			String text = (String) this.desiredString("string");
  78 			if (text == null) {
  79 				this.debug("Empty string.");
  80 				return result;
  81 			}
  82 
  83 			result = StringProcessors.evalString2Core(text, vmc);
  84 
  85 		} catch (Exception e) {
  86 			throw new CallException(
  87 				this.format(
  88 					"Exception while trying to eval.  error=" + e.getMessage()),
  89 				CallException.CODE_CALL_ERROR,
  90 				e);
  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 }