}
}
private static NodeId inline$(Node node)
{
LiteralLabel lit = node.getLiteral() ;
// Decimal is a valid supertype of integer but we handle integers and decimals differently.
if ( node.getLiteralDatatype().equals(XSDDatatype.XSDdecimal) )
{
// Check lexical form.
if ( ! XSDDatatype.XSDdecimal.isValidLiteral(lit) )
return null ;
// Not lit.getValue() because that may be a narrower type e.g. Integer.
// .trim is how Jena does it but it rather savage. spc, \n \r \t.
// But at this point we know it's a valid literal so the excessive
// chopping by .trim is safe.
BigDecimal decimal = new BigDecimal(lit.getLexicalForm().trim()) ;
// Does range checking.
DecimalNode dn = DecimalNode.valueOf(decimal) ;
// null is "does not fit"
if ( dn != null )
// setType
return new NodeId(dn.pack()) ;
else
return null ;
}
else // Not decimal.
{
if ( XSDDatatype.XSDinteger.isValidLiteral(lit) )
{
// Check length of lexical form to see if it's in range of a long.
// Long.MAX_VALUE = 9223372036854775807
// Long.MIN_VALUE = -9223372036854775808
// 9,223,372,036,854,775,807 is 19 digits.
if ( lit.getLexicalForm().length() > 19 )
return null ;
try {
long v = ((Number)lit.getValue()).longValue() ;
v = IntegerNode.pack(v) ;
// Value -1 is "does not fit"
if ( v != -1 )
return new NodeId(v) ;
else
return null ;
}
// Out of range for the type, not a long etc etc.
catch (Throwable ex) { return null ; }
}
}
if ( XSDDatatype.XSDdateTime.isValidLiteral(lit) )
{
// Could use the Jena/XSDDateTime object here rather than reparse the lexical form.
// But this works and it's close to a release ...
long v = DateTimeNode.packDateTime(lit.getLexicalForm()) ;
if ( v == -1 )
return null ;
v = setType(v, DATETIME) ;
return new NodeId(v) ;
}
if ( XSDDatatype.XSDdate.isValidLiteral(lit) )
{
long v = DateTimeNode.packDate(lit.getLexicalForm()) ;
if ( v == -1 )
return null ;
v = setType(v, DATE) ;
return new NodeId(v) ;
}
if ( XSDDatatype.XSDboolean.isValidLiteral(lit) )
{
long v = 0 ;
boolean b = ((Boolean)lit.getValue()).booleanValue() ;
//return new NodeValueBoolean(b, node) ;
v = setType(v, BOOLEAN) ;
if ( b )
v = v | 0x01 ;
return new NodeId(v) ;