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
27 /**
28 * LOAD_UNISIZE. Report the size of a universe object. It'll report 0 if the object is empty, doens't exist, or there is a universe error.
29 * <pre>
30 * REQURIES: logger, core
31 * IGNORES: uni
32 * PARAMETERS (INPUT):
33 * uniobj= universe object to size
34 * </pre>
35 * RETURNS: The string
36 *
37 * @author Erich P. Gatejen
38 * @version 1.0
39 * <i>Version History</i>
40 * <code>EPG - Initial - 12Sep03</code>
41 *
42 */
43 public class Call_UNISIZE extends Call {
44
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 // Nothing to do.
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 "LOAD_UNISIZE";
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 return this.call(u);
73 }
74
75 /**
76 * Execute using the passed universe, rather than the loaded.
77 * @param uni a universe
78 * @return the result or '0' if there is no result or an onject error
79 * @see autohit.universe.Universe
80 */
81 public String call(Universe uni) throws CallException {
82 String result = Constants.EMPTY_LEFT;
83
84 try {
85
86 // Get the uniobj name
87 String name = (String) this.requiredString("uniobj");
88
89 // Load it
90 result = Long.toString(uni.size(name));
91
92 } catch (UniverseException ue) {
93 // Assume it isn't there
94 result = "0";
95
96 } catch (CallException cce) {
97 throw cce;
98 } catch (Exception e) {
99 // Assume it isn't there
100 result = "0";
101 }
102 return result;
103 }
104 }
|