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. INSERT_TABLE Inserts a name(n)/value(v) into a TABLE in persist. It will
30 * replace the name(n)/value(v) is the name alredy exists.
31 * <pre>
32 * REQURIES: logger, core
33 * IGNORES:
34 * PARAMETERS (INPUT):
35 * name= name of the table in which to insert. REQUIRED
36 * n= name of the table entry REQUIRED
37 * v= value of the table entry REQUIRED
38 * </pre>
39 * RETURNS: empty string.
40 *
41 * @author Erich P. Gatejen
42 * @version 1.0
43 * <i>Version History</i>
44 * <code>EPG - Initial - 28Jun03
45 *
46 */
47 public class Call_INSERT_TABLE extends Call {
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 "INSERT_TABLE";
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
76 String name = Constants.UNKNOWN;
77 Hashtable table;
78
79 try {
80
81 // Get the params and the table. Exceptions will handle problems
82 name = this.requiredString("name");
83 String n = this.requiredString("n");
84 String v = this.requiredString("v");
85 table = (Hashtable) this.requiredPersist(name, Hashtable.class);
86
87 // Insert it
88 table.put(n, v);
89
90 } catch (CallException e) {
91 // Trap the table errors.
92 if (e.numeric == CallException.CODE_CALL_PERSISTMISMATCH_FAULT) {
93 throw new CallException(
94 this.format(
95 "Persist object named "
96 + name
97 + " found, but it is not a TABLE."),
98 CallException.CODE_CALL_PERSISTMISMATCH_FAULT,
99 e);
100 } else if (
101 e.numeric == CallException.CODE_CALL_PERSISTNOTFOUND_FAULT) {
102 throw new CallException(
103 this.format("Table named " + name + " not found."),
104 CallException.CODE_CALL_PERSISTNOTFOUND_FAULT,
105 e);
106 }
107 throw e;
108 }
109 return Constants.EMPTY_LEFT;
110 }
111
112 /**
113 * Execute using the passed universe, rather than the loaded.
114 * @param uni a universe
115 * @return the result or null if there is no result
116 * @see autohit.universe.Universe
117 */
118 public String call(Universe uni) throws CallException {
119 return this.call();
120 }
121 }
|