01: // Modified or written by Object Mentor, Inc. for inclusion with FitNesse.
02: // Copyright (c) 2002 Cunningham & Cunningham, Inc.
03: // Released under the terms of the GNU General Public License version 2 or later.
04: package fit;
05:
06: // Copyright (c) 2002 Cunningham & Cunningham, Inc.
07: // Released under the terms of the GNU General Public License version 2 or later.
08:
09: public class ColumnFixture extends Fixture {
10:
11: protected Binding columnBindings[];
12: protected boolean hasExecuted = false;
13:
14: // Traversal ////////////////////////////////
15:
16: public void doRows(Parse rows) {
17: bind(rows.parts);
18: super .doRows(rows.more);
19: }
20:
21: public void doRow(Parse row) {
22: hasExecuted = false;
23: try {
24: reset();
25: super .doRow(row);
26: if (!hasExecuted) {
27: execute();
28: }
29: } catch (Exception e) {
30: exception(row.leaf(), e);
31: }
32: }
33:
34: public void doCell(Parse cell, int column) {
35: try {
36: columnBindings[column].doCell(this , cell);
37: } catch (Throwable e) {
38: exception(cell, e);
39: }
40: }
41:
42: public void check(Parse cell, TypeAdapter a) {
43: try {
44: executeIfNeeded();
45: } catch (Exception e) {
46: exception(cell, e);
47: }
48: super .check(cell, a);
49: }
50:
51: protected void executeIfNeeded() throws Exception {
52: if (!hasExecuted) {
53: hasExecuted = true;
54: execute();
55: }
56: }
57:
58: public void reset() throws Exception {
59: // about to process first cell of row
60: }
61:
62: public void execute() throws Exception {
63: // about to process first method call of row
64: }
65:
66: // Utility //////////////////////////////////
67:
68: protected void bind(Parse heads) {
69: try {
70: columnBindings = new Binding[heads.size()];
71: for (int i = 0; heads != null; i++, heads = heads.more) {
72: columnBindings[i] = createBinding(i, heads);
73: }
74: } catch (Throwable throwable) {
75: exception(heads, throwable);
76: }
77: }
78:
79: protected Binding createBinding(int column, Parse heads)
80: throws Throwable {
81: return Binding.create(this, heads.text());
82: }
83:
84: }
|