org.mmbase.util
Class Casting

java.lang.Object
  extended byorg.mmbase.util.Casting

public class Casting
extends java.lang.Object


Constructor Summary
Casting()
           
 
Method Summary
static boolean toBoolean(java.lang.Object b)
          Get a value of a certain field.
static byte[] toByte(java.lang.Object obj)
          Get a binary value of a object.
static java.util.Date toDate(java.lang.Object i)
          How to convert mmbase object to a Date object
static double toDouble(java.lang.Object i)
          Get a value of a certain field.
static float toFloat(java.lang.Object i)
          Get a value of a certain field.
static int toInt(java.lang.Object i)
          Get a value of a certain field.
static int toInt(java.lang.Object i, int def)
          as toInt, but with configurable fallback-value
static java.lang.Integer toInteger(java.lang.Object i)
          Get a value of a certain field.
static java.util.List toList(java.lang.Object o)
           
static long toLong(java.lang.Object i)
           
static long toLong(java.lang.Object i, long def)
          Get a value of a certain field.
static Node toNode(java.lang.Object i, Cloud cloud)
           
static MMObjectNode toNode(java.lang.Object i, MMObjectBuilder parent)
          Get a value of a certain field.
static java.lang.String toString(java.lang.Object o)
          Get a value of a certain field.
static java.lang.StringBuffer toStringBuffer(java.lang.StringBuffer buffer, java.lang.Object o)
           
static java.io.Writer toWriter(java.io.Writer writer, java.lang.Object o)
           
static org.w3c.dom.Document toXML(java.lang.Object o, java.lang.String documentType, java.lang.String conversion)
          Returns the value of the specified field as a dom.Document 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, toString, wait, wait, wait
 

Constructor Detail

Casting

public Casting()
Method Detail

toString

public static java.lang.String toString(java.lang.Object o)
Get a value of a certain field. The value is returned as a String. Non-string values are automatically converted to String. 'null' is converted to an empty string.

Parameters:
o - the object which must be presented as a string
Returns:
the field's value as a String

toStringBuffer

public static java.lang.StringBuffer toStringBuffer(java.lang.StringBuffer buffer,
                                                    java.lang.Object o)
Since:
MMBase-1.7

toWriter

public static java.io.Writer toWriter(java.io.Writer writer,
                                      java.lang.Object o)
                               throws java.io.IOException
Throws:
java.io.IOException
Since:
MMBase-1.7

toList

public static java.util.List toList(java.lang.Object o)
Since:
MMBase-1.7

toXML

public static org.w3c.dom.Document toXML(java.lang.Object o,
                                         java.lang.String documentType,
                                         java.lang.String conversion)
Returns the value of the specified field as a 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

Parameters:
o - the object to be converted to an XML document
Returns:
the value of the specified field as a DOM Element or null
Throws:
java.lang.IllegalArgumentException - if the Field is not of type TYPE_XML.
Since:
MMBase-1.6

toByte

public static byte[] toByte(java.lang.Object obj)
Get a binary value of a object.

Parameters:
obj - The object to be converted to a byte[]
Returns:
the field's value as an byte [] (binary/blob field)

toNode

public static MMObjectNode toNode(java.lang.Object i,
                                  MMObjectBuilder parent)
Get a value of a certain field. The value is returned as an MMObjectNode. If the field contains an Numeric value, the method tries to obtrain the object with that number. If it is a String, the method tries to obtain the object with that alias. The only other possible values are those created by certain virtual fields. All remaining situations return null.

Returns:
the field's value as an int

toNode

public static Node toNode(java.lang.Object i,
                          Cloud cloud)
Since:
MMBase-1.7

toInt

public static int toInt(java.lang.Object i)
Get a value of a certain field. The value is returned as an int value. Values of non-int, numeric fields are converted if possible. Booelan fields return 0 for false, 1 for true. String fields are parsed to a number, if possible. If a value is an MMObjectNode, it's numberfield is returned. All remaining field values return -1.

Returns:
the field's value as an int

toInt

public static int toInt(java.lang.Object i,
                        int def)
as toInt, but with configurable fallback-value

Since:
MMBase-1.7

toBoolean

public static boolean toBoolean(java.lang.Object b)
Get a value of a certain field. The value is returned as an boolean value. If the actual value is numeric, 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. Note that there is currently no basic MMBase boolean type, but some excecuteFunction calls may return a Boolean result.

Returns:
the field's value as an int

toInteger

public static java.lang.Integer toInteger(java.lang.Object i)
Get a value of a certain field. The value is returned as an Integer value. Values of non-Integer, numeric fields are converted if possible. Boolean fields return 0 for false, 1 for true. String fields are parsed to a number, if possible. All remaining field values return -1.

Returns:
the field's value as an Integer

toLong

public static long toLong(java.lang.Object i,
                          long def)
Get a value of a certain field. The value is returned as a long value. Values of non-long, numeric fields are converted if possible. Boolean fields return 0 for false, 1 for true. String fields are parsed to a number, if possible. All remaining field values return -1.

Returns:
the field's value as a long
Since:
MMBase-1.7

toLong

public static long toLong(java.lang.Object i)

toFloat

public static float toFloat(java.lang.Object i)
Get a value of a certain field. The value is returned as a float value. Values of non-float, numeric fields are converted if possible. Boolean fields return 0 for false, 1 for true. String fields are parsed to a number, if possible. All remaining field values return -1.

Returns:
the field's value as a float

toDate

public static java.util.Date toDate(java.lang.Object i)
How to convert mmbase object to a Date object

Since:
MMBase-1.7

toDouble

public static double toDouble(java.lang.Object i)
Get a value of a certain field. The value is returned as a double value. Values of non-double, numeric fields are converted if possible. Boolean fields return 0 for false, 1 for true. String fields are parsed to a number, if possible. All remaining field values return -1.

Returns:
the field's value as a double


MMBase build 1.7.4.20050922