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.call.modules.Module;
24 import autohit.common.Constants;
25 import autohit.universe.Universe;
26
27 /**
28 * FREE. Frees a module instance.
29 * <pre>
30 * REQURIES: logger, core
31 * IGNORES: uni
32 * PARAMETERS (INPUT):
33 name= name of the module to free
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 - 22Jun03</code>
41 */
42 public class Call_FREE 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 "FREE";
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 String name;
71
72 try {
73
74 name = this.requiredString("name");
75 log.debug("call:FREE.: Going to free= " + name);
76
77 // Even if the Module.free() causes an exception, at least remove it
78 // from the persist
79 // DO NOT USE THE Call.class requiredPersist!!!
80 if (vmc.has(name)) {
81 Module mod = (Module) vmc.get(name);
82 try {
83 mod.free();
84 } catch (Exception e) {
85 throw e;
86 } finally {
87 vmc.free(name);
88 }
89
90 } else {
91 // if it doesn't exist, that's a problem
92 throw new CallException(
93 this.format("Instance of " + name + " doesn't exist."),
94 CallException.CODE_CALL_ERROR);
95 }
96
97 } catch (CallException ce) {
98 throw ce;
99 } catch (Exception ex) {
100 //any other is REAL bad
101 throw new CallException(
102 this.format("Serious fault. error=" + ex.getMessage()),
103 CallException.CODE_CALL_UNRECOVERABLE_FAULT,
104 ex);
105 }
106 return Constants.EMPTY_LEFT;
107 }
108
109 /**
110 * Execute using the passed universe, rather than the loaded.
111 * @param uni a universe
112 * @return the result or null if there is no result
113 * @see autohit.universe.Universe
114 */
115 public String call(Universe uni) throws CallException {
116 return this.call();
117 }
118 }
|