Source code for /engineering/autohit-2003/src/autohit/call/Call_NEW_TABLE.javaOriginal file Call_NEW_TABLE.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 java.util.Hashtable;
  24 
  25 import autohit.common.Constants;
  26 import autohit.universe.Universe;
  27 
  28 /**
  29  * CALL.  NEW_TABLE  Creates a table in persist.  The table is implemented as hashtable.
  30  * <pre>
  31  * REQURIES: logger, core
  32  * IGNORES: 
  33  * PARAMETERS (INPUT):
  34  * name= name to give the table.  Must be unique to the persist.  REQUIRED
  35  * </pre>
  36  * RETURNS: empty string.
  37  *
  38  * @author Erich P. Gatejen
  39  * @version 1.0
  40  * <i>Version History</i>
  41  * <code>EPG - Initial - 28Jun03</code>
  42  */
  43 public class Call_NEW_TABLE 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 "NEW_TABLE";
  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 		Hashtable table;
  74 
  75 		try {
  76 			// see if the parameter is passed
  77 			name = this.requiredString("name");
  78 
  79 			// check for duplicates
  80 			name = (String) vmc.fetch("name");
  81 			if (vmc.has(name)) {
  82 				this.debug(
  83 					"Table named "
  84 						+ name
  85 						+ " already exists in persist.  New instance NOT created.");
  86 			} else {
  87 				table = new Hashtable();
  88 				vmc.persist(name, table);
  89 				this.debug("Created a table named=" + name);
  90 			}
  91 
  92 		} catch (CallException ce) {
  93 			throw ce;
  94 		} catch (Exception e) {
  95 			throw new CallException(
  96 				this.format(
  97 					"Exception while creating instance.  error="
  98 						+ e.getMessage()),
  99 				CallException.CODE_CALL_FAULT,
 100 				e);
 101 		}
 102 		return Constants.EMPTY_LEFT;
 103 	}
 104 
 105 	/**
 106 	 * Execute using the passed universe, rather than the loaded.
 107 	 * @param uni a universe
 108 	 * @return the result or null if there is no result
 109 	 * @see autohit.universe.Universe
 110 	 */
 111 	public String call(Universe uni) throws CallException {
 112 		return this.call();
 113 	}
 114 
 115 }