Example usage for javax.xml.datatype DatatypeConstants FIELD_UNDEFINED

List of usage examples for javax.xml.datatype DatatypeConstants FIELD_UNDEFINED

Introduction

In this page you can find the example usage for javax.xml.datatype DatatypeConstants FIELD_UNDEFINED.

Prototype

int FIELD_UNDEFINED

To view the source code for javax.xml.datatype DatatypeConstants FIELD_UNDEFINED.

Click Source Link

Document

Designation that an "int" field is not set.

Usage

From source file:org.openanzo.test.client.TestDateTime.java

/**
 * Test the conversion of javax.xml.datatype.XMLGregorianCalendar objects in the Anzo.java API into various XML Schema-types RDF literals. The test will add
 * statements using javax.xml.datatype.XMLGregorianCalendar objects and verify that when those statements are retrieved, the expected lexical value,
 * datatype, etc. are correct.//from   w  w  w . j  av a 2s . com
 * 
 * @throws Exception
 */
public void testXMLGregorianCalendarBecomesXsdTypedLiterals() 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:dateTime with time zone.
        // With time zone, a literal with a time zone is represented as a java.util.Calendar when it is retrieved even if the input is an XMLGregorianCalendar. 
        XMLGregorianCalendar cal = df.newXMLGregorianCalendar(2008, DatatypeConstants.JULY, 11, 16, 48, 32, 357,
                9 * 60);
        addAndRetrieveNativeLiteral(client, graph, cal, cal, "2008-07-11T16:48:32.357+09:00",
                XMLSchema.DATETIME);
        // Without time zone
        cal = df.newXMLGregorianCalendar(2008, DatatypeConstants.JULY, 12, 16, 48, 32, 357,
                DatatypeConstants.FIELD_UNDEFINED);
        addAndRetrieveNativeLiteral(client, graph, cal, cal, "2008-07-12T16:48:32.357", XMLSchema.DATETIME);

        // xsd:date
        // Without time zone
        cal = df.newXMLGregorianCalendarDate(2008, DatatypeConstants.JULY, 12,
                DatatypeConstants.FIELD_UNDEFINED);
        addAndRetrieveNativeLiteral(client, graph, cal, cal, "2008-07-12", XMLSchema.DATE);
        // With time zone
        cal = df.newXMLGregorianCalendarDate(2008, DatatypeConstants.JULY, 11, -8 * 60);
        addAndRetrieveNativeLiteral(client, graph, cal, cal, "2008-07-11-08:00", XMLSchema.DATE);

        // xsd:time
        // Without time zone
        cal = df.newXMLGregorianCalendarTime(16, 48, 32, 357, DatatypeConstants.FIELD_UNDEFINED);
        addAndRetrieveNativeLiteral(client, graph, cal, cal, "16:48:32.357", XMLSchema.TIME);
        // With time zone
        cal = df.newXMLGregorianCalendarTime(16, 48, 32, 357, 4 * 60);
        addAndRetrieveNativeLiteral(client, graph, cal, cal, "16:48:32.357+04:00", XMLSchema.TIME);

        // xsd:gYearMonth
        // With time zone
        cal = df.newXMLGregorianCalendarDate(2008, DatatypeConstants.JULY, DatatypeConstants.FIELD_UNDEFINED,
                -4 * 60);
        addAndRetrieveNativeLiteral(client, graph, cal, cal, "2008-07-04:00", XMLSchema.GYEARMONTH);
        // Without time zone
        cal = df.newXMLGregorianCalendarDate(2008, DatatypeConstants.AUGUST, DatatypeConstants.FIELD_UNDEFINED,
                DatatypeConstants.FIELD_UNDEFINED);
        addAndRetrieveNativeLiteral(client, graph, cal, cal, "2008-08", XMLSchema.GYEARMONTH);

        // xsd:gYear
        // With time zone
        cal = df.newXMLGregorianCalendarDate(2009, DatatypeConstants.FIELD_UNDEFINED,
                DatatypeConstants.FIELD_UNDEFINED, -6 * 60);
        addAndRetrieveNativeLiteral(client, graph, cal, cal, "2009-06:00", XMLSchema.GYEAR);
        // Without time zone
        cal = df.newXMLGregorianCalendarDate(2010, DatatypeConstants.FIELD_UNDEFINED,
                DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED);
        addAndRetrieveNativeLiteral(client, graph, cal, cal, "2010", XMLSchema.GYEAR);

        // xsd:gMonthDay
        // With time zone
        cal = df.newXMLGregorianCalendarDate(DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.JULY, 15,
                -6 * 60);
        addAndRetrieveNativeLiteral(client, graph, cal, cal, "--07-15-06:00", XMLSchema.GMONTHDAY);
        // Without time zone
        cal = df.newXMLGregorianCalendarDate(DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.JULY, 16,
                DatatypeConstants.FIELD_UNDEFINED);
        addAndRetrieveNativeLiteral(client, graph, cal, cal, "--07-16", XMLSchema.GMONTHDAY);

        // xsd:gMonth
        // With time zone
        cal = df.newXMLGregorianCalendarDate(DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.AUGUST,
                DatatypeConstants.FIELD_UNDEFINED, -6 * 60);
        addAndRetrieveNativeLiteral(client, graph, cal, cal, "--08-06:00", XMLSchema.GMONTH);
        // Without time zone
        cal = df.newXMLGregorianCalendarDate(DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.SEPTEMBER,
                DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED);
        addAndRetrieveNativeLiteral(client, graph, cal, cal, "--09", XMLSchema.GMONTH);

        // xsd:gDay
        // With time zone
        cal = df.newXMLGregorianCalendarDate(DatatypeConstants.FIELD_UNDEFINED,
                DatatypeConstants.FIELD_UNDEFINED, 15, -6 * 60);
        addAndRetrieveNativeLiteral(client, graph, cal, cal, "---15-06:00", XMLSchema.GDAY);
        // Without time zone
        cal = df.newXMLGregorianCalendarDate(DatatypeConstants.FIELD_UNDEFINED,
                DatatypeConstants.FIELD_UNDEFINED, 16, DatatypeConstants.FIELD_UNDEFINED);
        addAndRetrieveNativeLiteral(client, graph, cal, cal, "---16", XMLSchema.GDAY);

        // Invalid XMLGregorianCalendar objects
        // Incomplete data. No XML Schema built-in type allows just an hour. We expect an exception.
        cal = df.newXMLGregorianCalendar();
        cal.setHour(13);
        try {
            Constants.valueFactory.createTypedLiteral(cal);
            fail("Should not get here since previous statement should throw exception.");
        } catch (AnzoRuntimeException e) {
            log.debug("Expected exception.");
        }

        // An XMLGregorianCalendar that has invalid data (February 31st) will go into the
        // system but will not be able to be parsed back into an XMLGregorianCalendar on retrieval.
        cal = df.newXMLGregorianCalendar();
        cal.setDay(31);
        cal.setMonth(DatatypeConstants.FEBRUARY);
        addAndRetrieveNativeLiteral(client, graph, cal, null, "--02-31", XMLSchema.GMONTHDAY);

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

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   w w  w  .  j  a  v  a 2  s .  c  o  m*/
 * @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.orcid.frontend.web.forms.CurrentWork.java

private void setDate() {
    String dateString = crossRefContext.getDate();
    XMLGregorianCalendar cal = DateUtils.convertToXMLGregorianCalendar(dateString);
    if (cal != null) {
        int calYear = cal.getYear();
        if (calYear != DatatypeConstants.FIELD_UNDEFINED) {
            year = String.valueOf(calYear);
        }//www.  j  a  v a  2 s .  com
        int calMonth = cal.getMonth();
        if (calMonth != DatatypeConstants.FIELD_UNDEFINED) {
            month = String.valueOf(calMonth);
        }
        int calDay = cal.getDay();
        if (calDay != DatatypeConstants.FIELD_UNDEFINED) {
            day = String.valueOf(calDay);
        }
    }
}

From source file:org.orcid.frontend.web.forms.Publication.java

public OrcidWork getOrcidWork() {
    initCrossRefContext();/* w ww  . java2  s .c om*/
    OrcidWork orcidWork = new OrcidWork();

    if (StringUtils.isNotBlank(doi)) {
        WorkExternalIdentifier doiExtId = new WorkExternalIdentifier();
        doiExtId.setWorkExternalIdentifierType(WorkExternalIdentifierType.DOI);
        doiExtId.setWorkExternalIdentifierId(new WorkExternalIdentifierId(doi));
        WorkExternalIdentifiers workExtIds = new WorkExternalIdentifiers();
        orcidWork.setWorkExternalIdentifiers(workExtIds);
        workExtIds.getWorkExternalIdentifier().add(doiExtId);
    }

    if (StringUtils.isNotBlank(title)) {
        WorkTitle workTitle = new WorkTitle();
        orcidWork.setWorkTitle(workTitle);
        workTitle.setTitle(new Title(title));
    }

    // Will throw an IllegalArgumentException if not valid
    CitationType cType = CitationType.fromValue(citationType);
    Citation citation = new Citation(fullCitation, cType);
    orcidWork.setWorkCitation(citation);

    String publicationDateString = crossRefContext.getDate();
    if (StringUtils.isNotBlank(publicationDateString)) {
        XMLGregorianCalendar publicationDateGregCal = DateUtils
                .convertToXMLGregorianCalendar(publicationDateString);
        if (publicationDateGregCal != null) {
            Year publicationyear = new Year(publicationDateGregCal.getYear());
            Month publicationMonth = publicationDateGregCal.getMonth() == DatatypeConstants.FIELD_UNDEFINED
                    ? null
                    : new Month(publicationDateGregCal.getMonth());
            Day publicationDay = publicationDateGregCal.getDay() == DatatypeConstants.FIELD_UNDEFINED ? null
                    : new Day(publicationDateGregCal.getDay());
            orcidWork
                    .setPublicationDate(new PublicationDate(publicationyear, publicationMonth, publicationDay));
        }
    }

    String author = crossRefContext.getAuthor();
    if (StringUtils.isNotBlank(author)) {
        WorkContributors workContributors = new WorkContributors();
        orcidWork.setWorkContributors(workContributors);
        Contributor contributor = new Contributor();
        workContributors.getContributor().add(contributor);
        contributor.setCreditName(new CreditName(author));
        ContributorAttributes contributorAttributes = new ContributorAttributes();
        contributor.setContributorAttributes(contributorAttributes);
        contributorAttributes.setContributorRole(ContributorRole.AUTHOR);
        contributorAttributes.setContributorSequence(SequenceType.FIRST);
    }

    return orcidWork;
}

From source file:org.orcid.utils.DateUtils.java

public static XMLGregorianCalendar convertToXMLGregorianCalendarNoTimeZoneNoMillis(Date date) {
    XMLGregorianCalendar basicCalender = convertToXMLGregorianCalendar(date);
    basicCalender.setTimezone(DatatypeConstants.FIELD_UNDEFINED);
    basicCalender.setMillisecond(DatatypeConstants.FIELD_UNDEFINED);
    return basicCalender;
}