/** * Check that a value is in range for the specified subtype of xs:integer * * @param value the value to be checked * @param type the required item type, a subtype of xs:integer * @return true if successful, false if value is out of range for the subtype */ public static boolean checkRange(long value, /*@NotNull*/ BuiltInAtomicType type) { int fp = type.getFingerprint(); for (int i = 0; i < ranges.length; i += 3) { if (ranges[i] == fp) { long min = ranges[i + 1]; if (min != NO_LIMIT && value < min) { return false; } long max = ranges[i + 2]; return max == NO_LIMIT || max == MAX_UNSIGNED_LONG || value <= max; } } throw new IllegalArgumentException( "No range information found for integer subtype " + type.getDescription()); }
/** * Check that a value is in range for the specified subtype of xs:integer * * @param value the value to be checked * @param type the required item type, a subtype of xs:integer * @return true if successful, false if value is out of range for the subtype */ public static boolean checkRange(long value, /*@NotNull*/ BuiltInAtomicType type) { int fp = type.getFingerprint(); for (int i = 0; i < ranges.length; i += 3) { if (ranges[i] == fp) { long min = ranges[i + 1]; if (min != NO_LIMIT && value < min) { return false; } long max = ranges[i + 2]; return max == NO_LIMIT || max == MAX_UNSIGNED_LONG || value <= max; } } throw new IllegalArgumentException( "No range information found for integer subtype " + type.getDescription()); }
/** * Check that a value is in range for the specified subtype of xs:integer * * @param value the value to be checked * @param type the required item type, a subtype of xs:integer * @return true if successful, false if value is out of range for the subtype */ public static boolean checkRange(long value, BuiltInAtomicType type) { int fp = type.getFingerprint(); for (int i = 0; i < ranges.length; i += 3) { if (ranges[i] == fp) { long min = ranges[i+1]; if (min != NO_LIMIT && value < min) { return false; } long max = ranges[i+2]; return (max == NO_LIMIT || max == MAX_UNSIGNED_LONG || value <= max); } } throw new IllegalArgumentException( "No range information found for integer subtype " + type.getDescription()); }
/** * Check that a value is in range for the specified subtype of xs:integer * * @param value the value to be checked * @param type the required item type, a subtype of xs:integer * @return true if successful, false if value is out of range for the subtype */ public static boolean checkRange(long value, BuiltInAtomicType type) { int fp = type.getFingerprint(); for (int i = 0; i < ranges.length; i += 3) { //TODO: avoid linear search if (ranges[i] == fp) { long min = ranges[i+1]; if (min != NO_LIMIT && value < min) { return false; } long max = ranges[i+2]; return (max == NO_LIMIT || max == MAX_UNSIGNED_LONG || value <= max); } } throw new IllegalArgumentException( "No range information found for integer subtype " + type.getDescription()); }
/** * Check that a BigInteger is within the required range for a given integer subtype. * This method is expensive, so it should not be used unless the BigInteger is outside the range of a long. * * @param big the supplied BigInteger * @param type the derived type (a built-in restriction of xs:integer) to check the value against * @return true if the value is within the range for the derived type */ public static boolean checkBigRange(BigInteger big, /*@NotNull*/ BuiltInAtomicType type) { for (int i = 0; i < ranges.length; i += 3) { if (ranges[i] == type.getFingerprint()) { long min = ranges[i + 1]; if (min != NO_LIMIT && BigInteger.valueOf(min).compareTo(big) > 0) { return false; } long max = ranges[i + 2]; if (max == NO_LIMIT) { return true; } else if (max == MAX_UNSIGNED_LONG) { return BigIntegerValue.MAX_UNSIGNED_LONG.compareTo(big) >= 0; } else { return BigInteger.valueOf(max).compareTo(big) >= 0; } } } throw new IllegalArgumentException( "No range information found for integer subtype " + type.getDescription()); }
/** * This class allows subtypes of xs:integer to be held, as well as xs:integer values. * This method sets the required type label. Note that this method modifies the value in situ. * * @param type the subtype of integer required * @return null if the operation succeeds, or a ValidationException if the value is out of range */ /*@Nullable*/ public ValidationFailure validateAgainstSubType(/*@NotNull*/ BuiltInAtomicType type) { if (checkRange(value, type)) { return null; } else { ValidationFailure err = new ValidationFailure("Value " + value + " cannot be converted to integer subtype " + type.getDescription()); err.setErrorCode("FORG0001"); return err; } }
/** * This class allows subtypes of xs:integer to be held, as well as xs:integer values. * This method sets the required type label. Note that this method modifies the value in situ. * * @param type the subtype of integer required * @return null if the operation succeeds, or a ValidationException if the value is out of range */ public ValidationFailure validateAgainstSubType(BuiltInAtomicType type) { if (checkRange(value, type)) { return null; } else { ValidationFailure err = new ValidationFailure("Value " + value + " cannot be converted to integer subtype " + type.getDescription()); err.setErrorCode("FORG0001"); return err; } }
/** * This class allows subtypes of xs:integer to be held, as well as xs:integer values. * This method sets the required type label. Note that this method modifies the value in situ. * * @param type the subtype of integer required * @return null if the operation succeeds, or a ValidationException if the value is out of range */ public ValidationFailure validateAgainstSubType(BuiltInAtomicType type) { if (checkRange(value, type)) { return null; } else { ValidationFailure err = new ValidationFailure("Value " + value + " cannot be converted to integer subtype " + type.getDescription()); err.setErrorCode("FORG0001"); return err; } }
/** * This class allows subtypes of xs:integer to be held, as well as xs:integer values. * This method sets the required type label. Note that this method modifies the value in situ. * * @param type the subtype of integer required * @return null if the operation succeeds, or a ValidationException if the value is out of range */ /*@Nullable*/ public ValidationFailure validateAgainstSubType(/*@NotNull*/ BuiltInAtomicType type) { if (checkRange(value, type)) { return null; } else { ValidationFailure err = new ValidationFailure("Value " + value + " cannot be converted to integer subtype " + type.getDescription()); err.setErrorCode("FORG0001"); return err; } }
/** * Convert the value to a subtype of xs:integer * @param subtype the target subtype * @param validate true if validation is required; false if the caller already knows that the value is valid * @return null if the conversion succeeds; a ValidationFailure describing the failure if it fails. Note * that the exception is returned, not thrown. */ public ValidationFailure convertToSubType(BuiltInAtomicType subtype, boolean validate) { if (!validate) { setSubType(subtype); return null; } else if (checkRange(subtype)) { return null; } else { ValidationFailure err = new ValidationFailure("String " + value + " cannot be converted to integer subtype " + subtype.getDescription()); err.setErrorCode("FORG0001"); return err; } }
/** * Convert the value to a subtype of xs:integer * * @param subtype the target subtype * @param validate true if validation is required; false if the caller already knows that the value is valid * @return null if the conversion succeeds; a ValidationFailure describing the failure if it fails. Note * that the exception is returned, not thrown. */ /*@Nullable*/ public ValidationFailure convertToSubType(/*@NotNull*/ BuiltInAtomicType subtype, boolean validate) { if (!validate) { setSubType(subtype); return null; } else if (checkRange(subtype)) { return null; } else { ValidationFailure err = new ValidationFailure("String " + value + " cannot be converted to integer subtype " + subtype.getDescription()); err.setErrorCode("FORG0001"); return err; } }
/** * Constructor for a subtype, supplying a long and a type label. * * @param val The supplied value, as an integer * @param type the required item type, a subtype of xs:integer * @param check Set to true if the method is required to check that the value is in range; * false if the caller can guarantee that the value has already been checked. * @throws XPathException if the supplied value is out of range for the * target type */ public Int64Value(long val, BuiltInAtomicType type, boolean check) throws XPathException { value = val; typeLabel = type; if (check && !checkRange(value, type)) { XPathException err = new XPathException("Integer value " + val + " is out of range for the requested type " + type.getDescription()); err.setErrorCode("XPTY0004"); err.setIsTypeError(true); throw err; } }
/** * Constructor for a subtype, supplying a long and a type label. * * @param val The supplied value, as an integer * @param type the required item type, a subtype of xs:integer * @param check Set to true if the method is required to check that the value is in range; * false if the caller can guarantee that the value has already been checked. * @throws XPathException if the supplied value is out of range for the * target type */ public Int64Value(long val, /*@NotNull*/ BuiltInAtomicType type, boolean check) throws XPathException { value = val; typeLabel = type; if (check && !checkRange(value, type)) { XPathException err = new XPathException("Integer value " + val + " is out of range for the requested type " + type.getDescription()); err.setErrorCode("XPTY0004"); err.setIsTypeError(true); throw err; } }
/** * Check that this type is validly derived from a given type * * @param type the type from which this type is derived * @param block the derivations that are blocked by the relevant element declaration * @throws SchemaException if the derivation is not allowed */ public void checkTypeDerivationIsOK(SchemaType type, int block) throws SchemaException { if (type == AnySimpleType.getInstance()) { // OK } else if (isSameType(type)) { // OK } else { SchemaType base = getBaseType(); if (base == null) { throw new SchemaException("The type " + getDescription() + " is not validly derived from the type " + type.getDescription()); } try { base.checkTypeDerivationIsOK(type, block); } catch (SchemaException se) { throw new SchemaException("The type " + getDescription() + " is not validly derived from the type " + type.getDescription()); } } }
/** * Convert the value to a subtype of xs:integer * * @param subtype the target subtype * @param validate true if validation is required; false if the caller already knows that the value is valid * @return null if the conversion succeeds; a ValidationFailure describing the failure if it fails. Note * that the exception is returned, not thrown. */ /*@Nullable*/ public ValidationFailure convertToSubType(/*@NotNull*/ BuiltInAtomicType subtype, boolean validate) { if (!validate) { setSubType(subtype); return null; } else if (checkRange(subtype)) { return null; } else { ValidationFailure err = new ValidationFailure("String " + value + " cannot be converted to integer subtype " + subtype.getDescription()); err.setErrorCode("FORG0001"); return err; } }
/** * Convert the value to a subtype of xs:integer * @param subtype the target subtype * @param validate true if validation is required; false if the caller already knows that the value is valid * @return null if the conversion succeeds; a ValidationFailure describing the failure if it fails. Note * that the exception is returned, not thrown. */ public ValidationFailure convertToSubType(BuiltInAtomicType subtype, boolean validate) { if (!validate) { setSubType(subtype); return null; } else if (checkRange(subtype)) { return null; } else { ValidationFailure err = new ValidationFailure("String " + value + " cannot be converted to integer subtype " + subtype.getDescription()); err.setErrorCode("FORG0001"); return err; } }
/** * Constructor for a subtype, supplying a long and a type label. * * @param val The supplied value, as an integer * @param type the required item type, a subtype of xs:integer * @param check Set to true if the method is required to check that the value is in range; * false if the caller can guarantee that the value has already been checked. * @throws XPathException if the supplied value is out of range for the * target type */ public Int64Value(long val, BuiltInAtomicType type, boolean check) throws XPathException { value = val; typeLabel = type; if (check && !checkRange(value, type)) { XPathException err = new XPathException("Integer value " + val + " is out of range for the requested type " + type.getDescription()); err.setErrorCode("XPTY0004"); err.setIsTypeError(true); throw err; } }
/** * Constructor for a subtype, supplying a long and a type label. * * @param val The supplied value, as an integer * @param type the required item type, a subtype of xs:integer * @param check Set to true if the method is required to check that the value is in range; * false if the caller can guarantee that the value has already been checked. * @throws XPathException if the supplied value is out of range for the * target type */ public Int64Value(long val, /*@NotNull*/ BuiltInAtomicType type, boolean check) throws XPathException { value = val; typeLabel = type; if (check && !checkRange(value, type)) { XPathException err = new XPathException("Integer value " + val + " is out of range for the requested type " + type.getDescription()); err.setErrorCode("XPTY0004"); err.setIsTypeError(true); throw err; } }
/** * Check that this type is validly derived from a given type * * @param type the type from which this type is derived * @param block the derivations that are blocked by the relevant element declaration * @throws SchemaException if the derivation is not allowed */ public void checkTypeDerivationIsOK(SchemaType type, int block) throws SchemaException { if (type == AnySimpleType.getInstance()) { // OK } else if (isSameType(type)) { // OK } else { SchemaType base = getBaseType(); if (base == null) { throw new SchemaException("Type " + getDescription() + " is not validly derived from " + type.getDescription()); } try { base.checkTypeDerivationIsOK(type, block); } catch (SchemaException se) { throw new SchemaException("Type " + getDescription() + " is not validly derived from " + type.getDescription()); } } }
/** * Check that this type is validly derived from a given type * * @param type the type from which this type is derived * @param block the derivations that are blocked by the relevant element declaration * @throws SchemaException if the derivation is not allowed */ public void checkTypeDerivationIsOK(SchemaType type, int block) throws SchemaException { if (type == AnySimpleType.getInstance()) { // OK } else if (isSameType(type)) { // OK } else { SchemaType base = getBaseType(); if (base == null) { throw new SchemaException("The type " + getDescription() + " is not validly derived from the type " + type.getDescription()); } try { base.checkTypeDerivationIsOK(type, block); } catch (SchemaException se) { throw new SchemaException("The type " + getDescription() + " is not validly derived from the type " + type.getDescription()); } } }