@Test public void testCastUnknownDatatypedLiteral() { String lexVal = "foobar"; Literal dtLit = f.createLiteral(lexVal, f.createIRI("foo:unknownDt")); try { Literal result = stringCast.evaluate(f, dtLit); assertNotNull(result); assertEquals(XMLSchema.STRING, result.getDatatype()); assertFalse(result.getLanguage().isPresent()); assertEquals(lexVal, result.getLabel()); } catch (ValueExprEvaluationException e) { fail(e.getMessage()); } }
@Override public Literal evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { if (args.length != 1) { throw new ValueExprEvaluationException( getXsdName() + " cast requires exactly 1 argument, got " + args.length); } if (args[0] instanceof Literal) { Literal literal = (Literal) args[0]; IRI datatype = literal.getDatatype(); if (QueryEvaluationUtil.isSimpleLiteral(literal)) { String lexicalValue = XMLDatatypeUtil.collapseWhiteSpace(literal.getLabel()); if (isValidForDatatype(lexicalValue)) { return valueFactory.createLiteral(lexicalValue, getXsdDatatype()); } } else if (datatype != null) { if (datatype.equals(getXsdDatatype())) { return literal; } } return convert(valueFactory, literal); } else { return convert(valueFactory, args[0]); } }
StringCast extends CastFunction { @Override public Literal evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { if (args.length != 1) { throw new ValueExprEvaluationException( getXsdName() + " cast requires exactly 1 argument, got " + args.length); } if (args[0] instanceof Literal) { Literal literal = (Literal) args[0]; IRI datatype = literal.getDatatype(); if (QueryEvaluationUtil.isSimpleLiteral(literal)) { String lexicalValue = XMLDatatypeUtil.collapseWhiteSpace(literal.getLabel()); if (isValidForDatatype(lexicalValue)) { return valueFactory.createLiteral(lexicalValue, getXsdDatatype()); } } else if (datatype != null) { if (datatype.equals(getXsdDatatype())) { return literal; } } return convert(valueFactory, literal); } else { return convert(valueFactory, args[0]); } } }
StringCast extends CastFunction { @Override public Literal evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { if (args.length != 1) { throw new ValueExprEvaluationException( getXsdName() + " cast requires exactly 1 argument, got " + args.length); } if (args[0] instanceof Literal) { Literal literal = (Literal) args[0]; IRI datatype = literal.getDatatype(); if (QueryEvaluationUtil.isSimpleLiteral(literal)) { String lexicalValue = XMLDatatypeUtil.collapseWhiteSpace(literal.getLabel()); if (isValidForDatatype(lexicalValue)) { return valueFactory.createLiteral(lexicalValue, getXsdDatatype()); } } else if (datatype != null) { if (datatype.equals(getXsdDatatype())) { return literal; } } return convert(valueFactory, literal); } else { return convert(valueFactory, args[0]); } }  }
StringCast extends CastFunction { @Override public Literal evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { if (args.length != 1) { throw new ValueExprEvaluationException( getXsdName() + " cast requires exactly 1 argument, got " + args.length); } if (args[0] instanceof Literal) { Literal literal = (Literal) args[0]; IRI datatype = literal.getDatatype(); if (QueryEvaluationUtil.isSimpleLiteral(literal)) { String lexicalValue = XMLDatatypeUtil.collapseWhiteSpace(literal.getLabel()); if (isValidForDatatype(lexicalValue)) { return valueFactory.createLiteral(lexicalValue, getXsdDatatype()); } } else if (datatype != null) { if (datatype.equals(getXsdDatatype())) { return literal; } } return convert(valueFactory, literal); } else { return convert(valueFactory, args[0]); } }  @Override Literal evaluate(ValueFactory valueFactory, Value... args); }
StringCast extends CastFunction { @Override public Literal evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { if (args.length != 1) { throw new ValueExprEvaluationException( getXsdName() + " cast requires exactly 1 argument, got " + args.length); } if (args[0] instanceof Literal) { Literal literal = (Literal) args[0]; IRI datatype = literal.getDatatype(); if (QueryEvaluationUtil.isSimpleLiteral(literal)) { String lexicalValue = XMLDatatypeUtil.collapseWhiteSpace(literal.getLabel()); if (isValidForDatatype(lexicalValue)) { return valueFactory.createLiteral(lexicalValue, getXsdDatatype()); } } else if (datatype != null) { if (datatype.equals(getXsdDatatype())) { return literal; } } return convert(valueFactory, literal); } else { return convert(valueFactory, args[0]); } }  @Override Literal evaluate(ValueFactory valueFactory, Value... args);  }