Source code for /engineering/autohit-2003/src/autohit/call/Call_LOAD_UNI2STRING.javaOriginal file Call_LOAD_UNI2STRING.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.universe.UniverseException;
  26 import autohit.universe.UniverseUtils;
  27 
  28 /**
  29  * LOAD_UNI2STRING.  Load a universe object to a store string.
  30  * <pre>
  31  * REQURIES: logger, core
  32  * IGNORES: uni
  33  * PARAMETERS (INPUT):
  34  *	uniobj= universe object to load
  35  * </pre>
  36  * RETURNS: The string
  37  *
  38  * @author Erich P. Gatejen
  39  * @version 1.0
  40  * <i>Version History</i>
  41  * <code>EPG - Initial - 12Sep03</code>
  42  * 
  43  */
  44 public class Call_LOAD_UNI2STRING extends Call {
  45 
  46 	// total number of times to try and find a unique file.
  47 	public final static int MAX_TRIES = 5;
  48 
  49 	/**
  50 	 * Implement this to handle load time initialization.  The 
  51 	 * four main fields will already be set--vmc, sc, log, and u.
  52 	 * You must implement this, but you don't have to do anything.
  53 	 * Remember that calls are cached per VM and reused as often
  54 	 * as possible.  There will be no thread-safety issues with the
  55 	 * VMCore or log, but the SystemContecxt and Universe may be shared.
  56 	 * @throws CallException
  57 	 */
  58 	public void load_chain() throws CallException {
  59 		// Nothing to do.
  60 	}
  61 
  62 	/**
  63 	 * Implement this to return the name of the CALL
  64 	 * @return name of the CALL
  65 	 */
  66 	public String name() {
  67 		return "LOAD_UNI2STRING";
  68 	}
  69 
  70 	/**
  71 	 * Execute it.
  72 	 * @return the result or null if there is no result
  73 	 */
  74 	public String call() throws CallException {
  75 		return this.call(u);
  76 	}
  77 
  78 	/**
  79 	 * Execute using the passed universe, rather than the loaded.
  80 	 * @param uni a universe
  81 	 * @return the result or null if there is no result
  82 	 * @see autohit.universe.Universe
  83 	 */
  84 	public String call(Universe uni) throws CallException {
  85 		String result = Constants.EMPTY_LEFT;
  86 
  87 		try {
  88 
  89 			// Get the uniobj name
  90 			String name = (String) this.requiredString("uniobj");
  91 
  92 			// Load it
  93 			result = UniverseUtils.load2String(uni.getStream(name));
  94 
  95 		} catch (UniverseException ue) {
  96 			throw new CallException(
  97 				this.format(
  98 					"Failed with Universe exception.  message="
  99 						+ ue.getMessage()),
 100 				CallException.CODE_MODULE_FAULT,
 101 				ue);
 102 		} catch (CallException cce) {
 103 			throw cce;
 104 		} catch (Exception e) {
 105 			throw new CallException(
 106 				this.format(
 107 					"Exception while trying to load.  error=" + e.getMessage()),
 108 				CallException.CODE_CALL_ERROR,
 109 				e);
 110 		}
 111 		return result;
 112 	}
 113 }