1 package net.sf.tomp.xtcl.command;
2
3 import net.sf.tomp.xtcl.Context;
4
5 import org.apache.commons.logging.Log;
6 import org.apache.commons.logging.LogFactory;
7
8 /***
9 * Removes referenced objects (usually variables) from Context. If any
10 * referenced object is not found, terminates and returns 1; otherwise 0.
11 *
12 * @author tomp
13 */
14 public class Remove extends AbstractCommand {
15
16 private static final Log log = LogFactory.getLog(Remove.class);
17
18 /*** Array of names of objects to be removed. */
19 protected String[] removes;
20
21 /***
22 * set Array of names of objects to be removed.
23 *
24 * @param r
25 * Array of names of objects to be removed.
26 */
27 public void setRemoves(String[] r) {
28 removes = r;
29 }
30
31 /***
32 * Removes referenced objects (usually variables) from Context. If any
33 * referenced object is not found, terminates and returns 1; otherwise 0.
34 *
35 */
36 public int execute(Context context) throws Exception {
37 for (int i = 0; i < removes.length; i++) {
38 if (context.remove(removes[i]) == null) {
39 return done(context, 1);
40 }
41 }
42 return done(context, 0);
43 }
44
45 /***
46 * @return "REMOVE (" + listArray(removes) + ")";
47 */
48 public String toString() {
49 return "REMOVE (" + listArray(removes) + ")";
50 }
51 }
52
53
54
55
56
57
58
59
60
61
62