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
26 /**
27 * LOG call. Makes a log entry.
28 * <pre>
29 * REQURIES: logger, core
30 * IGNORES: uni
31 * PARAMETERS (INPUT):
32 * entry= text entry
33 * numeric= value (optional). Value between
34 * </pre>
35 * RETURNS: empty string.
36 *
37 * @author Erich P. Gatejen
38 * @version 1.0
39 * <i>Version History</i>
40 * <code>EPG - Initial - 25Apr03</code>
41 */
42 public class Call_LOG extends Call {
43
44 /**
45 * Implement this to handle load time initialization. The
46 * four main fields will already be set--vmc, sc, log, and u.
47 * You must implement this, but you don't have to do anything.
48 * Remember that calls are cached per VM and reused as often
49 * as possible. There will be no thread-safety issues with the
50 * VMCore or log, but the SystemContecxt and Universe may be shared.
51 * @throws CallException
52 */
53 public void load_chain() throws CallException {
54 // Nothing to do.
55 }
56
57 /**
58 * Implement this to return the name of the CALL
59 * @return name of the CALL
60 */
61 public String name() {
62 return "LOG";
63 }
64
65 /**
66 * Execute it.
67 * @return the result or null if there is no result
68 */
69 public String call() throws CallException {
70
71 try {
72 int numeric = CallException.CODE_INFORMATIONAL_OK;
73
74 String numString = this.optionalString("numeric");
75 if (numString != null) {
76 try {
77 numeric = Integer.parseInt(numString);
78 } catch (Exception ee) {
79 throw new CallException(
80 this.format(
81 "Numeric format is bad. String=" + numeric),
82 CallException.CODE_CALL_PROGRAM_ERROR);
83 }
84 }
85 // DO NOT USE Call SERVICE for this
86 log.info(((String) vmc.fetch("entry")), numeric);
87
88 } catch (CallException cce) {
89 throw cce;
90 } catch (Exception e) {
91 throw new CallException(
92 this.format(
93 "Exception while logging. error=" + e.getMessage()),
94 CallException.CODE_CALL_ERROR,
95 e);
96 }
97 return Constants.EMPTY_LEFT;
98 }
99
100 /**
101 * Execute using the passed universe, rather than the loaded.
102 * @param uni a universe
103 * @return the result or null if there is no result
104 * @see autohit.universe.Universe
105 */
106 public String call(Universe uni) throws CallException {
107 return this.call();
108 }
109 }
|