01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.fixtures;
04:
05: import java.lang.reflect.*;
06: import java.util.Stack;
07: import fit.*;
08:
09: public class LoopingActionFixture extends ActionFixture {
10:
11: Stack loopContexts = new Stack();
12: Parse rows;
13:
14: boolean isSpecialName(String name) {
15: return name.equals("do") || name.equals("while");
16: }
17:
18: Method getAction(String name) throws SecurityException,
19: NoSuchMethodException {
20: String methodName = isSpecialName(name) ? ("action_" + name)
21: : name;
22: return getClass().getMethod(methodName, empty);
23: }
24:
25: public void doRows(Parse rows) {
26: this .rows = rows;
27: while (this .rows != null) {
28: doRow(this .rows);
29: this .rows = this .rows.more;
30: }
31: }
32:
33: public void doCells(Parse cells) {
34: this .cells = cells;
35: try {
36: Method action = getAction(cells.text());
37: action.invoke(this );
38: } catch (Exception e) {
39: exception(cells, e);
40: }
41: }
42:
43: public void action_do() {
44: loopContexts.push(rows);
45: }
46:
47: public void action_while() throws Exception {
48: String methodName = cells.more.text();
49: Method action = actor.getClass().getMethod(methodName);
50: Boolean result = (Boolean) action.invoke(actor);
51: if (result.booleanValue()) {
52: rows = (Parse) loopContexts.peek();
53: } else {
54: loopContexts.pop();
55: }
56: }
57: }
|