View Javadoc

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