Search in sources :

Example 1 with GDate

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;
}
Also used : GDate(org.apache.xmlbeans.GDate) Date(java.util.Date) GDate(org.apache.xmlbeans.GDate)

Example 2 with GDate

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();
}
Also used : XmlAnySimpleType(org.apache.xmlbeans.XmlAnySimpleType) ConversionException(org.springframework.core.convert.ConversionException) XmlDateTime(org.apache.xmlbeans.XmlDateTime) ConversionService(org.springframework.core.convert.ConversionService) Calendar(java.util.Calendar) GDateBuilder(org.apache.xmlbeans.GDateBuilder) GDate(org.apache.xmlbeans.GDate)

Example 3 with GDate

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;
}
Also used : XmlTime(org.apache.xmlbeans.XmlTime) GDate(org.apache.xmlbeans.GDate)

Aggregations

GDate (org.apache.xmlbeans.GDate)3 Calendar (java.util.Calendar)1 Date (java.util.Date)1 GDateBuilder (org.apache.xmlbeans.GDateBuilder)1 XmlAnySimpleType (org.apache.xmlbeans.XmlAnySimpleType)1 XmlDateTime (org.apache.xmlbeans.XmlDateTime)1 XmlTime (org.apache.xmlbeans.XmlTime)1 ConversionException (org.springframework.core.convert.ConversionException)1 ConversionService (org.springframework.core.convert.ConversionService)1