Example usage for javax.xml.datatype DatatypeFactory newInstance

List of usage examples for javax.xml.datatype DatatypeFactory newInstance

Introduction

In this page you can find the example usage for javax.xml.datatype DatatypeFactory newInstance.

Prototype

public static DatatypeFactory newInstance() throws DatatypeConfigurationException 

Source Link

Document

Obtain a new instance of a DatatypeFactory .

Usage

From source file:com.github.dozermapper.core.converters.XMLGregorianCalendarConverter.java

/**
 * Returns a new instance of DatatypeFactory, or the cached one if previously created.
 *
 * @return instance of DatatypeFactory//from  www . j  a v a 2  s . c  om
 */
private static DatatypeFactory dataTypeFactory() {
    if (dataTypeFactory == null) {
        try {
            dataTypeFactory = DatatypeFactory.newInstance();
        } catch (DatatypeConfigurationException e) {
            throw new MappingException(e);
        }
    }
    return dataTypeFactory;
}

From source file:org.wiredwidgets.cow.server.convert.DateToXMLGregorianCalendar.java

public DateToXMLGregorianCalendar() {
    try {/*  w  w w  . j av a2s. c  om*/
        dtf = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException e) {
        throw new RuntimeException(e);
    }
}

From source file:ejava.projects.edmv.xml.EDmvParserTest.java

public void testMonthFormat() throws Exception {
    log.info("*** testMonthFormat ***");
    XMLGregorianCalendar cal1 = DatatypeFactory.newInstance().newXMLGregorianCalendar();
    cal1.setMonth(GregorianCalendar.MARCH);
    String xml = cal1.toXMLFormat();
    log.debug("MAR=" + xml);

    XMLGregorianCalendar cal = DatatypeFactory.newInstance().newXMLGregorianCalendar(xml);
    assertNotNull("calendar was null", cal);
    log.info("month=" + cal.getMonth());
    assertEquals("unexpected month", GregorianCalendar.MARCH, cal.getMonth());
}

From source file:Main.java

public static XMLGregorianCalendar getXMLDate(final Calendar calendar) {
    GregorianCalendar c;/*from   ww  w . j a v  a 2 s . c o m*/
    if (calendar instanceof GregorianCalendar) {
        c = (GregorianCalendar) calendar;
    } else {
        c = new GregorianCalendar();
        c.setTimeZone(UTC);
        c.setTime(calendar.getTime());
    }

    try {
        XMLGregorianCalendar ret = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
        ret.setMillisecond(DatatypeConstants.FIELD_UNDEFINED);
        return ret;
    } catch (DatatypeConfigurationException e) {
        return null;
    }
}

From source file:com.msopentech.odatajclient.engine.data.ODataDuration.java

public ODataDuration(final String input) {
    try {//from w  w w . j  av a2 s  .  c  o m
        final DatatypeFactory dtFactory = DatatypeFactory.newInstance();
        this.duration = dtFactory.newDuration(input);
    } catch (DatatypeConfigurationException e) {
        throw new IllegalArgumentException("Could not parse '" + input + "' as Duration", e);
    }
}

From source file:com.redhat.rhevm.api.powershell.util.PowerShellUtils.java

private static DatatypeFactory getDatatypeFactory() {
    if (datatypeFactory == null) {
        try {/*from w  w  w  .  j  av a  2 s .c  o m*/
            datatypeFactory = DatatypeFactory.newInstance();
        } catch (javax.xml.datatype.DatatypeConfigurationException dtce) {
            log.warn("Failed to initialize DatatypeFactory: " + dtce);
        }
    }
    return datatypeFactory;
}

From source file:com.microsoft.exchange.DateHelp.java

/**
 * /*from w  w w  .  j a  v a 2 s  .  co  m*/
 * @param date
 * @return
 */
public static XMLGregorianCalendar convertDateToXMLGregorianCalendar(final Date date) {
    if (date == null) {
        return null;
    }
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(date);
    try {
        return DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar);
    } catch (DatatypeConfigurationException e) {
        throw new IllegalStateException("unable to invoke DatatypeFactory.newInstance", e);
    }
}

From source file:ejava.projects.edmv.xml.EDmvBindingTest.java

public void testCalendar() throws Exception {
    log.info("*** testCalendar ***");
    DatatypeFactory dataFactory = DatatypeFactory.newInstance();
    log.info("DataTypeFactory=" + dataFactory);
    XMLGregorianCalendar cal = dataFactory.newXMLGregorianCalendar();
    log.info("XMLGregorianCalendar=" + cal.getClass());
    cal.setMonth(GregorianCalendar.MARCH);
    String xml = cal.toXMLFormat();
    log.debug("cal=" + xml);
    dataFactory.newXMLGregorianCalendar(xml);

    cal.setTimezone(0);/*from  w w w .  j  a  va2  s. c  o m*/

    Calendar jCal = Calendar.getInstance();
    jCal.clear();
    jCal.set(Calendar.MONTH, Calendar.MARCH);
    DateFormat df = DateFormat.getDateInstance();
    String dfString = df.format(jCal.getTime());
    log.debug("calendar=" + dfString);

    String format = "--01";
    try {
        XMLGregorianCalendar xCal = dataFactory.newXMLGregorianCalendar(format);
        log.info("successfully parsed:" + format + ", xCal=" + xCal.toXMLFormat());
        format = "--01--";
        xCal = dataFactory.newXMLGregorianCalendar(format);
        log.info("successfully parsed:" + format + ", xCal=" + xCal.toXMLFormat());
    } catch (Exception ex) {
        log.error("failed to parse:" + format);
        fail("failed to parse:" + format);
    }
}

From source file:org.miloss.fgsms.services.rs.impl.reports.ws.MeanTimeBetweenFailureByService.java

public MeanTimeBetweenFailureByService() {
    try {
        df = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException ex) {

    }
}

From source file:com.adaptris.core.fs.LastModifiedFilter.java

protected Date filterDate() throws Exception {
    Date filterDate = new Date();
    if (NumberUtils.isDigits(when)) {
        filterDate.setTime(Long.parseLong(when));
    } else {/*from w  w  w.  j  ava 2  s  .co m*/
        Duration duration = DatatypeFactory.newInstance().newDuration(when);
        duration.addTo(filterDate);
    }
    return filterDate;
}