Search in sources :

Example 56 with DatatypeConfigurationException

use of javax.xml.datatype.DatatypeConfigurationException in project sis by apache.

the class UniversalTimeAdapter method marshal.

/**
 * Converts the date to the object to be marshalled in a XML file or stream.
 * JAXB calls automatically this method at marshalling time.
 *
 * @param  value  the {@code java.util} date value, or {@code null}.
 * @return the XML date, or {@code null}.
 */
@Override
public XMLGregorianCalendar marshal(final Date value) {
    if (value != null) {
        final GregorianCalendar calendar = new GregorianCalendar(UTC, Locale.ROOT);
        calendar.setTime(value);
        try {
            final XMLGregorianCalendar gc = XmlUtilities.getDatatypeFactory().newXMLGregorianCalendar(calendar);
            if (gc.getMillisecond() == 0) {
                gc.setMillisecond(DatatypeConstants.FIELD_UNDEFINED);
            }
            return gc;
        } catch (DatatypeConfigurationException e) {
            Context.warningOccured(Context.current(), XmlAdapter.class, "marshal", e, true);
        }
    }
    return null;
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) XmlAdapter(javax.xml.bind.annotation.adapters.XmlAdapter)

Aggregations

DatatypeConfigurationException (javax.xml.datatype.DatatypeConfigurationException)56 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)35 GregorianCalendar (java.util.GregorianCalendar)33 DatatypeFactory (javax.xml.datatype.DatatypeFactory)20 Date (java.util.Date)18 BigInteger (java.math.BigInteger)6 ParseException (java.text.ParseException)6 JAXBException (javax.xml.bind.JAXBException)5 QName (javax.xml.namespace.QName)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 ConverterException (ch.ehi.ili2db.converter.ConverterException)2 BlackboxType (ch.interlis.ili2c.metamodel.BlackboxType)2 EnumerationType (ch.interlis.ili2c.metamodel.EnumerationType)2 NumericType (ch.interlis.ili2c.metamodel.NumericType)2 PrecisionDecimal (ch.interlis.ili2c.metamodel.PrecisionDecimal)2 IomObject (ch.interlis.iom.IomObject)2 ArrayOfString (com.marketo.mktows.ArrayOfString)2 LastUpdateAtSelector (com.marketo.mktows.LastUpdateAtSelector)2 File (java.io.File)2