1 package net.sf.tomp.xtcl.command;
2
3 import net.sf.tomp.xtcl.Command;
4 import net.sf.tomp.xtcl.Context;
5
6 /***
7 * Function command
8 *
9 * @author tomp
10 */
11 public class Function extends AbstractCommand {
12
13 /*** Function name */
14 protected String name;
15
16 /*** Function formal param names */
17 protected String[] params;
18
19 /*** the command itself */
20 protected Command command;
21
22 /***
23 * execute the function command means execute its command
24 *
25 * @param context
26 * @return
27 * @throws Exception
28 */
29 public int execute(Context context) throws Exception {
30 return command.execute(context);
31 }
32
33 /***
34 * sets the function name
35 *
36 * @param p the function name
37 */
38 public void setName(String p) {
39 name = p;
40 }
41
42 /***
43 * sets the function's parameter names
44 *
45 * @param p the function's parameter names
46 */
47 public void setParams(String[] p) {
48 params = p;
49 }
50
51 /***
52 * sets the command representing the function
53 *
54 * @param c the command
55 */
56 public void setCommand(Command c) {
57 command = c;
58 }
59
60 /***
61 * Get the i-th formal param name
62 *
63 * @param i formal param index
64 * @return the i-th formal param name
65 */
66 public String getParam(int i) {
67 return params[i];
68 }
69
70 /***
71 *
72 * @return "FUNCTION " + name + " (" + listArray(params) + ") {" + command
73 + "}";
74 */
75 public String toString() {
76 return "FUNCTION " + name + " (" + listArray(params) + ") {" + command
77 + "}";
78 }
79 /***
80 * @return Returns the name.
81 */
82 public String getName() {
83 return name;
84 }
85 }
86
87
88
89
90
91
92
93
94
95
96