use of org.apache.xmlbeans.GDate in project iaf by ibissource.
the class DateUtils method parseXmlDateTime.
/**
* Parses a string to a Date, according to the XML Schema dateTime data type
*/
public static Date parseXmlDateTime(String s) {
GDate gdate = new org.apache.xmlbeans.GDate(s);
Date result = gdate.getDate();
return result;
}
use of org.apache.xmlbeans.GDate in project hale by halestudio.
the class SimpleTypeUtil method convertToXml.
/**
* Convert a simple type value to a string
*
* @param <T> the type of the value
* @param value the value
* @param type the type definition of the simple type
* @return the string representation of the value or <code>null</code> if
* the value is <code>null</code>
*/
public static <T> String convertToXml(T value, TypeDefinition type) {
if (value == null) {
return null;
}
ConversionService conversionService = HalePlatform.getService(ConversionService.class);
Class<? extends XmlAnySimpleType> simpleType = getSimpleType(type);
if (simpleType != null) {
try {
XmlAnySimpleType simpleTypeValue = conversionService.convert(value, simpleType);
if (simpleTypeValue instanceof XmlDateTime) {
XmlDateTime xmlDateTime = (XmlDateTime) simpleTypeValue;
// use Zulu time to have a reproducable result
// (as the old Java Date types always assume the current
// time zone!)
//
// XXX this should be removed when time/date types are used
// that are timezone aware
Calendar calendar = xmlDateTime.getCalendarValue();
GDateBuilder builder = new GDateBuilder(calendar);
builder.normalizeToTimeZone(0);
GDate gdate = builder.toGDate();
xmlDateTime.setGDateValue(gdate);
}
if (simpleTypeValue != null) {
return simpleTypeValue.getStringValue();
}
} catch (ConversionException e) {
// ignore
}
}
// try to convert to string
try {
String stringValue = conversionService.convert(value, String.class);
if (stringValue != null) {
return stringValue;
}
} catch (ConversionException e) {
// ignore
}
// fall-back
return value.toString();
}
use of org.apache.xmlbeans.GDate in project hale by halestudio.
the class DateToXmlTime method convert.
/**
* @see Converter#convert(Object)
*/
@Override
public XmlTime convert(Date value) {
XmlTime result = XmlTime.Factory.newInstance();
result.setGDateValue(new GDate(value));
return result;
}
Aggregations