/** * Get the typed value corresponding to a given string value, assuming it is * valid against this type * * @param value the string value * @param resolver a namespace resolver used to resolve any namespace prefixes appearing * in the content of values. Can supply null, in which case any namespace-sensitive content * will be rejected. * @param nameChecker checks names against XML 1.0 or XML 1.1 syntax rules * @return an iterator over the atomic sequence comprising the typed value. The objects * returned by this SequenceIterator will all be of type {@link net.sf.saxon.value.AtomicValue} */ public SequenceIterator getTypedValue(CharSequence value, NamespaceResolver resolver, NameChecker nameChecker) throws ValidationException { throw new ValidationException("Cannot validate a string against an external object type"); }
/** * Get the typed value corresponding to a given string value, assuming it is * valid against this type * * @param value the string value * @param resolver a namespace resolver used to resolve any namespace prefixes appearing * in the content of values. Can supply null, in which case any namespace-sensitive content * will be rejected. * @param nameChecker checks names against XML 1.0 or XML 1.1 syntax rules * @return an iterator over the atomic sequence comprising the typed value. The objects * returned by this SequenceIterator will all be of type {@link net.sf.saxon.value.AtomicValue} */ public SequenceIterator getTypedValue(CharSequence value, NamespaceResolver resolver, NameChecker nameChecker) throws ValidationException { throw new ValidationException("Cannot validate a string against an external object type"); }
/** * Get the numeric value converted to a decimal * * @return a decimal representing this numeric value; * @throws ValidationException * if the value cannot be converted, for example if it is NaN or infinite */ @Override public BigDecimal getDecimalValue() throws ValidationException { try { return new BigDecimal(value); } catch (NumberFormatException e) { throw new ValidationException(e); } }
/** * Get the numeric value converted to a decimal * * @return a decimal representing this numeric value; * @throws ValidationException * if the value cannot be converted, for example if it is NaN or infinite */ @Override public BigDecimal getDecimalValue() throws ValidationException { try { return new BigDecimal(value); } catch (NumberFormatException e) { throw new ValidationException(e); } }
public ValidationException makeException() { ValidationException ve = new ValidationException(message); ve.setConstraintReference(schemaPart, constraintName, clause); ve.setErrorCode(errorCode == null ? "FORG0001" : errorCode); return ve; }
/** * Constructor supplying a string */ public FloatValue(CharSequence val) throws ValidationException { try { value = (float)Value.stringToNumber(val); } catch (NumberFormatException e) { throw new ValidationException("Cannot convert string " + Err.wrap(val, Err.VALUE) + " to a float"); } typeLabel = BuiltInAtomicType.FLOAT; }
public ValidationException makeException() { ValidationException ve = new ValidationException(message); ve.setConstraintReference(schemaPart, constraintName, clause); ve.setErrorCode(errorCode == null ? "FORG0001" : errorCode); return ve; }
/** * Constructor supplying a string */ public FloatValue(CharSequence val) throws ValidationException { try { value = (float)Value.stringToNumber(val); } catch (NumberFormatException e) { throw new ValidationException("Cannot convert string " + Err.wrap(val, Err.VALUE) + " to a float"); } typeLabel = BuiltInAtomicType.FLOAT; }
/** * Constructor supplying a string * @param val the string representation of the double value, conforming to the XML Schema lexical * representation of xs:double, with leading and trailing spaces permitted * @throws ValidationException if the string does not have the correct lexical form for a double. * Note that the error will contain no error code or context information. */ public DoubleValue(CharSequence val) throws ValidationException { try { value = Value.stringToNumber(val); } catch (NumberFormatException e) { throw new ValidationException("Cannot convert string " + Err.wrap(val, Err.VALUE) + " to a double"); } typeLabel = BuiltInAtomicType.DOUBLE; }
/** * Constructor supplying a string * @param val the string representation of the double value, conforming to the XML Schema lexical * representation of xs:double, with leading and trailing spaces permitted * @throws ValidationException if the string does not have the correct lexical form for a double. * Note that the error will contain no error code or context information. */ public DoubleValue(CharSequence val) throws ValidationException { try { value = Value.stringToNumber(val); } catch (NumberFormatException e) { throw new ValidationException("Cannot convert string " + Err.wrap(val, Err.VALUE) + " to a double"); } typeLabel = BuiltInAtomicType.DOUBLE; }
/** * Constructor supplying a double * @param in the value of the DecimalValue */ public DecimalValue(double in) throws ValidationException { try { value = stripTrailingZeros(new BigDecimal(in)); } catch (NumberFormatException err) { // Must be a special value such as NaN or infinity ValidationException e = new ValidationException( "Cannot convert double " + Err.wrap(in+"", Err.VALUE) + " to decimal"); e.setErrorCode("FOCA0002"); throw e; } typeLabel = BuiltInAtomicType.DECIMAL; }
/** * Construct a duration value as a number of milliseconds. * * @param milliseconds the number of milliseconds in the duration (may be negative) * @return the corresponding xs:dayTimeDuration value * @throws ValidationException if implementation-defined limits are exceeded, specifically * if the total number of seconds exceeds 2^63. */ public static DayTimeDurationValue fromMilliseconds(long milliseconds) throws ValidationException { int sign = longSignum(milliseconds); if (sign < 0) { milliseconds = -milliseconds; } try { return new DayTimeDurationValue( sign, 0, 0, 0, milliseconds / 1000, (int)(milliseconds % 1000) * 1000); } catch (IllegalArgumentException err) { // limits exceeded throw new ValidationException("Duration exceeds limits"); } }
/** * Constructor supplying a double * @param in the value of the DecimalValue */ public DecimalValue(double in) throws ValidationException { try { value = stripTrailingZeros(new BigDecimal(in)); } catch (NumberFormatException err) { // Must be a special value such as NaN or infinity ValidationException e = new ValidationException( "Cannot convert double " + Err.wrap(in+"", Err.VALUE) + " to decimal"); e.setErrorCode("FOCA0002"); throw e; } typeLabel = BuiltInAtomicType.DECIMAL; }
/** * Construct a duration value as a number of milliseconds. * * @param milliseconds the number of milliseconds in the duration (may be negative) * @return the corresponding xs:dayTimeDuration value * @throws ValidationException if implementation-defined limits are exceeded, specifically * if the total number of seconds exceeds 2^63. */ public static DayTimeDurationValue fromMilliseconds(long milliseconds) throws ValidationException { int sign = longSignum(milliseconds); if (sign < 0) { milliseconds = -milliseconds; } try { return new DayTimeDurationValue( sign, 0, 0, 0, milliseconds / 1000, (int)(milliseconds % 1000) * 1000); } catch (IllegalArgumentException err) { // limits exceeded throw new ValidationException("Duration exceeds limits"); } }
public ValidationException makeException() { if (exception != null) { exception.maybeSetLocation(this); return exception; } ValidationException ve = new ValidationException(this); if (errorCode == null) { ve.setErrorCode("FORG0001"); } else { ve.setErrorCodeQName(errorCode); } ve.setHasBeenReported(hasBeenReported); exception = ve; return ve; }
public ValidationException makeException() { if (exception != null) { exception.maybeSetLocation(this); return exception; } ValidationException ve = new ValidationException(this); if (errorCode == null) { ve.setErrorCode("FORG0001"); } else { ve.setErrorCodeQName(errorCode); } ve.setHasBeenReported(hasBeenReported); exception = ve; return ve; }
/** * Get the typed value of a given input string. This method assumes that the input value * is valid according to this SimpleType * * @param value the string whose typed value is required * @param resolver namespace resolver for namespace-sensitive content * @param rules the type conversion rules to be used */ /*@NotNull*/ public AtomicSequence getTypedValue(/*@NotNull*/ CharSequence value, NamespaceResolver resolver, ConversionRules rules) throws ValidationException { Whitespace.Tokenizer iter = new Whitespace.Tokenizer(value); ListTypeMappingFunction map = new ListTypeMappingFunction(); map.resolver = resolver; map.atomicType = (AtomicType) getItemType(); map.rules = rules; try { return new AtomicArray(new MappingIterator<>(iter, map)); } catch (XPathException err) { throw new ValidationException(err); // should not happen } }
/** * Get the typed value of a given input string. This method assumes that the input value * is valid according to this SimpleType * * @param value the string whose typed value is required * @param resolver namespace resolver for namespace-sensitive content * @param rules the type conversion rules to be used */ /*@NotNull*/ public AtomicSequence getTypedValue(/*@NotNull*/ CharSequence value, NamespaceResolver resolver, ConversionRules rules) throws ValidationException { Whitespace.Tokenizer iter = new Whitespace.Tokenizer(value); ListTypeMappingFunction map = new ListTypeMappingFunction(); map.resolver = resolver; map.atomicType = (AtomicType) getItemType(); map.rules = rules; try { return new AtomicArray(new MappingIterator<>(iter, map)); } catch (XPathException err) { throw new ValidationException(err); // should not happen } }
o.getStringValueCS(), DummyNamespaceResolver.getInstance(), context.getConfiguration().getNameChecker()); if (err != null) { throw new ValidationException("Attribute value " + Err.wrap(o.getStringValueCS(), Err.VALUE) + " does not the match the required type " + schemaType.getDescription() + ". " +
o.getStringValueCS(), DummyNamespaceResolver.getInstance(), context.getConfiguration().getNameChecker()); if (err != null) { throw new ValidationException("Attribute value " + Err.wrap(o.getStringValueCS(), Err.VALUE) + " does not the match the required type " + schemaType.getDescription() + ". " +