001: /*
002:
003: This software is OSI Certified Open Source Software.
004: OSI Certified is a certification mark of the Open Source Initiative.
005:
006: The license (Mozilla version 1.0) can be read at the MMBase site.
007: See http://www.MMBase.org/license
008:
009: */
010:
011: package org.mmbase.bridge.implementation;
012:
013: import org.mmbase.bridge.*;
014:
015: /**
016: * This is the basic implementation of the Field Value interface.
017: *
018: * @author Pierre van Rooden
019: * @version $Id: BasicFieldValue.java,v 1.12 2007/02/16 20:04:39 michiel Exp $
020: * @since MMBase-1.6
021: */
022: public class BasicFieldValue implements FieldValue {
023:
024: private Node node = null;
025: private Field field = null;
026:
027: public BasicFieldValue(Node node, Field field) {
028: this .node = node;
029: this .field = field;
030: }
031:
032: public boolean canModify() {
033: // rather simple... should maybe ask Node
034: return (field != null) || "number".equals(field.getName())
035: || "otype".equals(field.getName())
036: || "owner".equals(field.getName())
037: || "snumber".equals(field.getName())
038: || "dnumber".equals(field.getName())
039: || "rnumber".equals(field.getName());
040: }
041:
042: public boolean isNull() {
043: return node.isNull(field.getName());
044: }
045:
046: public Object get() {
047: return node.getValue(field.getName());
048: }
049:
050: public Field getField() {
051: return field;
052: }
053:
054: public Node getNode() {
055: return node;
056: }
057:
058: public boolean toBoolean() {
059: return node.getBooleanValue(field.getName());
060: }
061:
062: public byte[] toByte() {
063: return node.getByteValue(field.getName());
064: }
065:
066: public float toFloat() {
067: return node.getFloatValue(field.getName());
068: }
069:
070: public double toDouble() {
071: return node.getDoubleValue(field.getName());
072: }
073:
074: public long toLong() {
075: return node.getLongValue(field.getName());
076: }
077:
078: public int toInt() {
079: return node.getIntValue(field.getName());
080: }
081:
082: public Node toNode() {
083: return node.getNodeValue(field.getName());
084: }
085:
086: @Override
087: public String toString() {
088: return node.getStringValue(field.getName());
089: }
090:
091: public org.w3c.dom.Document toXML() throws IllegalArgumentException {
092: return node.getXMLValue(field.getName());
093: }
094:
095: public org.w3c.dom.Element toXML(org.w3c.dom.Document tree)
096: throws IllegalArgumentException {
097: return node.getXMLValue(field.getName(), tree);
098: }
099:
100: public java.util.Date toDate() {
101: return node.getDateValue(field.getName());
102: }
103:
104: public void set(Object value) {
105: node.setValue(field.getName(), value);
106: }
107:
108: public void setObject(Object value) {
109: node.setObjectValue(field.getName(), value);
110: }
111:
112: public void setBoolean(boolean value) {
113: node.setBooleanValue(field.getName(), value);
114: }
115:
116: public void setFLoat(float value) {
117: node.setFloatValue(field.getName(), value);
118: }
119:
120: public void setDouble(double value) {
121: node.setDoubleValue(field.getName(), value);
122: }
123:
124: public void setLong(long value) {
125: node.setLongValue(field.getName(), value);
126: }
127:
128: public void setInt(int value) {
129: node.setIntValue(field.getName(), value);
130: }
131:
132: public void setByte(byte[] value) {
133: node.setByteValue(field.getName(), value);
134: }
135:
136: public void setString(String value) {
137: node.setStringValue(field.getName(), value);
138: }
139:
140: public void setNode(Node value) {
141: node.setNodeValue(field.getName(), value);
142: }
143:
144: public void setXML(org.w3c.dom.Document value) {
145: node.setXMLValue(field.getName(), value);
146: }
147:
148: public void setDate(java.util.Date value) {
149: node.setDateValue(field.getName(), value);
150: }
151:
152: }
|