use of org.apache.xmlbeans.GDateBuilder 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.GDateBuilder in project arctic-sea by 52North.
the class SweCommonEncoderv101 method createDateTime.
private XmlDateTime createDateTime(DateTime sosDateTime) {
XmlDateTime xbDateTime = XmlDateTime.Factory.newInstance(getXmlOptions());
// encode the DateTime in UTC
GDateBuilder gdb = new GDateBuilder(sosDateTime.toDate());
gdb.normalize();
xbDateTime.setGDateValue(gdb.toGDate());
return xbDateTime;
}
Aggregations