org.mmbase.bridge.util
Class AbstractFieldValue

java.lang.Object
  extended by org.mmbase.bridge.util.AbstractFieldValue
All Implemented Interfaces:
FieldValue
Direct Known Subclasses:
BasicFunctionValue

public abstract class AbstractFieldValue
extends Object
implements FieldValue

This abstract version of FieldValue only leaves get() to implement. Many other methods ('to<Some type>') are implemented by wrapping methods of Casting.

Since:
MMBase-1.8
Version:
$Id: AbstractFieldValue.java 41943 2010-04-16 17:18:19Z michiel $
Author:
Michiel Meeuwissen

Field Summary
protected static BridgeException CANNOTCHANGE
           
protected  Cloud cloud
           
protected  Node node
           
 
Constructor Summary
protected AbstractFieldValue(Node n, Cloud c)
           
 
Method Summary
 boolean canModify()
          Function values cannot be changed
abstract  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)
          Function values cannot be changed, and all set-functions throw an exception.
 void setBoolean(boolean value)
          Function values cannot be changed, and all set-functions throw an exception.
 void setByte(byte[] value)
          Function values cannot be changed, and all set-functions throw an exception.
 void setDate(Date value)
          Function values cannot be changed, and all set-functions throw an exception.
 void setDouble(double value)
          Function values cannot be changed, and all set-functions throw an exception.
 void setFLoat(float value)
          Function values cannot be changed, and all set-functions throw an exception.
 void setInt(int value)
          Function values cannot be changed, and all set-functions throw an exception.
 void setLong(long value)
          Function values cannot be changed, and all set-functions throw an exception.
 void setNode(Node value)
          Function values cannot be changed, and all set-functions throw an exception.
 void setObject(Object value)
           
 void setString(String value)
          Function values cannot be changed, and all set-functions throw an exception.
 void setXML(Document value)
          Function values cannot be changed, and all set-functions throw an exception.
 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
 

Field Detail

CANNOTCHANGE

protected static BridgeException CANNOTCHANGE

node

protected final Node node

cloud

protected final Cloud cloud
Constructor Detail

AbstractFieldValue

protected AbstractFieldValue(Node n,
                             Cloud c)
Method Detail

canModify

public boolean canModify()
Function values cannot be changed

Specified by:
canModify in interface FieldValue
Returns:
false

isNull

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

get

public abstract 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 final 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
Since:
MMBase-1.8

set

public void set(Object value)
Function values cannot be changed, and all set-functions throw an exception.

Specified by:
set in interface FieldValue
Parameters:
value - set value
Throws:
BridgeException
See Also:
FieldValue.get()

setObject

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

setBoolean

public void setBoolean(boolean value)
Function values cannot be changed, and all set-functions throw an exception.

Specified by:
setBoolean in interface FieldValue
Parameters:
value - set value
Throws:
BridgeException
See Also:
FieldValue.toBoolean()

setFLoat

public void setFLoat(float value)
Function values cannot be changed, and all set-functions throw an exception.

Specified by:
setFLoat in interface FieldValue
Parameters:
value - set value
Throws:
BridgeException
See Also:
FieldValue.toFloat()

setDouble

public void setDouble(double value)
Function values cannot be changed, and all set-functions throw an exception.

Specified by:
setDouble in interface FieldValue
Parameters:
value - set value
Throws:
BridgeException
See Also:
FieldValue.toDouble()

setLong

public void setLong(long value)
Function values cannot be changed, and all set-functions throw an exception.

Specified by:
setLong in interface FieldValue
Parameters:
value - set value
Throws:
BridgeException
See Also:
FieldValue.toLong()

setInt

public void setInt(int value)
Function values cannot be changed, and all set-functions throw an exception.

Specified by:
setInt in interface FieldValue
Parameters:
value - set value
Throws:
BridgeException
See Also:
FieldValue.toInt()

setByte

public void setByte(byte[] value)
Function values cannot be changed, and all set-functions throw an exception.

Specified by:
setByte in interface FieldValue
Parameters:
value - set value
Throws:
BridgeException
See Also:
FieldValue.toByte()

setString

public void setString(String value)
Function values cannot be changed, and all set-functions throw an exception.

Specified by:
setString in interface FieldValue
Parameters:
value - set value
Throws:
BridgeException
See Also:
FieldValue.toString()

setNode

public void setNode(Node value)
Function values cannot be changed, and all set-functions throw an exception.

Specified by:
setNode in interface FieldValue
Parameters:
value - set value
Throws:
BridgeException
See Also:
FieldValue.toNode()

setXML

public void setXML(Document value)
Function values cannot be changed, and all set-functions throw an exception.

Specified by:
setXML in interface FieldValue
Parameters:
value - set value
Throws:
BridgeException
See Also:
FieldValue.toXML(org.w3c.dom.Document)

setDate

public void setDate(Date value)
Function values cannot be changed, and all set-functions throw an exception.

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


MMBase 2.0-SNAPSHOT - null