01: /*
02: * Created on Feb 24, 2004
03: */
04: package net.sourceforge.orbroker;
05:
06: /**
07: * A column definition.
08: * @author Nils Kilden-Pedersen
09: */
10: final class Column extends ValueType {
11:
12: private static boolean isPositiveInteger(String column) {
13: for (int i = 0; i < column.length(); i++) {
14: if (column.charAt(i) < '0' || column.charAt(i) > '9') {
15: return false;
16: }
17: }
18: return true;
19: }
20:
21: private final String columnName;
22: private final int index;
23:
24: /**
25: * Constructor.
26: * @param columnName
27: * @param requiredClass
28: */
29: Column(String columnName, Class requiredClass) {
30: super (requiredClass);
31: String column;
32: int idx;
33: if (isPositiveInteger(columnName)) {
34: idx = Integer.parseInt(columnName);
35: column = null;
36: } else {
37: column = columnName;
38: idx = 0;
39: }
40: this .columnName = column;
41: this .index = idx;
42: }
43:
44: String getName() {
45: return this .columnName != null ? this .columnName : String
46: .valueOf(this .index);
47: }
48:
49: /**
50: * @throws ConfigurationException
51: * @see net.sourceforge.orbroker.ValueType#getValue(ResultRow)
52: */
53: Object getValue(ResultRow row) throws ConfigurationException {
54:
55: int columnIndex;
56: if (this .columnName == null) {
57: columnIndex = this .index;
58: } else {
59: columnIndex = row.findColumn(this .columnName);
60: }
61: return row.getColumnValue(columnIndex, this .getType());
62: }
63:
64: /**
65: * @see java.lang.Object#toString()
66: */
67: public String toString() {
68: return "Column " + this.columnName;
69: }
70: }
|