// - xsd:boolean
// - xsd:dateTime
// - xsd:string
// - RDF term (equal and unequal only)
URI leftDatatype = leftLit.getDatatype();
URI rightDatatype = rightLit.getDatatype();
Integer compareResult = null;
if (QueryEvaluationUtil.isStringLiteral(leftLit) && QueryEvaluationUtil.isStringLiteral(rightLit)) {
compareResult = leftLit.getLabel().compareTo(rightLit.getLabel());
}
else if (leftDatatype != null && rightDatatype != null) {
URI commonDatatype = null;
if (leftDatatype.equals(rightDatatype)) {
commonDatatype = leftDatatype;
}
else if (XMLDatatypeUtil.isNumericDatatype(leftDatatype)
&& XMLDatatypeUtil.isNumericDatatype(rightDatatype))
{
// left and right arguments have different datatypes, try to find a
// more general, shared datatype
if (leftDatatype.equals(XMLSchema.DOUBLE) || rightDatatype.equals(XMLSchema.DOUBLE)) {
commonDatatype = XMLSchema.DOUBLE;
}
else if (leftDatatype.equals(XMLSchema.FLOAT) || rightDatatype.equals(XMLSchema.FLOAT)) {
commonDatatype = XMLSchema.FLOAT;
}
else if (leftDatatype.equals(XMLSchema.DECIMAL) || rightDatatype.equals(XMLSchema.DECIMAL)) {
commonDatatype = XMLSchema.DECIMAL;
}
else {
commonDatatype = XMLSchema.INTEGER;
}
}
if (commonDatatype != null) {
try {
if (commonDatatype.equals(XMLSchema.DOUBLE)) {
compareResult = Double.compare(leftLit.doubleValue(), rightLit.doubleValue());
}
else if (commonDatatype.equals(XMLSchema.FLOAT)) {
compareResult = Float.compare(leftLit.floatValue(), rightLit.floatValue());
}
else if (commonDatatype.equals(XMLSchema.DECIMAL)) {
compareResult = leftLit.decimalValue().compareTo(rightLit.decimalValue());
}
else if (XMLDatatypeUtil.isIntegerDatatype(commonDatatype)) {
compareResult = leftLit.integerValue().compareTo(rightLit.integerValue());
}
else if (commonDatatype.equals(XMLSchema.BOOLEAN)) {
Boolean leftBool = Boolean.valueOf(leftLit.booleanValue());
Boolean rightBool = Boolean.valueOf(rightLit.booleanValue());
compareResult = leftBool.compareTo(rightBool);
}
else if (XMLDatatypeUtil.isCalendarDatatype(commonDatatype)) {
XMLGregorianCalendar left = leftLit.calendarValue();
XMLGregorianCalendar right = rightLit.calendarValue();
compareResult = left.compare(right);
// Note: XMLGregorianCalendar.compare() returns compatible
// values
// (-1, 0, 1) but INDETERMINATE needs special treatment
if (compareResult == DatatypeConstants.INDETERMINATE) {
throw new ValueExprEvaluationException("Indeterminate result for date/time comparison");
}
}
else if (commonDatatype.equals(XMLSchema.STRING)) {
compareResult = leftLit.getLabel().compareTo(rightLit.getLabel());
}
}
catch (IllegalArgumentException e) {
// One of the basic-type method calls failed, try syntactic match