001: package net.xoetrope.optional.data.sql;
002:
003: import net.xoetrope.xui.data.XModel;
004:
005: /**
006: * A model node wrapping a database field value.
007: * <p>Copyright (c) Xoetrope Ltd. 2001-2003</p>
008: * $Revision: 1.1 $
009: */
010: public class DatabaseFieldModel extends XModel {
011: protected int rowIdx;
012: protected int fieldIdx;
013: protected DatabaseTableModel xtable;
014:
015: public DatabaseFieldModel() {
016: }
017:
018: public DatabaseFieldModel(DatabaseTableModel table, int row,
019: int field) {
020: setCellReference(table, row, field);
021: }
022:
023: public DatabaseTableModel getTable() {
024: return xtable;
025: }
026:
027: public int getFieldIndex() {
028: return fieldIdx;
029: }
030:
031: public void setCellReference(DatabaseTableModel table, int row,
032: int field) {
033: xtable = table;
034: rowIdx = row;
035: fieldIdx = field;
036: }
037:
038: public void append(XModel newObject) {
039: /**@todo Implement this net.xoetrope.xui.data.XModel abstract method*/
040: }
041:
042: public double getValueAsDouble(String elementName) {
043: /**@todo Implement this net.xoetrope.xui.data.XModel abstract method*/
044: throw new java.lang.UnsupportedOperationException(
045: "Method getValueAsDouble() not yet implemented.");
046: }
047:
048: public String getValue() {
049: return xtable.getFieldValue(rowIdx, fieldIdx);
050: }
051:
052: public Object getAttribValue(int i) {
053: /**@todo Implement this net.xoetrope.xui.data.XModel abstract method*/
054: throw new java.lang.UnsupportedOperationException(
055: "Method getAttribValue() not yet implemented.");
056: }
057:
058: public String getAttribValueAsString(int i) {
059: /**@todo Implement this net.xoetrope.xui.data.XModel abstract method*/
060: throw new java.lang.UnsupportedOperationException(
061: "Method getAttribValueAsString() not yet implemented.");
062: }
063:
064: /**
065: * Gets the value attribute of the specified node as a string.
066: * @param elementName
067: * @return the value as a string
068: */
069: public String getValueAsString(String elementName) {
070: /**@todo Implement this net.xoetrope.xui.data.XModel abstract method*/
071: throw new java.lang.UnsupportedOperationException(
072: "Method getValueAsString() not yet implemented.");
073: }
074:
075: public String getId() {
076: /**@todo Implement this net.xoetrope.xui.data.XModel abstract method*/
077: throw new java.lang.UnsupportedOperationException(
078: "Method getName() not yet implemented.");
079: }
080:
081: public String getAttribName(int i) {
082: /**@todo Implement this net.xoetrope.xui.data.XModel abstract method*/
083: throw new java.lang.UnsupportedOperationException(
084: "Method getAttribName() not yet implemented.");
085: }
086:
087: public int getAttribute(String attribName) {
088: /**@todo Implement this net.xoetrope.xui.data.XModel abstract method*/
089: throw new java.lang.UnsupportedOperationException(
090: "Method getAttribute() not yet implemented.");
091: }
092:
093: public void set(String attribName, Object newObject) {
094: /**@todo Implement this net.xoetrope.xui.data.XModel abstract method*/
095: }
096:
097: public void set(Object s) {
098: /**@todo Implement this net.xoetrope.xui.data.XModel abstract method*/
099: fireModelUpdated();
100: }
101:
102: public void remove(XModel model) {
103: /**@todo Implement this net.xoetrope.xui.data.XModel abstract method*/
104: }
105:
106: public XModel get(int i) {
107: return null;
108: }
109:
110: public Object append(String id) {
111: return null;
112: }
113:
114: /**
115: * Gets the model element tag name, e.g. 'Component' from the XML fragment
116: * <Component ....
117: * @return the model element name
118: */
119: public String getTagName() {
120: return "";
121: }
122:
123: public Object get() {
124: return xtable.getFieldValue(rowIdx, fieldIdx);
125: }
126:
127: public int getValueAsInt(String elementName) {
128: /**@todo Implement this net.xoetrope.xui.data.XModel abstract method*/
129: throw new java.lang.UnsupportedOperationException(
130: "Method getValueAsInt() not yet implemented.");
131: }
132:
133: public void setAttribValue(int i, Object value) {
134: /**@todo Implement this net.xoetrope.xui.data.XModel abstract method*/
135: }
136:
137: public void setAttribValue(int i, String attribName, Object value) {
138: /**@todo Implement this net.xoetrope.xui.data.XModel abstract method*/
139: }
140:
141: public int hashCode() {
142: return rowIdx * 10000 + fieldIdx;
143: }
144:
145: /**
146: * @param i The index of the attributeValues array whose value we want
147: * @return The int value of the attributeValues array at position i
148: */
149: public int getAttribValueAsInt(int i) {
150: return new Integer(xtable.getFieldValue(0, fieldIdx))
151: .intValue();
152: }
153:
154: /**
155: * @param i The index of the attributeValues array whose value we want
156: * @return The int value of the attributeValues array at position i
157: */
158: public double getAttribValueAsDouble(int i) {
159: return new Double(xtable.getFieldValue(0, fieldIdx))
160: .doubleValue();
161: }
162:
163: public String toString() {
164: return (String) get();
165: }
166: }
|