List of usage examples for javax.xml.datatype DatatypeConstants JULY
int JULY
To view the source code for javax.xml.datatype DatatypeConstants JULY.
Click Source Link
From source file:org.openanzo.test.client.TestDateTime.java
/** * Test that XMLGregorianCalendar objects of various flavors are converted into the appropriate lexical representation with the appropriate datatype. * //from w w w . jav a 2 s . co m * @throws Exception */ public void testXsdTimeRelatedTypeLiteralsBecomeXMLGregorianCalendar() 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 // Without time zone XMLGregorianCalendar cal = df.newXMLGregorianCalendar(2008, DatatypeConstants.JULY, 11, 16, 48, 32, 357, DatatypeConstants.FIELD_UNDEFINED); retrieveLexicalLiteralAsNativeType(client, graph, "2008-07-11T16:48:32.357", XMLSchema.DATETIME, cal); // Without time zone without fractional seconds cal = df.newXMLGregorianCalendar(2008, DatatypeConstants.JULY, 12, 16, 48, 32, DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED); retrieveLexicalLiteralAsNativeType(client, graph, "2008-07-12T16:48:32", XMLSchema.DATETIME, cal); // With time zone cal = df.newXMLGregorianCalendar(2008, DatatypeConstants.JULY, 11, 16, 48, 32, 357, 7 * 60); retrieveLexicalLiteralAsNativeType(client, graph, "2008-07-11T16:48:32.357+07:00", XMLSchema.DATETIME, cal); // With time zone and nanosecond precision cal = df.newXMLGregorianCalendar(BigInteger.valueOf(2008), DatatypeConstants.JULY, 11, 16, 48, 32, BigDecimal.valueOf(123665845, 9), -8 * 60); retrieveLexicalLiteralAsNativeType(client, graph, "2008-07-11T16:48:32.123665845-08:00", XMLSchema.DATETIME, cal); // UTC cal = df.newXMLGregorianCalendar(2008, DatatypeConstants.JULY, 11, 16, 48, 32, 357, 0); retrieveLexicalLiteralAsNativeType(client, graph, "2008-07-11T16:48:32.357Z", XMLSchema.DATETIME, cal); // xsd:date // Without time zone cal = df.newXMLGregorianCalendarDate(2008, DatatypeConstants.JULY, 12, DatatypeConstants.FIELD_UNDEFINED); retrieveLexicalLiteralAsNativeType(client, graph, "2008-07-12", XMLSchema.DATE, cal); // With time zone cal = df.newXMLGregorianCalendarDate(2008, DatatypeConstants.JULY, 11, -8 * 60); retrieveLexicalLiteralAsNativeType(client, graph, "2008-07-11-08:00", XMLSchema.DATE, cal); // xsd:time // Without time zone cal = df.newXMLGregorianCalendarTime(16, 48, 32, 357, DatatypeConstants.FIELD_UNDEFINED); retrieveLexicalLiteralAsNativeType(client, graph, "16:48:32.357", XMLSchema.TIME, cal); // With time zone cal = df.newXMLGregorianCalendarTime(16, 48, 32, 357, 4 * 60); retrieveLexicalLiteralAsNativeType(client, graph, "16:48:32.357+04:00", XMLSchema.TIME, cal); // xsd:gYearMonth // With time zone cal = df.newXMLGregorianCalendarDate(2008, DatatypeConstants.JULY, DatatypeConstants.FIELD_UNDEFINED, -4 * 60); retrieveLexicalLiteralAsNativeType(client, graph, "2008-07-04:00", XMLSchema.GYEARMONTH, cal); // Without time zone cal = df.newXMLGregorianCalendarDate(2008, DatatypeConstants.AUGUST, DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED); retrieveLexicalLiteralAsNativeType(client, graph, "2008-08", XMLSchema.GYEARMONTH, cal); // xsd:gYear // With time zone cal = df.newXMLGregorianCalendarDate(2009, DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED, -6 * 60); retrieveLexicalLiteralAsNativeType(client, graph, "2009-06:00", XMLSchema.GYEAR, cal); // Without time zone cal = df.newXMLGregorianCalendarDate(2010, DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED); retrieveLexicalLiteralAsNativeType(client, graph, "2010", XMLSchema.GYEAR, cal); // xsd:gMonthDay // With time zone cal = df.newXMLGregorianCalendarDate(DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.JULY, 15, -6 * 60); retrieveLexicalLiteralAsNativeType(client, graph, "--07-15-06:00", XMLSchema.GMONTHDAY, cal); // Without time zone cal = df.newXMLGregorianCalendarDate(DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.JULY, 16, DatatypeConstants.FIELD_UNDEFINED); retrieveLexicalLiteralAsNativeType(client, graph, "--07-16", XMLSchema.GMONTHDAY, cal); // xsd:gMonth // With time zone cal = df.newXMLGregorianCalendarDate(DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.AUGUST, DatatypeConstants.FIELD_UNDEFINED, -6 * 60); retrieveLexicalLiteralAsNativeType(client, graph, "--08-06:00", XMLSchema.GMONTH, cal); // Without time zone cal = df.newXMLGregorianCalendarDate(DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.SEPTEMBER, DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED); retrieveLexicalLiteralAsNativeType(client, graph, "--09", XMLSchema.GMONTH, cal); // xsd:gDay // With time zone cal = df.newXMLGregorianCalendarDate(DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED, 15, -6 * 60); retrieveLexicalLiteralAsNativeType(client, graph, "---15-06:00", XMLSchema.GDAY, cal); // Without time zone cal = df.newXMLGregorianCalendarDate(DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED, 16, DatatypeConstants.FIELD_UNDEFINED); retrieveLexicalLiteralAsNativeType(client, graph, "---16", XMLSchema.GDAY, cal); } finally { if (client != null) { client.close(); } } }
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. * //from w ww.j av a 2s.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(); } } }
From source file:org.openanzo.test.client.TestDateTime.java
/** * Test the conversion of java.util.Date objects in the Anzo.java API into xsd:dateTime RDF literals in the UTC time zone. The test will add statements * using java.util.Date objects and verify that when those statements are retrieved, the expected lexical value, datatype, etc. are correct. * // w ww .ja va 2 s . c o m * @throws Exception */ public void testJavaDateBecomesXsdDateTimeInUTCTimeZone() 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(); Date d = new Date(1216330344703L); // Thu Jul 17 17:32:24.703 EDT 2008 which is Thu Jul 17 21:32:24.703 UTC 2008 XMLGregorianCalendar cal = df.newXMLGregorianCalendar(2008, DatatypeConstants.JULY, 17, 21, 32, 24, 703, 0); addAndRetrieveNativeLiteral(client, graph, d, cal, "2008-07-17T21:32:24.703Z", XMLSchema.DATETIME); } finally { if (client != null) { client.close(); } } }
From source file:org.openanzo.test.client.TestDateTime.java
/** * Test the conversion of java.sql.Timestamp objects in the Anzo.java API into xsd:dateTime RDF literals in the UTC time zone. The test will add statements * using java.util.Timestamp objects and verify that when those statements are retrieved, the expected lexical value, datatype, etc. are correct. * //from w w w. j a v a2s . c o m * We also make sure that the nanosecond precision of java.sql.Timestamp objects is maintained. * * @throws Exception */ public void testSqlTimestampBecomesXsdDateTimeInUTCTimeZone() 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(); // Thu Jul 17 17:32:24.336512127 EDT 2008 which is Thu Jul 17 21:32:24.336512127 UTC 2008 Timestamp ts = new Timestamp(1216330344000L); ts.setNanos(336512127); XMLGregorianCalendar cal = df.newXMLGregorianCalendar(BigInteger.valueOf(2008), DatatypeConstants.JULY, 17, 21, 32, 24, BigDecimal.valueOf(336512127, 9), 0); addAndRetrieveNativeLiteral(client, graph, ts, cal, "2008-07-17T21:32:24.336512127Z", XMLSchema.DATETIME); // Thu Jul 17 17:32:24.000000001 EDT 2008 which is Thu Jul 17 21:32:24.000000001 UTC 2008 ts = new Timestamp(1216330344000L); ts.setNanos(1); // If we don't account for some JDK bugs, then this can come out as 2008-07-17T21:32:24.1E-9Z cal = df.newXMLGregorianCalendar(BigInteger.valueOf(2008), DatatypeConstants.JULY, 17, 21, 32, 24, BigDecimal.valueOf(1, 9), 0); addAndRetrieveNativeLiteral(client, graph, ts, cal, "2008-07-17T21:32:24.000000001Z", XMLSchema.DATETIME); } finally { if (client != null) { client.close(); } } }
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.// ww w . j av a 2 s . 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(); } } }