/** * Return the datatype of the literal. This will be null in the case of * plain literals. */ @Override public RDFDatatype getDatatype() throws ReadDeniedException, AuthenticationRequiredException { checkRead(); return holder.getBaseItem().getDatatype(); }
public void testCreateTypedLiteral() { final Literal l = ResourceFactory.createTypedLiteral("22", XSDDatatype.XSDinteger); Assert.assertTrue(l.getLexicalForm().equals("22")); Assert.assertTrue(l.getLanguage().equals("")); Assert.assertTrue(l.getDatatype() == XSDDatatype.XSDinteger); Assert.assertTrue(l.getDatatypeURI().equals( XSDDatatype.XSDinteger.getURI())); }
public void testRDFLangString_2() { // "abc"^^rdf:langString (no language tag) Literal ll1 = m.createTypedLiteral("abc", RDFLangString.rdfLangString) ; assertEquals("", ll1.getLanguage()) ; Literal ll2 = m.createLiteral("xyz", "en") ; if ( JenaRuntime.isRDF11 ) assertTrue(ll1.getDatatype() == ll2.getDatatype()) ; else assertTrue(ll1.getDatatype() != ll2.getDatatype()) ; }
public void testCreateTypedLiteral() { final Literal l = ResourceFactory.createTypedLiteral("22", XSDDatatype.XSDinteger); Assert.assertTrue(l.getLexicalForm().equals("22")); Assert.assertTrue(l.getLanguage().equals("")); Assert.assertTrue(l.getDatatype() == XSDDatatype.XSDinteger); Assert.assertTrue(l.getDatatypeURI().equals( XSDDatatype.XSDinteger.getURI())); }
@Override public Literal inModel(final Model m) throws ReadDeniedException, AuthenticationRequiredException { checkRead(); return m.createTypedLiteral(holder.getBaseItem().getLexicalForm(), holder.getBaseItem().getDatatype()); }
public void testCreateLiteral() { final Literal l = ResourceFactory.createPlainLiteral("lex"); Assert.assertTrue(l.getLexicalForm().equals("lex")); Assert.assertTrue(l.getLanguage().equals("")); Assert.assertNull(l.getDatatype()); Assert.assertNull(l.getDatatypeURI()); }
public void testDateTime_17() { // Creation of datetime from a date object Calendar ncal = new GregorianCalendar(TimeZone.getTimeZone("GMT")); ncal.set(2003, 11, 8, 10, 50, 42); ncal.set(Calendar.MILLISECOND, 0); Literal l1 = m.createTypedLiteral(ncal); assertEquals("DateTime from date", XSDDatatype.XSDdateTime, l1.getDatatype()); assertEquals("DateTime from date", XSDDateTime.class, l1.getValue().getClass()); assertEquals("DateTime from date", "2003-12-08T10:50:42Z", l1.getValue().toString()); }
private static void testCalendarRT(long value) { Calendar cal=GregorianCalendar.getInstance(); cal.setTimeInMillis(value); Literal lit1 = ResourceFactory.createTypedLiteral(cal) ; Literal lit2 = ResourceFactory.createTypedLiteral(lit1.getLexicalForm(), lit1.getDatatype()) ; Assert.assertEquals("equals: ", lit1, lit2) ; Assert.assertEquals("hash code: ", lit1.hashCode(), lit2.hashCode()); }
public void testDateTime_17() { // Creation of datetime from a date object Calendar ncal = new GregorianCalendar(TimeZone.getTimeZone("GMT")); ncal.set(2003, 11, 8, 10, 50, 42); ncal.set(Calendar.MILLISECOND, 0); Literal l1 = m.createTypedLiteral(ncal); assertEquals("DateTime from date", XSDDatatype.XSDdateTime, l1.getDatatype()); assertEquals("DateTime from date", XSDDateTime.class, l1.getValue().getClass()); assertEquals("DateTime from date", "2003-12-08T10:50:42Z", l1.getValue().toString()); }
/** * Test ability to override an apparent DateTime to be just a date */ public void testDateOverride() { Calendar date = new GregorianCalendar(2007, 3, 4); date.setTimeZone( TimeZone.getTimeZone("GMT+0") ); XSDDateTime xsdDate = new XSDDateTime( date ); Literal l1 = m.createTypedLiteral(xsdDate, XSDDatatype.XSDdate); assertEquals(XSDDatatype.XSDdate, l1.getDatatype()); assertEquals("2007-04-04Z", l1.getLexicalForm()); }
/** * Check can legally construct a literal with given lex, value and dtype */ public void checkLegalLiteral(String lex, RDFDatatype dtype, Class<?> jtype, Object value) { Literal l = m.createTypedLiteral(lex, dtype); assertEquals(l.getValue().getClass(), jtype); assertEquals(l.getValue(), value); assertEquals(l.getDatatype(), dtype); }
/** * Check can legally construct a literal with given lex, value and dtype */ public void checkLegalLiteral(String lex, RDFDatatype dtype, Class<?> jtype, Object value) { Literal l = m.createTypedLiteral(lex, dtype); assertEquals(l.getValue().getClass(), jtype); assertEquals(l.getValue(), value); assertEquals(l.getDatatype(), dtype); }
public void testCreateTypedLiteralObject() { final Literal l = ResourceFactory.createTypedLiteral( 22 ); Assert.assertEquals("22", l.getLexicalForm()); Assert.assertEquals("", l.getLanguage()); Assert.assertEquals(XSDDatatype.XSDint, l.getDatatype()); }
public void testDateTime_14() { Literal l1 = m.createTypedLiteral("--05--", XSDDatatype.XSDgMonth); assertEquals("dateTime data type", XSDDatatype.XSDgMonth, l1.getDatatype()); assertEquals("dateTime java type", XSDDateTime.class, l1.getValue().getClass()); XSDDateTime xdt = (XSDDateTime)l1.getValue(); assertEquals("dateTime value", 5, xdt.getMonths()); try { xdt.getYears(); assertTrue("Failed to prevent illegal access", false); } catch (IllegalDateTimeFieldException e) {} }
public void testDateTime_16() { Literal l1 = m.createTypedLiteral("---25", XSDDatatype.XSDgDay); assertEquals("dateTime data type", XSDDatatype.XSDgDay, l1.getDatatype()); assertEquals("dateTime java type", XSDDateTime.class, l1.getValue().getClass()); XSDDateTime xdt = (XSDDateTime)l1.getValue(); assertEquals("dateTime value", 25, xdt.getDays()); try { xdt.getMonths(); assertTrue("Failed to prevent illegal access", false); } catch (IllegalDateTimeFieldException e) {} }
public void testDateTime_13() { Literal l1 = m.createTypedLiteral("1999", XSDDatatype.XSDgYear); assertEquals("dateTime data type", XSDDatatype.XSDgYear, l1.getDatatype()); assertEquals("dateTime java type", XSDDateTime.class, l1.getValue().getClass()); XSDDateTime xdt = (XSDDateTime)l1.getValue(); assertEquals("dateTime value", 1999, xdt.getYears()); try { xdt.getMonths(); assertTrue("Failed to prevent illegal access", false); } catch (IllegalDateTimeFieldException e) {} // gMonth }
public void testDateTime_13() { Literal l1 = m.createTypedLiteral("1999", XSDDatatype.XSDgYear); assertEquals("dateTime data type", XSDDatatype.XSDgYear, l1.getDatatype()); assertEquals("dateTime java type", XSDDateTime.class, l1.getValue().getClass()); XSDDateTime xdt = (XSDDateTime)l1.getValue(); assertEquals("dateTime value", 1999, xdt.getYears()); try { xdt.getMonths(); assertTrue("Failed to prevent illegal access", false); } catch (IllegalDateTimeFieldException e) {} // gMonth }
public void testDateTime_15() { Literal l1 = m.createTypedLiteral("--05-25", XSDDatatype.XSDgMonthDay); assertEquals("dateTime data type", XSDDatatype.XSDgMonthDay, l1.getDatatype()); assertEquals("dateTime java type", XSDDateTime.class, l1.getValue().getClass()); XSDDateTime xdt = (XSDDateTime)l1.getValue(); assertEquals("dateTime value", 5, xdt.getMonths()); assertEquals("dateTime value", 25, xdt.getDays()); try { xdt.getYears(); assertTrue("Failed to prevent illegal access", false); } catch (IllegalDateTimeFieldException e) {} }
public void testDateTime_3() { Literal l1 = m.createTypedLiteral("P1Y", XSDDatatype.XSDduration); assertEquals("duration data type", XSDDatatype.XSDduration, l1.getDatatype()); assertEquals("duration java type", XSDDuration.class, l1.getValue().getClass()); assertEquals("duration value", 1, ((XSDDuration)l1.getValue()).getYears()); assertEquals("serialization", "P1Y", l1.getValue().toString()); assertTrue("equality test", l1.sameValueAs( m.createTypedLiteral("P1Y", XSDDatatype.XSDduration) ) ); assertTrue("inequality test", l1 != m.createTypedLiteral("P1Y", XSDDatatype.XSDduration)); } public void testDateTime_4() {
public void testDateTime_3() { Literal l1 = m.createTypedLiteral("P1Y", XSDDatatype.XSDduration); assertEquals("duration data type", XSDDatatype.XSDduration, l1.getDatatype()); assertEquals("duration java type", XSDDuration.class, l1.getValue().getClass()); assertEquals("duration value", 1, ((XSDDuration)l1.getValue()).getYears()); assertEquals("serialization", "P1Y", l1.getValue().toString()); assertTrue("equality test", l1.sameValueAs( m.createTypedLiteral("P1Y", XSDDatatype.XSDduration) ) ); assertTrue("inequality test", l1 != m.createTypedLiteral("P1Y", XSDDatatype.XSDduration)); } public void testDateTime_4() {