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:
13: Parse rows;
14:
15: boolean isSpecialName(String name) {
16: return name.equals("do") || name.equals("while");
17: }
18:
19: Method getAction(String name) throws SecurityException,
20: NoSuchMethodException {
21: String methodName = isSpecialName(name) ? ("action_" + name)
22: : name;
23: return getClass().getMethod(methodName, empty);
24: }
25:
26: public void doRows(Parse rows) {
27: this .rows = rows;
28: while (this .rows != null) {
29: doRow(this .rows);
30: this .rows = this .rows.more;
31: }
32: }
33:
34: public void doCells(Parse cells) {
35: this .cells = cells;
36: try {
37: Method action = getAction(cells.text());
38: action.invoke(this , empty);
39: } catch (Exception e) {
40: exception(cells, e);
41: }
42: }
43:
44: public void action_do() {
45: loopContexts.push(rows);
46: }
47:
48: public void action_while() throws Exception {
49: String methodName = cells.more.text();
50: Method action = actor.getClass().getMethod(methodName, empty);
51: Boolean result = (Boolean) action.invoke(actor, empty);
52: if (result.booleanValue()) {
53: rows = (Parse) loopContexts.peek();
54: } else {
55: loopContexts.pop();
56: }
57: }
58: }
|