org.mmbase.bridge
Interface FieldValue

All Known Implementing Classes:
BasicFieldValue, BasicFunctionValue

public interface FieldValue

This interface represents a value stored in a node.

Since:
MMBase 1.6
Version:
$Id: FieldValue.java,v 1.6 2004/03/02 12:42:25 pierre Exp $
Author:
Pierre van Rooden

Method Summary
 boolean canModify()
          Returns whether this value can be changed.
 java.lang.Object get()
          Returns the value as an Object.
 java.lang.Object getField()
          Returns the Field object belonging to this value.
 Node getNode()
          Returns the Node to which this value belongs.
 void set(java.lang.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 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 setString(java.lang.String value)
          Sets the value, passing a String.
 void setXML(org.w3c.dom.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.
 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.
 java.lang.String toString()
          Returns the value as a String.
 org.w3c.dom.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.
 org.w3c.dom.Element toXML(org.w3c.dom.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.
 

Method Detail

canModify

public boolean canModify()
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).

Returns:
true if the value can be changed

get

public java.lang.Object get()
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.

Returns:
the field value as an object

getField

public java.lang.Object getField()
Returns the Field object belonging to this value.

Returns:
the field object

getNode

public Node getNode()
Returns the Node to which this value belongs.

Returns:
the Node object

toBoolean

public boolean toBoolean()
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.

Returns:
the field value as a boolean

toByte

public byte[] toByte()
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.

Returns:
the field value as a byte array

toFloat

public float toFloat()
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.

Returns:
the field value as a float

toDouble

public double toDouble()
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.

Returns:
the field value as a double

toLong

public long toLong()
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

Returns:
the field value as a long.

toInt

public int toInt()
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

Returns:
the field value as an int.

toNode

public Node toNode()
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.

Returns:
the field value as a Node

toString

public java.lang.String toString()
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.

Returns:
the field value as a String

toXML

public org.w3c.dom.Document toXML()
                           throws java.lang.IllegalArgumentException
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

Returns:
the field value as a Document
Throws:
java.lang.IllegalArgumentException - if the Field is not of type TYPE_XML.

toXML

public org.w3c.dom.Element toXML(org.w3c.dom.Document tree)
                          throws java.lang.IllegalArgumentException
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

Parameters:
tree - the DOM Document to which the Element is added (as the document root element)
Returns:
the field value as an Element
Throws:
java.lang.IllegalArgumentException - if the Field is not of type TYPE_XML.

set

public void set(java.lang.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. 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()).

Parameters:
value - the field value as an Object
See Also:
get()

setBoolean

public void setBoolean(boolean value)
Sets the value, passing a boolean value. This value is converted to a Boolean object.

Parameters:
value - the field value as a boolean
See Also:
toBoolean()

setFLoat

public void setFLoat(float value)
Sets the value, passing a float value. This value is converted to a Float object.

Parameters:
value - the field value as a float
See Also:
toFloat()

setDouble

public void setDouble(double value)
Sets the value, passing a double value. This value is converted to a Double object.

Parameters:
value - the field value as a double
See Also:
toDouble()

setLong

public void setLong(long value)
Sets the value, passing a long value. This value is converted to a Long object.

Parameters:
value - the field value as a long
See Also:
toLong()

setInt

public void setInt(int value)
Sets the value, passing a int value. This value is converted to a Integer object.

Parameters:
value - the field value as a int
See Also:
toInt()

setByte

public void setByte(byte[] value)
Sets the value, passing a byte array.

Parameters:
value - the field value as a byte array
See Also:
toByte()

setString

public void setString(java.lang.String value)
Sets the value, passing a String.

Parameters:
value - the field value as a String
See Also:
toString()

setNode

public void setNode(Node value)
Sets the value, passing a Node.

Parameters:
value - the field value as a Node
See Also:
toNode()

setXML

public void setXML(org.w3c.dom.Document value)
Sets the value, passing a org.w3c.dom.Document object.

Parameters:
value - the field value as a XML Document
See Also:
toXML()


MMBase build 1.7.1.20041002