org.mmbase.bridge.implementation
Class BasicFieldValue

java.lang.Object
  extended by org.mmbase.bridge.implementation.BasicFieldValue
All Implemented Interfaces:
FieldValue

public class BasicFieldValue
extends Object
implements FieldValue

This is the basic implementation of the Field Value interface.

Since:
MMBase-1.6
Version:
$Id: BasicFieldValue.java 41943 2010-04-16 17:18:19Z michiel $
Author:
Pierre van Rooden

Constructor Summary
BasicFieldValue(Node node, Field field)
           
 
Method Summary
 boolean canModify()
          Returns whether this value can be changed.
 Object get()
          Returns the value as an Object.
 Field getField()
          Returns the Field object belonging to this value.
 Node getNode()
          Returns the Node to which this value belongs.
 boolean isNull()
           
 void set(Object value)
          Sets the value, passing any Object The object type may vary and is generally stored in memory as-is, which means that, generally, the get() method returns the same object.
 void setBoolean(boolean value)
          Sets the value, passing a boolean value.
 void setByte(byte[] value)
          Sets the value, passing a byte array.
 void setDate(Date value)
          Sets the value, passing a java.util.Date object.
 void setDouble(double value)
          Sets the value, passing a double value.
 void setFLoat(float value)
          Sets the value, passing a float value.
 void setInt(int value)
          Sets the value, passing a int value.
 void setLong(long value)
          Sets the value, passing a long value.
 void setNode(Node value)
          Sets the value, passing a Node.
 void setObject(Object value)
           
 void setString(String value)
          Sets the value, passing a String.
 void setXML(Document value)
          Sets the value, passing a org.w3c.dom.Document object.
 boolean toBoolean()
          Returns the value as an boolean (true or false).
 byte[] toByte()
          Returns the value as a byte array.
 Date toDate()
          Returns the value as a java.util.Date If the value cannot be converted, this method returns null
 double toDouble()
          Returns the value as a double.
 float toFloat()
          Returns the value as a float.
 int toInt()
          Returns the value as an int.
 long toLong()
          Returns the value as a long.
 Node toNode()
          Returns the value as a Node.
 String toString()
          Returns the value as a String.
 Document toXML()
          Returns the value as a org.w3c.dom.Document If the node value is not itself a Document, the method attempts to attempts to convert the String value into an XML.
 Element toXML(Document tree)
          Returns the value as a org.w3c.dom.Element If the node value is not itself a Document, the method attempts to attempts to convert the String value into an XML.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BasicFieldValue

public BasicFieldValue(Node node,
                       Field field)
Method Detail

canModify

public boolean canModify()
Description copied from interface: FieldValue
Returns whether this value can be changed. Some field values (such as the values of the number, owner, and otype fields) cannot be changed through this interface (but some may be changed through other means).

Specified by:
canModify in interface FieldValue
Returns:
true if the value can be changed

isNull

public boolean isNull()
Specified by:
isNull in interface FieldValue

get

public Object get()
Description copied from interface: FieldValue
Returns the value as an Object. The object type may vary and is dependent on how data was stored in a field. I.e. It may be possible for an Integer field to return it's value as a String if it was stored that way in the first place.

Specified by:
get in interface FieldValue
Returns:
the field value as an object

getField

public Field getField()
Description copied from interface: FieldValue
Returns the Field object belonging to this value.

Specified by:
getField in interface FieldValue
Returns:
the field object. Why not return Field?

getNode

public Node getNode()
Description copied from interface: FieldValue
Returns the Node to which this value belongs.

Specified by:
getNode in interface FieldValue
Returns:
the Node object

toBoolean

public boolean toBoolean()
Description copied from interface: FieldValue
Returns the value as an boolean (true or false). If the actual value is a Boolean object, this call returns it's (primitive) boolean value. If the actual value is a Number object, this call returns true if the value is a positive, non-zero, value. In other words, values '0' and '-1' are concidered false. If the value is a string, this call returns true if the value is "true" or "yes" (case-insensitive). In all other cases (including calling byte fields), false is returned.

Specified by:
toBoolean in interface FieldValue
Returns:
the field value as a boolean

toByte

public byte[] toByte()
Description copied from interface: FieldValue
Returns the value as a byte array. This function returns either the value of a byte field, or the byte value of a string (converted using the default encoding, i.e. UTF8) Other types of values return an empty byte-array.

Specified by:
toByte in interface FieldValue
Returns:
the field value as a byte array

toFloat

public float toFloat()
Description copied from interface: FieldValue
Returns the value as a float. This function attempts to convert the value to a float. Numeric fields are simply converted. Boolean fields return 0.0 if false, and 1.0 if true. String fields are parsed. If a parsed string contains an error, ot the field value is not of a type that can be converted (i.e. a byte array), this function returns -1.0.

Specified by:
toFloat in interface FieldValue
Returns:
the field value as a float

toDouble

public double toDouble()
Description copied from interface: FieldValue
Returns the value as a double. This function attempts to convert the value to a double. Numeric fields are simply converted. Double may be truncated. Boolean fields return 0.0 if false, and 1.0 if true. String fields are parsed. If a parsed string contains an error, ot the field value is not of a type that can be converted (i.e. a byte array), this function returns -1.0.

Specified by:
toDouble in interface FieldValue
Returns:
the field value as a double

toLong

public long toLong()
Description copied from interface: FieldValue
Returns the value as a long. This function attempts to convert the value to a long. Numeric fields are simply converted. Double and float values may be truncated. Boolean fields return 0 if false, and 1 if true. String fields are parsed. If a parsed string contains an error, ot the field value is not of a type that can be converted (i.e. a byte array), this function returns -1

Specified by:
toLong in interface FieldValue
Returns:
the field value as a long.

toInt

public int toInt()
Description copied from interface: FieldValue
Returns the value as an int. This function attempts to convert the value to an int. Numeric fields are simply converted. Double and float values may be truncated. For Node values, the numeric key is returned. Long values return -1 of the value is too large. Boolean fields return 0 if false, and 1 if true. String fields are parsed. If a parsed string contains an error, ot the field value is not of a type that can be converted (i.e. a byte array), this function returns -1

Specified by:
toInt in interface FieldValue
Returns:
the field value as an int.

toNode

public Node toNode()
Description copied from interface: FieldValue
Returns the value as a Node. This function attempts to retrieve the node represented by the value. For numeric fields the node is retrieved using the numeric values as the node key. String fields are used as Node aliases, withw hich to retrieve the Node. If the node does not exist, or the value is of anotehr type, the function returns null.

Specified by:
toNode in interface FieldValue
Returns:
the field value as a Node

toString

public String toString()
Description copied from interface: FieldValue
Returns the value as a String. Byte arrays are converted to string using the default encoding (UTF8). Node values return a string representation of their numeric key. DOM Documents are serialized to a proper strign represnattion fo the xml. For other values the result is calling the toString() method on the actual object.

Specified by:
toString in interface FieldValue
Overrides:
toString in class Object
Returns:
the field value as a String

toXML

public Document toXML()
               throws IllegalArgumentException
Description copied from interface: FieldValue
Returns the value as a org.w3c.dom.Document If the node value is not itself a Document, the method attempts to attempts to convert the String value into an XML. If the value cannot be converted, this method returns null

Specified by:
toXML in interface FieldValue
Returns:
the field value as a Document
Throws:
IllegalArgumentException - if the Field is not of type TYPE_XML.

toXML

public Element toXML(Document tree)
              throws IllegalArgumentException
Description copied from interface: FieldValue
Returns the value as a org.w3c.dom.Element If the node value is not itself a Document, the method attempts to attempts to convert the String value into an XML. This method fails (throws a IllegalArgumentException) if the Field is not of type TYPE_XML. If the value cannot be converted, this method returns null

Specified by:
toXML in interface FieldValue
Parameters:
tree - the DOM Document to which the Element is added (as the document root element)
Returns:
the field value as an Element
Throws:
IllegalArgumentException - if the Field is not of type TYPE_XML.

toDate

public Date toDate()
Description copied from interface: FieldValue
Returns the value as a java.util.Date If the value cannot be converted, this method returns null

Specified by:
toDate in interface FieldValue
Returns:
the field value as Date

set

public void set(Object value)
Description copied from interface: FieldValue
Sets the value, passing any Object The object type may vary and is generally stored in memory as-is, which means that, generally, the get() method returns the same object. Note that for an XML field String values are converted to a XML document, and individual builders may make their own changes. The object is converted to the actual type (using the getXXX() methods detailed above) once the node is stored, though that does not affect the data in-memory until the Node is read anew from the storage. Note that this behavior may change in the future and therefor code should not be dependent on this. By preference, use the more specific methods for setting data (i.e. setString()).

Specified by:
set in interface FieldValue
Parameters:
value - the field value as an Object
See Also:
FieldValue.get()

setObject

public void setObject(Object value)
Specified by:
setObject in interface FieldValue

setBoolean

public void setBoolean(boolean value)
Description copied from interface: FieldValue
Sets the value, passing a boolean value. This value is converted to a Boolean object.

Specified by:
setBoolean in interface FieldValue
Parameters:
value - the field value as a boolean
See Also:
FieldValue.toBoolean()

setFLoat

public void setFLoat(float value)
Description copied from interface: FieldValue
Sets the value, passing a float value. This value is converted to a Float object.

Specified by:
setFLoat in interface FieldValue
Parameters:
value - the field value as a float
See Also:
FieldValue.toFloat()

setDouble

public void setDouble(double value)
Description copied from interface: FieldValue
Sets the value, passing a double value. This value is converted to a Double object.

Specified by:
setDouble in interface FieldValue
Parameters:
value - the field value as a double
See Also:
FieldValue.toDouble()

setLong

public void setLong(long value)
Description copied from interface: FieldValue
Sets the value, passing a long value. This value is converted to a Long object.

Specified by:
setLong in interface FieldValue
Parameters:
value - the field value as a long
See Also:
FieldValue.toLong()

setInt

public void setInt(int value)
Description copied from interface: FieldValue
Sets the value, passing a int value. This value is converted to a Integer object.

Specified by:
setInt in interface FieldValue
Parameters:
value - the field value as a int
See Also:
FieldValue.toInt()

setByte

public void setByte(byte[] value)
Description copied from interface: FieldValue
Sets the value, passing a byte array.

Specified by:
setByte in interface FieldValue
Parameters:
value - the field value as a byte array
See Also:
FieldValue.toByte()

setString

public void setString(String value)
Description copied from interface: FieldValue
Sets the value, passing a String.

Specified by:
setString in interface FieldValue
Parameters:
value - the field value as a String
See Also:
FieldValue.toString()

setNode

public void setNode(Node value)
Description copied from interface: FieldValue
Sets the value, passing a Node.

Specified by:
setNode in interface FieldValue
Parameters:
value - the field value as a Node
See Also:
FieldValue.toNode()

setXML

public void setXML(Document value)
Description copied from interface: FieldValue
Sets the value, passing a org.w3c.dom.Document object.

Specified by:
setXML in interface FieldValue
Parameters:
value - the field value as a XML Document
See Also:
FieldValue.toXML(org.w3c.dom.Document)

setDate

public void setDate(Date value)
Description copied from interface: FieldValue
Sets the value, passing a java.util.Date object.

Specified by:
setDate in interface FieldValue
Parameters:
value - the field value as a java.util.Date Document
See Also:
FieldValue.toDate()


MMBase 2.0-SNAPSHOT - null