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:org.openanzo.test.client.TestDateTime.java

/**
 * Test the conversion of javax.xml.datatype.Duration objects in the Anzo.java API into various XML Schema-types RDF literals. The test will add statements
 * using javax.xml.datatype.Duration objects and verify that when those statements are retrieved, the expected lexical value, datatype, etc. are correct.
 * /*from  www  .  j a  va2  s .c om*/
 * @throws Exception
 */
public void testDurationBecomesXsdTypedLiterals() throws Exception {

    AnzoClient client = null;
    try {
        client = new AnzoClient(getDefaultClientConfiguration());
        client.connect();
        client.reset(loadStatements("initialize.trig"), null);
        ClientGraph graph = client.getReplicaGraph(GRAPH_URI);

        DatatypeFactory df = DatatypeFactory.newInstance();

        // xsd:duration
        Duration duration = df.newDuration(true, 28, 5, 16, 1, 15, 37);
        addAndRetrieveNativeLiteral(client, graph, duration, duration, "P28Y5M16DT1H15M37S",
                XMLSchema.DURATION);

        // xsd:yearMonthDuration
        duration = df.newDuration(true, 28, 5, DatatypeConstants.FIELD_UNDEFINED,
                DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED,
                DatatypeConstants.FIELD_UNDEFINED);
        addAndRetrieveNativeLiteral(client, graph, duration, duration, "P28Y5M", XMLSchema.DURATION_YEARMONTH);

        // xsd:dayTimeDuration
        duration = df.newDuration(true, DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED,
                16, 1, 15, 37);
        addAndRetrieveNativeLiteral(client, graph, duration, duration, "P16DT1H15M37S",
                XMLSchema.DURATION_DAYTIME);

    } finally {
        if (client != null) {
            client.close();
        }
    }
}

From source file:org.openbel.framework.ws.utils.Converter.java

/**
 * @param objCitation//  ww w  .j  a  v a  2  s  .  co m
 * @return
 */
public static Citation convert(KAMStoreDaoImpl.Citation objCitation) {

    Citation citation = OBJECT_FACTORY.createCitation();
    citation.setCitationType(convert(objCitation.getCitationType()));
    citation.setComment(objCitation.getComment());
    // citation id should not be encrypted, as it has a specific meaning
    citation.setId(objCitation.getId());
    citation.setName(objCitation.getName());

    Date pubdate = objCitation.getPublicationDate();
    if (pubdate != null) {
        try {
            calendar.setTime(pubdate);
            citation.setPublicationDate(DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar));
        } catch (DatatypeConfigurationException e) {
            // Swallowed
        }
    }

    List<String> authors = objCitation.getAuthors();
    if (authors != null) {
        citation.getAuthors().addAll(authors);
    }

    return citation;
}

From source file:org.openbel.framework.ws.utils.Converter.java

/**
 * @param kamInfo//from w ww. j  a  v a 2s  .  c  o m
 * @return
 */
public static Kam convert(KAMCatalogDao.KamInfo kamInfo) {

    Kam kam = OBJECT_FACTORY.createKam();
    try {
        kam.setId(KamStoreObjectRef.encode(kamInfo, kamInfo));
        kam.setDescription(kamInfo.getKamDbObject().getDescription());
        calendar.setTime(kamInfo.getKamDbObject().getLastCompiled());
        kam.setLastCompiled(DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar));
        kam.setName(kamInfo.getKamDbObject().getName());
    } catch (DatatypeConfigurationException e) {
        // Swallowed
    }
    return kam;
}

From source file:org.opencds.dss.evaluate.EvaluationImpl.java

/**
 * //from  w  w w.  j  ava 2 s . c o m
 * @param date as long
 * @return XMLGregorianCalendar
 */
private static XMLGregorianCalendar long2Gregorian(long date) {
    DatatypeFactory dataTypeFactory;
    try {
        dataTypeFactory = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException e) {
        throw new RuntimeException(e);
    }
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTimeInMillis(date);
    return dataTypeFactory.newXMLGregorianCalendar(gc);
}

From source file:org.openmainframe.ade.ext.output.ExtJaxbAnalyzedPeriodV2XmlStorer.java

/**
 * Default constructor/*from   ww w.j  a  v  a2  s .  c  o  m*/
 * @throws AdeException
 */
public ExtJaxbAnalyzedPeriodV2XmlStorer() throws AdeException {
    super();
    m_gc = new GregorianCalendar();
    try {
        s_dataTypeFactory = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException e) {
        throw new AdeInternalException("Failed to instantiate data factory for calendar", e);
    }
}

From source file:org.openmainframe.ade.scores.LastSeenLoggingScorerContinuous.java

/**
 * Creates variables used by this class for tracking last seen messages. 
 * m_prevIntervalTimelineMap contains the previous timeline (milliseconds from epoch time)
 * for each message ID. m_alreadySeen contains the message IDs of those messages that were seen
 * previously. /*from  ww  w  .j  a  v a2 s.co  m*/
 * @throws AdeException
 */
private final void createUsageVariables() throws AdeException {
    String dataObjectName = getAnalysisGroup() + "." + getName() + ".m_prevIntervalTimelineMap";
    Object tmp = Ade.getAde().getDataStore().models().getModelDataObject(dataObjectName);
    instantiateTimelineAndAlreadySeen(dataObjectName, tmp);

    dataObjectName = getAnalysisGroup() + "." + getName() + ".m_alreadySeen";
    tmp = Ade.getAde().getDataStore().models().getModelDataObject(dataObjectName);
    instantiateTimelineAndAlreadySeen(dataObjectName, tmp);

    if (m_dataTypeFactory == null) {
        try {
            m_dataTypeFactory = DatatypeFactory.newInstance();
        } catch (DatatypeConfigurationException e) {
            throw new AdeInternalException("Failed to instantiate data factory for calendar", e);
        }
    }

    if (m_gc == null) {
        final TimeZone outputTimeZone = Ade.getAde().getConfigProperties().getOutputTimeZone();
        m_gc = new GregorianCalendar(outputTimeZone);
    }
}

From source file:org.opennms.netmgt.provision.persist.foreignsource.ForeignSource.java

/**
 * Update the date stamp to the current date and time
 *//*from  w  w  w .j  a  va  2 s . c o  m*/
public void updateDateStamp() {
    try {
        m_dateStamp = DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar());
    } catch (final DatatypeConfigurationException e) {
        LOG.warn("unable to update datestamp", e);
    }
}

From source file:org.opennms.netmgt.provision.persist.requisition.Requisition.java

/**
 * Update the last imported stamp to the current date and time
 *//*from  w  ww. j a va2s  . c om*/
public void updateLastImported() {
    try {
        m_lastImport = DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar());
    } catch (final DatatypeConfigurationException e) {
        LOG.warn("unable to update last import datestamp", e);
    }
}

From source file:org.opennms.netmgt.provision.persist.requisition.Requisition.java

public void setDate(final Date date) {
    final GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(date);//from  w ww  .  j  ava  2 s.  c  o  m
    try {
        setDateStamp(DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar));
    } catch (final DatatypeConfigurationException e) {
        LOG.warn("Failed to turn {} into an XML date.", date);
    }
}

From source file:org.openvpms.esci.adapter.map.order.OrderMapperImpl.java

/**
 * Default constructor./*  w ww  . ja  v  a  2s.  c o  m*/
 */
public OrderMapperImpl() {
    try {
        datatypeFactory = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException exception) {
        throw new IllegalStateException(exception);
    }
}