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 fit;
04:
05: // Copyright (c) 2002 Cunningham & Cunningham, Inc.
06: // Released under the terms of the GNU General Public License version 2 or later.
07:
08: public class ColumnFixture extends Fixture {
09:
10: protected Binding columnBindings[];
11:
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: String name = heads.text();
73: columnBindings[i] = Binding.create(this , name);
74: }
75: } catch (Throwable throwable) {
76: exception(heads, throwable);
77: }
78: }
79:
80: }
|