org.exist.fluent
Class DataUtils

java.lang.Object
  extended by org.exist.fluent.DataUtils

public class DataUtils
extends Object

A bunch of static data conversion utility methods.

Author:
Piotr Kaminski

Field Summary
static Comparator<XMLGregorianCalendar> DATE_TIME_COMPARATOR
          A comparator for dateTimes (XMLGregorianCalendar objects), that uses the partial order defined on dateTimes and throws an exception if the order is indeterminate.
 
Method Summary
static DatatypeFactory datatypeFactory()
          Return a shared instance of a datatype factory, used for creating new XML data objects.
static Date toDate(XMLGregorianCalendar dateTime)
          Convert an XML date/time to its java.util.Date equivalent.
static XMLGregorianCalendar toDateTime(Date date)
          Convert a Java date to its XML date/time equivalent.
static XMLGregorianCalendar toDateTime(long millis)
          Convert milliseconds offset to its XML date/time equivalent.
static Object toXMLObject(Object o)
          Convert a Java object to its equivalent XML datatype representation.
static String toXMLString(Object o)
          Convert a Java object to its equivalent XML datatype string representation.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATE_TIME_COMPARATOR

public static final Comparator<XMLGregorianCalendar> DATE_TIME_COMPARATOR
A comparator for dateTimes (XMLGregorianCalendar objects), that uses the partial order defined on dateTimes and throws an exception if the order is indeterminate.

Method Detail

datatypeFactory

public static DatatypeFactory datatypeFactory()
Return a shared instance of a datatype factory, used for creating new XML data objects.

Returns:
a shared datatype factory

toDate

public static Date toDate(XMLGregorianCalendar dateTime)
Convert an XML date/time to its java.util.Date equivalent.

Parameters:
dateTime - the XML date/time to convert
Returns:
a Java date

toDateTime

public static XMLGregorianCalendar toDateTime(Date date)
Convert a Java date to its XML date/time equivalent.

Parameters:
date - the Java date to convert
Returns:
an XML date/time

toDateTime

public static XMLGregorianCalendar toDateTime(long millis)
Convert milliseconds offset to its XML date/time equivalent.

Parameters:
millis - a millisecond count since the epoch
Returns:
an XML date/time

toXMLString

public static String toXMLString(Object o)
Convert a Java object to its equivalent XML datatype string representation. At the moment, there is special treatment for java.util.Date, java.util.Calendar and byte[] (Base64 encoding); for all other objects, we simply invoke toString().

Parameters:
o - the object to convert
Returns:
a string representation of the object, according to XML Schema Datatype rules if possible

toXMLObject

public static Object toXMLObject(Object o)
Convert a Java object to its equivalent XML datatype representation. At the moment, there is special treatment for java.util.Date, java.util.Calendar and byte[] (Base64 encoding); all other objects are simply passed through as-is.

Parameters:
o - the object to convert
Returns:
an XML representation of the object, according to XML Schema Datatype rules if possible


Copyright (C) All rights reserved.