@Override public Object parse(String lexicalForm) throws DatatypeFormatException { return delegate.parse(lexicalForm); }
@Override public Object parse(String lexicalForm) throws DatatypeFormatException { return decoratee.parse(lexicalForm); }
@Override public Object parse(String lexicalForm) throws DatatypeFormatException { return delegate.parse(lexicalForm); }
/** * Internal function to set the object value from the lexical form. * Requires datatype to be set. * @throws DatatypeFormatException if the value is ill-formed and * eager checking is on. */ private void setValue(String lex) throws DatatypeFormatException { try { value = dtype.parse(lex); wellformed = true; } catch (DatatypeFormatException e) { if (JenaParameters.enableEagerLiteralValidation) { e.fillInStackTrace(); throw e; } else { wellformed = false; exceptionMsg = e.getMessage(); } } }
/** * Internal function to set the object value from the lexical form. * Requires datatype to be set. * @throws DatatypeFormatException if the value is ill-formed and * eager checking is on. */ private void setValue(String lex) throws DatatypeFormatException { try { value = dtype.parse(lex); wellformed = true; } catch (DatatypeFormatException e) { if (JenaParameters.enableEagerLiteralValidation) { e.fillInStackTrace(); throw e; } else { wellformed = false; exceptionMsg = e.getMessage(); } } }
@Override public Object createJavaObject(RDFNode node) { Object result; if(node.isLiteral()) { Literal literal = node.asLiteral(); //RDFDatatype nodeDt = literal.getDatatype(); // TODO Make sure that the node datatype/value is actually compatible with this one // I think node datatype must be a sub-type of this one (e.g. nodedt=Student, thisdt=Person) Object tmp = literal.getValue(); String lexicalForm = rdfDatatype.unparse(tmp); result = rdfDatatype.parse(lexicalForm); } else { throw new RuntimeException("Literal node expected, but got: " + node); } return result; }
@Override public Object createJavaObject(RDFNode node) { Object result; if(node.isLiteral()) { Literal literal = node.asLiteral(); //RDFDatatype nodeDt = literal.getDatatype(); // TODO Make sure that the node datatype/value is actually compatible with this one // I think node datatype must be a sub-type of this one (e.g. nodedt=Student, thisdt=Person) Object tmp = literal.getValue(); String lexicalForm = rdfDatatype.unparse(tmp); result = rdfDatatype.parse(lexicalForm); } else { throw new RuntimeException("Literal node expected, but got: " + node); } return result; }
Object o = dt.parse(lex); System.out.println(o.getClass());
item = (org.w3c.dom.Node)xmlDatatype.parse(xmlDatatype.unparse(item));
item = (org.w3c.dom.Node)xmlDatatype.parse(xmlDatatype.unparse(item));
/** * Test a user error report concerning date/time literals */ public void testDateTimeBug() { // Bug in serialization String XSDDateURI = XSD.date.getURI(); TypeMapper typeMapper=TypeMapper.getInstance(); RDFDatatype dt = typeMapper.getSafeTypeByName(XSDDateURI); Object obj = dt.parse("2003-05-21"); Literal literal = m.createTypedLiteral(obj, dt); literal.toString(); Object value2 = dt.parse(obj.toString()); assertEquals(obj, value2); // Check alternative form doesn't provoke exceptions RDFDatatype dateType = XSDDatatype.XSDdate; m.createTypedLiteral("2003-05-21", dateType); // Check alt time times checkSerialization("2003-05-21", XSDDatatype.XSDdate); checkSerialization("2003-05-21T12:56:10Z", XSDDatatype.XSDdateTime); checkSerialization("2003-05", XSDDatatype.XSDgYearMonth); checkSerialization("2003", XSDDatatype.XSDgYear); checkSerialization("--05", XSDDatatype.XSDgMonth); checkSerialization("--05-12", XSDDatatype.XSDgMonthDay); checkSerialization("---12", XSDDatatype.XSDgDay); }
/** * Test a user error report concerning date/time literals */ public void testDateTimeBug() { // Bug in serialization String XSDDateURI = XSD.date.getURI(); TypeMapper typeMapper=TypeMapper.getInstance(); RDFDatatype dt = typeMapper.getSafeTypeByName(XSDDateURI); Object obj = dt.parse("2003-05-21"); Literal literal = m.createTypedLiteral(obj, dt); literal.toString(); Object value2 = dt.parse(obj.toString()); assertEquals(obj, value2); // Check alternative form doesn't provoke exceptions RDFDatatype dateType = XSDDatatype.XSDdate; m.createTypedLiteral("2003-05-21", dateType); // Check alt time times checkSerialization("2003-05-21", XSDDatatype.XSDdate); checkSerialization("2003-05-21T12:56:10Z", XSDDatatype.XSDdateTime); checkSerialization("2003-05", XSDDatatype.XSDgYearMonth); checkSerialization("2003", XSDDatatype.XSDgYear); checkSerialization("--05", XSDDatatype.XSDgMonth); checkSerialization("--05-12", XSDDatatype.XSDgMonthDay); checkSerialization("---12", XSDDatatype.XSDgDay); }