View Javadoc

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   * The contents of this file are subject to the Mozilla Public License Version
89   * 1.1 (the "License"); you may not use this file except in compliance with the
90   * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
91   * Software distributed under the License is distributed on an "AS IS" basis,
92   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
93   * the specific language governing rights and limitations under the License. The
94   * Original Code is: all this file. The Initial Developer of the Original Code
95   * is: Tomas Pitner, Masaryk University in Brno, Czech Republic. Contributor(s):
96   */