/** * Create a new ValidationException that wraps a ValidationFailure * @param failure the ValidationFailure to be wrapped */ public ValidationException(ValidationFailure failure) { super(failure.getMessage(), failure.getErrorCode(), failure.getLocator()); this.failure = failure; }
public Item map(Item item) throws XPathException { if (item instanceof UntypedAtomicValue) { ConversionResult val = ((UntypedAtomicValue)item).convert(requiredItemType, true, context); if (val instanceof ValidationFailure) { ValidationFailure vex = (ValidationFailure)val; vex.setLocator(UntypedAtomicConverter.this); throw vex.makeException(); } return (AtomicValue)val; } else { return item; } } };
protected static ValidationFailure badDuration(String msg, CharSequence s, String errorCode) { ValidationFailure err = new ValidationFailure("Invalid duration value '" + s + "' (" + msg + ')'); err.setErrorCode(errorCode); return err; }
/** * 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 rules the conversion 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} * @throws ValidationException if the supplied value is not in the lexical space of the data type (which is * always true for this type) */ /*@NotNull*/ public AtomicSequence getTypedValue(CharSequence value, NamespaceResolver resolver, ConversionRules rules) throws ValidationException { throw new ValidationFailure("Cast to xs:error always fails").makeException(); }
public void setSourceLocator(/*@Nullable*/ SourceLocator locator) { if (locator != null) { setPublicId(locator.getPublicId()); setSystemId(locator.getSystemId()); setLineNumber(locator.getLineNumber()); setColumnNumber(locator.getColumnNumber()); } }
orphan.getStringValueCS(), DummyNamespaceResolver.getInstance(), rules); if (err != null) { err.setMessage("Attribute value " + Err.wrap(orphan.getStringValueCS(), Err.VALUE) + " does not the match the required type " + schemaType.getDescription() + ". " + err.getMessage()); err.setErrorCode("XTTE1555"); err.setLocator(getLocation()); throw err.makeException();
/** * Constructor supplying a double * * @param in the value of the DecimalValue * @throws ValidationException if the supplied value cannot be converted, typically because it is INF or NaN. */ public BigDecimalValue(double in) throws ValidationException { try { BigDecimal d = new BigDecimal(in); value = d.stripTrailingZeros(); } catch (NumberFormatException err) { // Must be a special value such as NaN or infinity ValidationFailure e = new ValidationFailure( "Cannot convert double " + Err.wrap(in + "", Err.VALUE) + " to decimal"); e.setErrorCode("FOCA0002"); throw e.makeException(); } typeLabel = BuiltInAtomicType.DECIMAL; }
/** * Creates a new ValidationFailure with the given nested * exception. * * @param exception the nested exception */ public static ValidationFailure fromException(/*@NotNull*/ Exception exception) { if (exception instanceof ValidationException) { return ((ValidationException)exception).getValidationFailure(); } else if (exception instanceof XPathException) { ValidationFailure failure = new ValidationFailure(exception.getMessage()); if (((XPathException) exception).getErrorCodeQName() == null) { failure.setErrorCode("FORG0001"); } else { failure.setErrorCodeQName(((XPathException) exception).getErrorCodeQName()); } failure.setLocator(((XPathException) exception).getLocator()); return failure; } else { return new ValidationFailure(exception.getMessage()); } }
public ConversionResult convert(/*@NotNull*/ AtomicValue input) { ValidationFailure vf = new ValidationFailure( "Implicit conversion of untypedAtomic value to " + requiredItemType.toString() + " is not allowed"); vf.setErrorCode("XPTY0117"); vf.setLocator(operand.getLocation()); return vf; } };
/** * Returns the String representation of this Exception * @return the String representation of this Exception **/ public String toString() { StringBuffer sb = new StringBuffer("ValidationException: "); String message = getMessage(); if (message != null) { sb.append(message); } return sb.toString(); }
if (result instanceof ValidationFailure) { ValidationFailure err = (ValidationFailure)result; String code = err.getErrorCode(); dynamicError(err.getMessage(), code, context); return null;
return new AnyURIValue(value); } else { ValidationFailure ve = new ValidationFailure("Invalid URI: " + value.toString()); ve.setErrorCode("FORG0001"); return ve; return new Base64BinaryValue(value); default: ValidationFailure ve = new ValidationFailure("Cannot convert string to type " + Err.wrap(requiredType.getDisplayName())); ve.setErrorCode("XPTY0004"); return ve; ValidationFailure vf = new ValidationFailure(err.getMessage()); vf.setErrorCode(err.getErrorCodeLocalPart()); if (vf.getErrorCode() == null) { vf.setErrorCode("FORG0001"); err.setErrorCode("FORG0001"); ValidationFailure ve = new ValidationFailure(err.getMessage()); if (err.getErrorCodeLocalPart() == null) { ve.setErrorCode("FORG0001"); } else { ve.setErrorCode(err.getErrorCodeLocalPart());
/** * Get a ValidationFailure object containing information from this ValidationException * @return a ValidationFailure object */ public ValidationFailure getValidationFailure() { if (failure != null) { return failure; } else { ValidationFailure failure = new ValidationFailure(getMessage()); failure.setErrorCodeQName(getErrorCodeQName()); failure.setLocator(getLocator()); return failure; } }
public String getPublicId() { SourceLocator loc = getLocator(); if (publicId == null && loc != null && loc != this) { return loc.getPublicId(); } else { return publicId; } }
selectValue.getStringValue(), null, getConfiguration().getConversionRules()); if (err != null) { err.setLocator(getLocation()); err.setErrorCode(isXSLT() ? "XTTE1540" : "XQDY0027"); throw err.makeException();
/** * Calling this method on a ConversionResult returns the AtomicValue that results * from the conversion if the conversion was successful, and throws a ValidationException * explaining the conversion error otherwise. * <p>Use this method if you are calling a conversion method that returns a ConversionResult, * and if you want to throw an exception if the conversion fails.</p> * * @return the atomic value that results from the conversion if the conversion was successful * @throws net.sf.saxon.type.ValidationException * if the conversion was not successful */ /*@NotNull*/ public AtomicValue asAtomic() throws ValidationException { throw makeException(); }
@Override public ValidationFailure validate( CharSequence input) { if (BigDecimalValue.castableAsDecimal(input)) { return null; } else { return new ValidationFailure("Cannot convert string to decimal: " + input); } } }
public AtomicValue mapItem(AtomicValue item) throws XPathException { ConversionResult result = converter.convert(item); if (errorCode != null && result instanceof ValidationFailure) { ((ValidationFailure)result).setErrorCode(errorCode); } return result.asAtomic(); } }
public void setSourceLocator(SourceLocator locator) { if (locator != null) { setPublicId(locator.getPublicId()); setSystemId(locator.getSystemId()); setLineNumber(locator.getLineNumber()); setColumnNumber(locator.getColumnNumber()); } }
orphan.getStringValueCS(), DummyNamespaceResolver.getInstance(), rules); if (err != null) { err.setMessage("Attribute value " + Err.wrap(orphan.getStringValueCS(), Err.VALUE) + " does not the match the required type " + schemaType.getDescription() + ". " + err.getMessage()); err.setErrorCode("XTTE1555"); err.setLocator(getLocation()); throw err.makeException();