}
// Returns null for unrecognized literal.
private static NodeValue _setByValue(Node node)
{
LiteralLabel lit = node.getLiteral() ;
// 50% of the time of this method is in isValidLiteral and the lexcial form parsing.
try { // DatatypeFormatException - should not happen
if ( sameValueAsString && XSDDatatype.XSDstring.isValidLiteral(node.getLiteral()) )
// String - plain or xsd:string
return new NodeValueString(lit.getLexicalForm(), node) ;
// Otherwise xsd:string is like any other unknown datatype.
// Ditto literals with language tags (which are handled by nodeToNodeValue)
// isValidLiteral is a value test - not a syntactic test.
// This makes a difference in that "1"^^xsd:decimal" is a
// valid literal for xsd:integer (all other cases are subtypes of xsd:integer)
// which we want to become integer anyway).
// Order here is promotion order integer-decimal-float-double
if ( ! node.getLiteralDatatype().equals(XSDDatatype.XSDdecimal) )
{
if ( XSDDatatype.XSDinteger.isValidLiteral(lit) )
{
String s = node.getLiteralLexicalForm() ;
if ( s.startsWith("+") )
// BigInteger does not accept leading "+"
s = s.substring(1) ;
// Includes subtypes (int, byte, postiveInteger etc).
// NB Known to be valid for type by now
BigInteger integer = new BigInteger(s) ;
return new NodeValueInteger(integer, node) ;
}
}
if ( XSDDatatype.XSDdecimal.isValidLiteral(lit) )
{
BigDecimal decimal = new BigDecimal(lit.getLexicalForm()) ;
return new NodeValueDecimal(decimal, node) ;
}
if ( XSDDatatype.XSDfloat.isValidLiteral(lit) )
{
// NB If needed, call to floatValue, then assign to double.
// Gets 1.3f != 1.3d right
float f = ((Number)lit.getValue()).floatValue() ;
return new NodeValueFloat(f, node) ;
}
if ( XSDDatatype.XSDdouble.isValidLiteral(lit) )
{
double d = ((Number)lit.getValue()).doubleValue() ;
return new NodeValueDouble(d, node) ;
}
if ( XSDDatatype.XSDdateTime.isValidLiteral(lit) )
{
XSDDateTime dateTime = (XSDDateTime)lit.getValue() ;
return new NodeValueDateTime(dateTime, node) ;
}
if ( XSDDatatype.XSDdate.isValidLiteral(lit) )
{
// Jena datatype support works on masked dataTimes.
XSDDateTime dateTime = (XSDDateTime)lit.getValue() ;
return new NodeValueDate(dateTime, node) ;
}
if ( XSDDatatype.XSDtime.isValidLiteral(lit) )
{
// Jena datatype support works on masked dataTimes.
XSDDateTime time = (XSDDateTime)lit.getValue() ;
return new NodeValueTime(time, node) ;
}
if ( XSDDatatype.XSDgYear.isValidLiteral(lit) )
{
XSDDateTime time = (XSDDateTime)lit.getValue() ;
return new NodeValueGYear(time, node) ;
}
if ( XSDDatatype.XSDgYearMonth.isValidLiteral(lit) )
{
XSDDateTime time = (XSDDateTime)lit.getValue() ;
return new NodeValueGYearMonth(time, node) ;
}
if ( XSDDatatype.XSDgMonth.isValidLiteral(lit) )
{
XSDDateTime time = (XSDDateTime)lit.getValue() ;
return new NodeValueGMonth(time, node) ;
}
if ( XSDDatatype.XSDgMonthDay.isValidLiteral(lit) )
{
XSDDateTime time = (XSDDateTime)lit.getValue() ;
return new NodeValueGMonthDay(time, node) ;
}
if ( XSDDatatype.XSDgDay.isValidLiteral(lit) )
{
XSDDateTime time = (XSDDateTime)lit.getValue() ;
return new NodeValueGDay(time, node) ;
}
if ( XSDDatatype.XSDduration.isValidLiteral(lit) )
{
XSDDuration duration = (XSDDuration)lit.getValue() ;
return new NodeValueDuration(duration, node) ;
}
if ( XSDDatatype.XSDboolean.isValidLiteral(lit) )
{
boolean b = ((Boolean)lit.getValue()).booleanValue() ;
return new NodeValueBoolean(b, node) ;
}
// If wired into the TypeMapper via RomanNumeralDatatype.enableAsFirstClassDatatype
// if ( RomanNumeralDatatype.get().isValidLiteral(lit) )
// {
// int i = ((RomanNumeral)lit.getValue()).intValue() ;
// return new NodeValueInteger(i) ;
// }
// Not wired in
if ( enableRomanNumerals.getValue() )
{
if ( lit.getDatatypeURI().equals(RomanNumeralDatatype.get().getURI()) )
{
Object obj = RomanNumeralDatatype.get().parse(lit.getLexicalForm()) ;
if ( obj instanceof Integer )
return new NodeValueInteger(((Integer)obj).longValue()) ;
if ( obj instanceof RomanNumeral )
return new NodeValueInteger( ((RomanNumeral)obj).intValue() ) ;
throw new ARQInternalErrorException("DatatypeFormatException: Roman numeral is unknown class") ;