Example usage for javax.xml.datatype DatatypeConstants JANUARY

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

Introduction

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

Prototype

int JANUARY

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

Click Source Link

Document

Value for first month of year.

Usage

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

/**
 * Test the conversion of java.util.Calendar objects in the Anzo.java API into xsd:dateTime RDF literals with time zones. The test will add statements using
 * java.util.Calendar objects and verify that when those statements are retrieved, the expected lexical value, datatype, etc. are correct.
 * // w  w  w  . ja v  a 2  s  .  c  o  m
 * @throws Exception
 */
public void testCalendarBecomesXsdDateTime() 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();

        // UTC
        Calendar cal = getCleanCalendar();
        cal.set(2008, Calendar.JULY, 11, 16, 48, 32);
        XMLGregorianCalendar xmlcal = df.newXMLGregorianCalendar(2008, DatatypeConstants.JULY, 11, 16, 48, 32,
                DatatypeConstants.FIELD_UNDEFINED, 0);
        addAndRetrieveNativeLiteral(client, graph, cal, xmlcal, "2008-07-11T16:48:32Z", XMLSchema.DATETIME);

        // Time zone offset
        cal = getCleanCalendar();
        cal.set(2008, Calendar.JULY, 11, 16, 48, 32);
        cal.setTimeZone(TimeZone.getTimeZone("GMT-09:00"));
        xmlcal = df.newXMLGregorianCalendar(2008, DatatypeConstants.JULY, 11, 16, 48, 32,
                DatatypeConstants.FIELD_UNDEFINED, -9 * 60);
        addAndRetrieveNativeLiteral(client, graph, cal, xmlcal, "2008-07-11T16:48:32-09:00",
                XMLSchema.DATETIME);

        // Fractional seconds
        cal = getCleanCalendar();
        cal.set(2008, Calendar.JULY, 11, 16, 48, 32);
        cal.set(Calendar.MILLISECOND, 357);
        cal.setTimeZone(TimeZone.getTimeZone("GMT-03:00"));
        xmlcal = df.newXMLGregorianCalendar(2008, DatatypeConstants.JULY, 11, 16, 48, 32, 357, -3 * 60);
        addAndRetrieveNativeLiteral(client, graph, cal, xmlcal, "2008-07-11T16:48:32.357-03:00",
                XMLSchema.DATETIME);

        // A partially filled Calendar still ends up as a fully specified xsd:dateTime with the default values
        // used for unspecified fields (i.e. 0 for time fields, January for month, 1 for day of month, etc.) 
        cal = getCleanCalendar();
        cal.set(2008, Calendar.JULY, 11);
        cal.setTimeZone(TimeZone.getTimeZone("GMT-03:00"));
        xmlcal = df.newXMLGregorianCalendar(2008, DatatypeConstants.JULY, 11, 0, 0, 0,
                DatatypeConstants.FIELD_UNDEFINED, -3 * 60);
        addAndRetrieveNativeLiteral(client, graph, cal, xmlcal, "2008-07-11T00:00:00-03:00",
                XMLSchema.DATETIME);

        // Another partially filled Calendar. 
        cal = getCleanCalendar();
        cal.set(Calendar.YEAR, 2012);
        xmlcal = df.newXMLGregorianCalendar(2012, DatatypeConstants.JANUARY, 1, 0, 0, 0,
                DatatypeConstants.FIELD_UNDEFINED, 0);
        addAndRetrieveNativeLiteral(client, graph, cal, xmlcal, "2012-01-01T00:00:00Z", XMLSchema.DATETIME);

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