if (value instanceof UriRef) {
return valueFactory.createReference((UriRef) value);
} else if (value instanceof PlainLiteral) {
return valueFactory.createText((Literal) value);
} else if (value instanceof TypedLiteral) {
TypedLiteral literal = (TypedLiteral) value;
if (literal.getDataType() == null) { // if no dataType is defined
// return a Text without a language
return valueFactory.createText(literal);
} else {
XsdDataTypeEnum mapping = RdfResourceUtils.XSD_DATATYPE_VALUE_MAPPING.get(literal.getDataType());
if (mapping != null) {
if (mapping.getMappedClass() != null) {
try {
return literalFactory.createObject(mapping.getMappedClass(), literal);
} catch (RuntimeException e){
log.info("Unable to convert Literal value {} to Java Class {} because of {} with message {}",
new Object[]{literal,mapping.getMappedClass().getSimpleName(),
e.getClass().getSimpleName(),e.getMessage()});
log.trace("Exception:",e);
//STANBOL-698: Decide what to do in such cases
//(a) throw an exception
// throw e;
//(b) ignore illegal values
//return null;
//(c) use the lexical form
return literal.getLexicalForm();
}
} else { // if no mapped class
// bypass the LiteralFactory and return the string
// representation
return literal.getLexicalForm();
}
} else { // if dataType is not supported
/*
* this could indicate two things: 1) the SimpleLiteralFactory supports a new DataType and
* because of that it creates Literals with this Type 2) Literals with this data type
* where created by other applications. In the first case one need to update the
* enumeration. In the second case using the LexicalForm should be OK Rupert Westenthaler
* 2010.10.28
*/
log.warn("Missing Mapping for DataType {} -> return String representation",
literal.getDataType().getUnicodeString());
return literal.getLexicalForm();
}
}
} else {
log.warn("Unsupported Resource Type {} -> return String by using the toString method",
value.getClass());