Source code for /engineering/autohit-2003/src/autohit/call/Call_DELETE_TABLE.javaOriginal file Call_DELETE_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.  DELETE_TABLE  Delete an entry from a TABLE in persist.
  30  * <pre>
  31  * REQURIES: logger, core
  32  * IGNORES: uni
  33  * PARAMETERS (INPUT):
  34  * name= table name
  35  * n= entry name
  36  * </pre>
  37  * RETURNS: defined by the method, but will always be a String.
  38  *
  39  * @author Erich P. Gatejen
  40  * @version 1.0
  41  * <i>Version History</i>
  42  * <code>EPG - Initial - 30Jun03</code>
  43  */
  44 public class Call_DELETE_TABLE extends Call {
  45 
  46 	/**
  47 	 * Implement this to handle load time initialization.  The 
  48 	 * four main fields will already be set--vmc, sc, log, and u.
  49 	 * You must implement this, but you don't have to do anything.
  50 	 * Remember that calls are cached per VM and reused as often
  51 	 * as possible.  There will be no thread-safety issues with the
  52 	 * VMCore or log, but the SystemContecxt and Universe may be shared.
  53 	 * @throws CallException
  54 	 */
  55 	public void load_chain() throws CallException {
  56 		// do nothing
  57 	}
  58 
  59 	/**
  60 	 * Implement this to return the name of the CALL
  61 	 * @return name of the CALL
  62 	 */
  63 	public String name() {
  64 		return "DELETE_TABLE";
  65 	}
  66 
  67 	/**
  68 	 * Execute it.
  69 	 * @return the result or null if there is no result
  70 	 */
  71 	public String call() throws CallException {
  72 
  73 		String name = Constants.UNKNOWN;
  74 		String n;
  75 		Hashtable table;
  76 
  77 		try {
  78 
  79 			// Get the params and the table.  Exceptions will handle problems
  80 			name = (String) this.requiredString("name");
  81 			n = (String) this.requiredString("n");
  82 			table = (Hashtable) this.requiredPersist(name, Hashtable.class);
  83 
  84 			if (table.containsKey(n)) {
  85 				table.remove(n);
  86 			} else {
  87 				throw new CallException(
  88 					this.format("Entry " + n + " not found in table " + name),
  89 					CallException.CODE_CALL_ERROR);
  90 			}
  91 
  92 		} catch (CallException e) {
  93 			// Trap the table errors.
  94 			if (e.numeric == CallException.CODE_CALL_PERSISTMISMATCH_FAULT) {
  95 				throw new CallException(
  96 					this.format(
  97 						"Persist object named "
  98 							+ name
  99 							+ " found, but it is not a TABLE."),
 100 					CallException.CODE_CALL_PERSISTMISMATCH_FAULT,
 101 					e);
 102 			} else if (
 103 				e.numeric == CallException.CODE_CALL_PERSISTNOTFOUND_FAULT) {
 104 				throw new CallException(
 105 					this.format("Table named " + name + " not found."),
 106 					CallException.CODE_CALL_PERSISTNOTFOUND_FAULT,
 107 					e);
 108 			}
 109 			throw e;
 110 
 111 		} catch (Exception e) {
 112 			throw new CallException(
 113 				this.format(
 114 					"Exception while removing table.  error=" + e.getMessage()),
 115 				CallException.CODE_CALL_FAULT,
 116 				e);
 117 		}
 118 		return Constants.EMPTY_LEFT;
 119 	}
 120 
 121 	/**
 122 	 * Execute using the passed universe, rather than the loaded.
 123 	 * @param uni a universe
 124 	 * @return the result or null if there is no result
 125 	 * @see autohit.universe.Universe
 126 	 */
 127 	public String call(Universe uni) throws CallException {
 128 		return this.call();
 129 	}
 130 }