public int compareTo(Collator collator, AtomicValue other) throws XPathException { if (other.getType() == getType()) { // filling in missing timezones with local timezone, should be total order as per XPath 2.0 // 10.4 int r = getImplicitCalendar().compare(((AbstractDateTimeValue) other).getImplicitCalendar()); if (r == DatatypeConstants.INDETERMINATE) throw new RuntimeException("indeterminate order between " + this + " and " + other); return r; } throw new XPathException( "Type error: cannot compare " + Type.getTypeName(getType()) + " to " + Type.getTypeName(other.getType())); }
/* (non-Javadoc) * @see org.exist.xquery.value.AtomicValue#compareTo(int, org.exist.xquery.value.AtomicValue) */ public boolean compareTo(Collator collator, int operator, AtomicValue other) throws XPathException { if (other.isEmpty()) return false; if (Type.subTypeOf(other.getType(), Type.STRING) || Type.subTypeOf(other.getType(), Type.UNTYPED_ATOMIC)) { int cmp = Collations.compare(collator, value, other.getStringValue()); switch (operator) { case Constants.EQ: return cmp == 0; case Constants.NEQ: return cmp != 0; case Constants.LT: return cmp < 0; case Constants.LTEQ: return cmp <= 0; case Constants.GT: return cmp > 0; case Constants.GTEQ: return cmp >= 0; default: throw new XPathException("Type error: cannot apply operand to string value"); } } throw new XPathException( "Type error: operands are not comparable; expected xdt:untypedAtomic; got " + Type.getTypeName(other.getType())); }
// override for xs:time public ComputableValue plus(ComputableValue other) throws XPathException { switch (other.getType()) { case Type.YEAR_MONTH_DURATION: case Type.DAY_TIME_DURATION: return other.plus(this); default: throw new XPathException( "Operand to plus should be of type xdt:dayTimeDuration or xdt:yearMonthDuration; got: " + Type.getTypeName(other.getType())); } }
public Object toJavaObject(Class target) throws XPathException { if (target == Object.class || target.isAssignableFrom(DateValue.class)) return this; else if (target.isAssignableFrom(XMLGregorianCalendar.class)) return calendar.clone(); else if (target.isAssignableFrom(GregorianCalendar.class)) return calendar.toGregorianCalendar(); else if (target == Date.class) return calendar.toGregorianCalendar().getTime(); throw new XPathException( "cannot convert value of type " + Type.getTypeName(getType()) + " to Java object of type " + target.getName()); }
public AtomicValue convertTo(int requiredType) throws XPathException { switch (requiredType) { case Type.GDAY: case Type.ATOMIC: case Type.ITEM: return this; case Type.STRING: return new StringValue(getStringValue()); case Type.UNTYPED_ATOMIC: return new UntypedAtomicValue(getStringValue()); default: throw new XPathException( "Type error: cannot cast xs:time to " + Type.getTypeName(requiredType)); } }
public int compareTo(Collator collator, AtomicValue other) throws XPathException { if (other.getType() == getType()) { if (!getTimezone().isEmpty()) { if (!((AbstractDateTimeValue) other).getTimezone().isEmpty()) { if (!((DayTimeDurationValue) getTimezone().itemAt(0)) .compareTo( null, Constants.EQ, (DayTimeDurationValue) ((AbstractDateTimeValue) other).getTimezone().itemAt(0))) return DatatypeConstants.LESSER; } else { if (!((DayTimeDurationValue) getTimezone().itemAt(0)).getStringValue().equals("PT0S")) return DatatypeConstants.LESSER; } } else { if (!((AbstractDateTimeValue) other).getTimezone().isEmpty()) { if (!((DayTimeDurationValue) ((AbstractDateTimeValue) other).getTimezone().itemAt(0)) .getStringValue() .equals("PT0S")) return DatatypeConstants.LESSER; } } // filling in missing timezones with local timezone, should be total order as per XPath 2.0 // 10.4 int r = this.getImplicitCalendar().compare(((AbstractDateTimeValue) other).getImplicitCalendar()); // getImplicitCalendar().compare(((AbstractDateTimeValue) other).getImplicitCalendar()); if (r == DatatypeConstants.INDETERMINATE) throw new RuntimeException("indeterminate order between " + this + " and " + other); return r; } throw new XPathException( "Type error: cannot compare " + Type.getTypeName(getType()) + " to " + Type.getTypeName(other.getType())); }
public MemoryNodeSet toMemNodeSet() throws XPathException { if (count == 0) { return MemoryNodeSet.EMPTY; } if (itemType == Type.ANY_TYPE || !Type.subTypeOf(itemType, Type.NODE)) { throw new XPathException( "Type error: the sequence cannot be converted into" + " a node set. Item type is " + Type.getTypeName(itemType)); } NodeValue v; for (int i = 0; i <= count; i++) { v = (NodeValue) items[i]; if (v.getImplementationType() == NodeValue.PERSISTENT_NODE) { return null; } } return new ValueSequence(this); }
/* (non-Javadoc) * @see org.exist.xquery.value.Item#toJavaObject(java.lang.Class) */ public Object toJavaObject(Class target) throws XPathException { if (target.isAssignableFrom(UntypedAtomicValue.class)) return this; else if (target == Object.class || target == String.class || target == CharSequence.class) return value; else if (target == double.class || target == Double.class) { DoubleValue v = (DoubleValue) convertTo(Type.DOUBLE); return new Double(v.getValue()); } else if (target == float.class || target == Float.class) { FloatValue v = (FloatValue) convertTo(Type.FLOAT); return new Float(v.value); } else if (target == long.class || target == Long.class) { IntegerValue v = (IntegerValue) convertTo(Type.LONG); return new Long(v.getInt()); } else if (target == int.class || target == Integer.class) { IntegerValue v = (IntegerValue) convertTo(Type.INT); return new Integer(v.getInt()); } else if (target == short.class || target == Short.class) { IntegerValue v = (IntegerValue) convertTo(Type.SHORT); return new Short((short) v.getInt()); } else if (target == byte.class || target == Byte.class) { IntegerValue v = (IntegerValue) convertTo(Type.BYTE); return new Byte((byte) v.getInt()); } else if (target == boolean.class || target == Boolean.class) { return Boolean.valueOf(effectiveBooleanValue()); } else if (target == char.class || target == Character.class) { if (value.length() > 1 || value.length() == 0) throw new XPathException( "cannot convert string with length = 0 or length > 1 to Java character"); return new Character(value.charAt(0)); } throw new XPathException( "cannot convert value of type " + Type.getTypeName(getType()) + " to Java object of type " + target.getName()); }
/* (non-Javadoc) * @see org.exist.xquery.value.Sequence#toNodeSet() */ public NodeSet toNodeSet() throws XPathException { // for this method to work, all items have to be nodes if (itemType != Type.ANY_TYPE && Type.subTypeOf(itemType, Type.NODE)) { final NodeSet set = new ExtArrayNodeSet(); // We can't make it from an ExtArrayNodeSet (probably because it is sorted ?) // NodeSet set = new ArraySet(100); for (int i = 0; i < this.count; i++) { NodeValue v = null; final Entry temp = items[i]; v = (NodeValue) temp.item; if (v.getImplementationType() != NodeValue.PERSISTENT_NODE) { set.add((NodeProxy) v); } else { set.add((NodeProxy) v); } } return set; } else { throw new XPathException( "Type error: the sequence cannot be converted into" + " a node set. Item type is " + Type.getTypeName(itemType)); } }
/* (non-Javadoc) * @see org.exist.xquery.value.Sequence#convertTo(int) */ public AtomicValue convertTo(int requiredType) throws XPathException { switch (requiredType) { case Type.ATOMIC: case Type.ITEM: case Type.UNTYPED_ATOMIC: return this; case Type.STRING: return new StringValue(value); case Type.ANY_URI: return new AnyURIValue(value); case Type.BOOLEAN: String trimmed = StringValue.trimWhitespace(value); if (trimmed.equals("0") || trimmed.equals("false")) return BooleanValue.FALSE; else if (trimmed.equals("1") || trimmed.equals("true")) return BooleanValue.TRUE; else throw new XPathException( "FORG0001: cannot cast '" + Type.getTypeName(this.getItemType()) + "(\"" + getStringValue() + "\")' to " + Type.getTypeName(requiredType)); case Type.FLOAT: return new FloatValue(value); case Type.DOUBLE: return new DoubleValue(this); case Type.NUMBER: // TODO : more complicated return new DoubleValue(this); case Type.DECIMAL: return new DecimalValue(getStringValue()); case Type.INTEGER: case Type.NON_POSITIVE_INTEGER: case Type.NEGATIVE_INTEGER: case Type.LONG: case Type.INT: case Type.SHORT: case Type.BYTE: case Type.NON_NEGATIVE_INTEGER: case Type.UNSIGNED_LONG: case Type.UNSIGNED_INT: case Type.UNSIGNED_SHORT: case Type.UNSIGNED_BYTE: return new IntegerValue(value, requiredType); case Type.BASE64_BINARY: return new Base64Binary(value); case Type.HEX_BINARY: return new HexBinary(value); case Type.DATE_TIME: return new DateTimeValue(value); case Type.TIME: return new TimeValue(value); case Type.DATE: return new DateValue(value); case Type.GYEAR: return new GYearValue(value); case Type.GMONTH: return new GMonthValue(value); case Type.GDAY: return new GDayValue(value); case Type.GYEARMONTH: return new GYearMonthValue(value); case Type.GMONTHDAY: return new GMonthDayValue(value); case Type.DURATION: return new DurationValue(value); case Type.YEAR_MONTH_DURATION: return new YearMonthDurationValue(value); case Type.DAY_TIME_DURATION: DayTimeDurationValue dtdv = new DayTimeDurationValue(value); return new DayTimeDurationValue(dtdv.getCanonicalDuration()); default: throw new XPathException( "FORG0001: cannot cast '" + Type.getTypeName(this.getItemType()) + "(\"" + getStringValue() + "\")' to " + Type.getTypeName(requiredType)); } }
public ComputableValue minus(ComputableValue other) throws XPathException { throw new XPathException( "Subtraction is not supported on values of type " + Type.getTypeName(getType())); }
public ComputableValue div(ComputableValue other) throws XPathException { throw new XPathException("division is not supported for type " + Type.getTypeName(getType())); }
public ComputableValue mult(ComputableValue other) throws XPathException { throw new XPathException( "multiplication is not supported for type " + Type.getTypeName(getType())); }
public boolean effectiveBooleanValue() throws XPathException { throw new XPathException( "FORG0006: effective boolean value invalid operand type: " + Type.getTypeName(getType())); }