View Javadoc

1   package net.sf.tomp.xtcl.command;
2   
3   import net.sf.tomp.xtcl.Context;
4   
5   /***
6    * Returns from a function, giving the results back to parent (calling) Context
7    * 
8    * @author tomp
9    */
10  public class Ret extends AbstractCommand {
11  
12  	/*** variables to be returned (copied) to parent Context */
13  	protected String[] returns;
14  
15  	/***
16  	 * set variables to be returned (copied) to parent Context
17  	 * 
18  	 * @param r
19  	 *            variables to be returned (copied) to parent Context
20  	 */
21  	public void setReturns(String[] r) {
22  		returns = r;
23  	}
24  
25  	/***
26  	 * Returns from a function, giving the results back to parent (calling)
27  	 * Context under names $1 .. $n (for n-params)
28  	 * 
29  	 * @param c
30  	 *            DOCUMENT ME!
31  	 * @return DOCUMENT ME!
32  	 * @throws Exception
33  	 *             DOCUMENT ME!
34  	 */
35  	public int execute(Context c) throws Exception {
36  		Context prev = c.getPrevious();
37  
38  		for (int i = 0; i < returns.length; i++) {
39  			String k = returns[i];
40  			Object v = c.get(k);
41  
42  			prev.put("$" + (i + 1), v);
43  		}
44  		return done(c, 0);
45  	}
46  
47  	/***
48  	 * @return "RETURN (" + listArray(returns) + ")";
49  	 */
50  	public String toString() {
51  		return "RETURN (" + listArray(returns) + ")";
52  	}
53  }
54  
55  /*
56   * The contents of this file are subject to the Mozilla Public License Version
57   * 1.1 (the "License"); you may not use this file except in compliance with the
58   * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
59   * Software distributed under the License is distributed on an "AS IS" basis,
60   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
61   * the specific language governing rights and limitations under the License. The
62   * Original Code is: all this file. The Initial Developer of the Original Code
63   * is: Tomas Pitner, Masaryk University in Brno, Czech Republic. Contributor(s):
64   */