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.cisco.cta.taxii.adapter.persistence.PersistenceConfigurationTest.java

@Test
public void writeReadTaxiiStatusWithPersistentObject() throws Exception {

    // write//from  w ww.  ja v a  2  s  . com
    TaxiiStatus writeRoot = new TaxiiStatus();
    TaxiiStatus.Feed feed = new TaxiiStatus.Feed();
    feed.setName("my");
    feed.setLastUpdate(DatatypeFactory.newInstance().newXMLGregorianCalendar("2000-01-02T03:04:05.006+07:00"));
    writeRoot.getFeed().add(feed);
    taxiiStatusPersistent.setRoot(writeRoot);

    //read
    TaxiiStatus readRoot = taxiiStatusPersistent.getRoot();
    assertThat(writeRoot, not(sameInstance(readRoot)));
    assertThat(readRoot.getFeed().get(0), is(feed));
}

From source file:com.cisco.cta.taxii.adapter.persistence.TaxiiStatusDaoTest.java

@Before
public void setUp() throws Exception {
    datatypeFactory = DatatypeFactory.newInstance();
    now = Instant.parse("2000-01-02T03:04:05.006Z");
}

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

public void testMonthParse() 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  ww  . j  a v a2 s. c o  m

    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:com.evolveum.midpoint.prism.xml.XmlTypeConverter.java

private static DatatypeFactory getDatatypeFactory() {
    if (datatypeFactory == null) {
        try {/*w ww.j  ava 2 s  . c  o m*/
            datatypeFactory = DatatypeFactory.newInstance();
        } catch (DatatypeConfigurationException ex) {
            throw new IllegalStateException("Cannot construct DatatypeFactory: " + ex.getMessage(), ex);
        }
    }
    return datatypeFactory;
}

From source file:net.servicefixture.converter.XMLGregorianCalendarConverter.java

private XMLGregorianCalendar calendarToXMLGregorianCalendar(Calendar calendar) {
    XMLGregorianCalendar xmlCal;/*from ww w .j  a  v a 2 s. c  om*/
    try {
        xmlCal = DatatypeFactory.newInstance().newXMLGregorianCalendar();
    } catch (DatatypeConfigurationException e) {
        throw new RuntimeException("Failed to create XMLGregorianCalendar", e);
    }

    xmlCal.setYear(calendar.get(Calendar.YEAR));
    xmlCal.setMonth(calendar.get(Calendar.MONTH) + 1);
    xmlCal.setDay(calendar.get(Calendar.DAY_OF_MONTH));
    xmlCal.setHour(calendar.get(Calendar.HOUR));
    xmlCal.setMinute(calendar.get(Calendar.MINUTE));
    xmlCal.setSecond(calendar.get(Calendar.SECOND));
    xmlCal.setMillisecond(calendar.get(Calendar.MILLISECOND));
    return xmlCal;
}

From source file:net.sourceforge.subsonic.controller.JAXBWriter.java

public JAXBWriter() {
    try {//from  w w  w. j a  v  a2s.  c  o m
        jaxbContext = JAXBContext.newInstance(Response.class);
        datatypeFactory = DatatypeFactory.newInstance();
        restProtocolVersion = getRESTProtocolVersion();
    } catch (Exception x) {
        throw new RuntimeException(x);
    }
}

From source file:eu.impress.repository.util.EDXLlib.java

public static XMLGregorianCalendar getXMLGregorianCalendar() throws DatatypeConfigurationException {

    try {/* ww  w  .  j  a  v a 2 s . c  om*/

        Date now = new Date();
        GregorianCalendar c = new GregorianCalendar();
        c.setTime(now);
        XMLGregorianCalendar date2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
        return date2;

    } catch (DatatypeConfigurationException c) {

        return null;

    }

}

From source file:org.ow2.petals.cloud.vacation.web.VacationWebUiApplication.java

@Bean
public DatatypeFactory dtf() throws DatatypeConfigurationException {
    return DatatypeFactory.newInstance();
}

From source file:io.getlime.security.powerauth.soap.spring.client.PowerAuthServiceClient.java

/**
 * Convert date to XMLGregorianCalendar/*from w ww.  j av  a  2 s . co  m*/
 * @param date Date to be converted.
 * @return A new instance of {@link XMLGregorianCalendar}.
 * @throws DatatypeConfigurationException
 */
private XMLGregorianCalendar calendarWithDate(Date date) {
    try {
        GregorianCalendar c = new GregorianCalendar();
        c.setTime(date);
        return DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
    } catch (DatatypeConfigurationException e) {
        // Unless there is a terrible configuration error, this should not happen
        e.printStackTrace();
    }
    return null;
}

From source file:net.kahowell.xsd.fuzzer.config.DefaultOptionsModule.java

@Override
protected void configure() {
    bindConstant().annotatedWith(Names.named("generate all attributes")).to(true);
    bindConstant().annotatedWith(Names.named("generate required attributes only")).to(false);
    bindConstant().annotatedWith(Names.named("output filename")).to("output.xml");
    bindConstant().annotatedWith(Names.named("hard element limit")).to(20);
    bindConstant().annotatedWith(Names.named("offline")).to(false);
    bind(XmlOptions.class).annotatedWith(Names.named("xml schema options"))
            .toProvider(DefaultSchemaXmlOptionsProvider.class).in(Singleton.class);
    bind(XmlOptions.class).annotatedWith(Names.named("xml save options"))
            .toProvider(DefaultSaveXmlOptionsProvider.class).in(Singleton.class);
    bind(RandomData.class).to(RandomDataImpl.class).in(Singleton.class);
    bind(XmlGenerationOptions.class).in(Singleton.class);
    try {//from   ww w.  j  a  v a2s.com
        bind(DatatypeFactory.class).toInstance(DatatypeFactory.newInstance());
    } catch (DatatypeConfigurationException e) {
        throw new RuntimeException(e);
    }
}