Package net.sf.saxon.type
Class ValidationFailure
java.lang.Object
net.sf.saxon.type.ValidationFailure
- All Implemented Interfaces:
- SourceLocator,- Invalidity,- Location,- ConversionResult,- Locator
This exception indicates a failure when validating an instance against a type
 defined in a schema.
 
This class holds the same information as a ValidationException, except that it is not an exception, and does not carry system overheads such as a stack trace. It is used because operations such as "castable", and validation of values in a union, cause validation failures on a success path and it is costly to throw, or even to create, exception objects on a success path.
- 
Constructor SummaryConstructorsConstructorDescriptionValidationFailure(String message) Creates a new ValidationException with the given message.ValidationFailure(String message, String errorCode) 
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddOffendingNode(NodeInfo node) Add information about an "offending node".asAtomic()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.static ValidationFailurefromException(Exception exception) Creates a new ValidationFailure with the given nested exception.Get the location of the error as a structured path objectintGet the column number.Get the constraint clause numberGet the constraint nameGet the constraint name and clause in the format defined in XML Schema Part C (Outcome Tabulations).Get the constraint reference as a string for inserting into an error message.Get additional location text, if any.Get a hierarchic path giving the node being validated (the validation root).Get the error code associated with the validity error.Get the node that was found to be invalid (if any).intGet the line number.Get the text of a message explaining what is wrongGet the list of "offending nodes".getPath()Get a hierarchic path giving the logical position in the instance document where the validation error was foundGet the Public IDintGet the "schema part" component of the constraint referenceGet the system ID.Get additional location text, if any.booleanGet an immutable copy of this Location object.voidsetColumnNumber(int column) voidsetConstraintReference(int schemaPart, String constraintName, String clause) Set a reference to the constraint in XML Schema that is not satisfiedvoidCopy the constraint reference from another exception objectvoidsetContextPath(AbsolutePath contextPath) voidsetErrorCode(String errorCode) voidsetErrorCodeQName(StructuredQName errorCode) voidsetHasBeenReported(boolean reported) voidsetInvalidNode(NodeInfo invalidNode) voidsetLineNumber(int line) voidsetLocator(SourceLocator locator) voidsetMessage(String message) voidsetPath(AbsolutePath path) voidsetPublicId(String id) voidsetSchemaType(SchemaType type) voidsetSourceLocator(SourceLocator locator) voidsetSystemId(String id) toString()Returns the String representation of this Exception
- 
Constructor Details- 
ValidationFailureCreates a new ValidationException with the given message.- Parameters:
- message- the message for this Exception
 
- 
ValidationFailure
 
- 
- 
Method Details- 
fromExceptionCreates a new ValidationFailure with the given nested exception.- Parameters:
- exception- the nested exception
 
- 
setConstraintReferenceSet a reference to the constraint in XML Schema that is not satisfied- Parameters:
- schemaPart- - 1 or 2, depending whether the constraint is in XMLSchema part 1 or part 2
- constraintName- - the short name of the constraint in XMLSchema, as a fragment identifier in the HTML of the XML Schema Part 1 specification
- clause- - the clause number within the description of that constraint
 
- 
setConstraintReferenceCopy the constraint reference from another exception object- Parameters:
- e- the other exception object from which to copy the information
 
- 
getSchemaPartpublic int getSchemaPart()Get the "schema part" component of the constraint reference- Specified by:
- getSchemaPartin interface- Invalidity
- Returns:
- 1 or 2 depending on whether the violated constraint is in XML Schema Part 1 or Part 2; or -1 if there is no constraint reference
 
- 
getConstraintNameGet the constraint name- Specified by:
- getConstraintNamein interface- Invalidity
- Returns:
- the name of the violated constraint, in the form of a fragment identifier within the published XML Schema specification; or null if the information is not available.
 
- 
getConstraintClauseNumberGet the constraint clause number- Specified by:
- getConstraintClauseNumberin interface- Invalidity
- Returns:
- the section number of the clause containing the constraint that has been violated. Generally a decimal number in the form n.n.n; possibly a sequence of such numbers separated by semicolons. Or null if the information is not available.
 
- 
getConstraintReferenceGet the constraint name and clause in the format defined in XML Schema Part C (Outcome Tabulations). This mandates the format validation-rule-name.clause-number- Specified by:
- getConstraintReferencein interface- Invalidity
- Returns:
- the constraint reference, for example "cos-ct-extends.1.2"; or null if the reference is not known.
 
- 
getConstraintReferenceMessageGet the constraint reference as a string for inserting into an error message.- Returns:
- the reference as a message, or null if no information is available
 
- 
addOffendingNodeAdd information about an "offending node". This is used for assertions, where the assertion on a particular node A places conditions on descendant nodes D: for exampleevery $n in .//* satisfies self::x. With that kind of assertion, the nodes in.//*that do not satisfy the condition are reported as "offending nodes", although it is the root node containing the assertion that is technically invalid.- Parameters:
- node- a node that fails to satisfy the conditions specified in an assertion
 
- 
getOffendingNodesGet the list of "offending nodes". This is used for assertions, where the assertion on a particular node A places conditions on descendant nodes D: for exampleevery $n in .//* satisfies self::x. With that kind of assertion, the nodes in.//*that do not satisfy the condition are reported as "offending nodes", although it is the root node containing the assertion that is technically invalid.- Returns:
- the list of offending nodes
 
- 
getPathDescription copied from interface:InvalidityGet a hierarchic path giving the logical position in the instance document where the validation error was found- Specified by:
- getPathin interface- Invalidity
- Returns:
- a path to the location in the document where the error was found. This is not necessarily the same thing as the node that is invalid: for example if the schema type for element A does not allow a child element named B, but in the instance document there is an A element with a B child, then the path returned may be the path to B, whereas it is A that is invalid.
 
- 
setPath
- 
getContextPathDescription copied from interface:InvalidityGet a hierarchic path giving the node being validated (the validation root). If validation is invoked from XSLT this might be a node selected by the instruction<xsl:copy-of select="X" validation="strict"/>; in XQuery it might be the target of avalidateexpression.- Specified by:
- getContextPathin interface- Invalidity
- Returns:
- a path to the location in the document
 
- 
setContextPath
- 
getInvalidNodeDescription copied from interface:InvalidityGet the node that was found to be invalid (if any). This will be available only when validating an input document supplied in the form of an in-memory tree- Specified by:
- getInvalidNodein interface- Invalidity
- Returns:
- the invalid node, if it is known, or null
 
- 
setInvalidNode
- 
getMessageDescription copied from interface:InvalidityGet the text of a message explaining what is wrong- Specified by:
- getMessagein interface- Invalidity
- Returns:
- a human-readable message explaining the validity error
 
- 
setMessage
- 
toStringReturns the String representation of this Exception
- 
getPublicIdDescription copied from interface:LocationGet the Public ID- Specified by:
- getPublicIdin interface- Location
- Specified by:
- getPublicIdin interface- Locator
- Specified by:
- getPublicIdin interface- SourceLocator
- Returns:
- usually null
 
- 
getSystemIdDescription copied from interface:LocationGet the system ID. This should be the system identifier of an XML external entity; if a stylesheet module comprises multiple external entities, the distinction should be retained. This means, for example, that an instruction in a stylesheet can have a different system identifier from its parent instruction. However, SAX parsers only provide location information at the element level, so when part of an XPath expression is in a different external entity from other parts of the same expression, this distinction is lost.The system identifier of a node is in general not the same as its base URI. The base URI is affected by xml:base attributes; the system identifier is not. - Specified by:
- getSystemIdin interface- Location
- Specified by:
- getSystemIdin interface- Locator
- Specified by:
- getSystemIdin interface- SourceLocator
- Returns:
- the system ID, or null if the information is not available.
 
- 
getLineNumberpublic int getLineNumber()Description copied from interface:LocationGet the line number. This line number is relative to the external entity identified by the system identifier. Line numbers start at 1. The value may be an approximation; SAX parsers only provide line number information at the level of element nodes.- Specified by:
- getLineNumberin interface- Location
- Specified by:
- getLineNumberin interface- Locator
- Specified by:
- getLineNumberin interface- SourceLocator
- Returns:
- the line number, or -1 if the information is not available.
 
- 
getColumnNumberpublic int getColumnNumber()Description copied from interface:LocationGet the column number. This column number is relative to the line identified by the line number. Column numbers start at 1.- Specified by:
- getColumnNumberin interface- Location
- Specified by:
- getColumnNumberin interface- Locator
- Specified by:
- getColumnNumberin interface- SourceLocator
- Returns:
- the column number, or -1 if the information is not available.
 
- 
saveLocationGet an immutable copy of this Location object. By default Location objects may be mutable, so they should not be saved for later use. The result of this operation holds the same location information, but in an immutable form.- Specified by:
- saveLocationin interface- Location
- Returns:
- an immutable copy (which may be the original object, if it is already immutable)
 
- 
setPublicId
- 
setSystemId
- 
setLineNumberpublic void setLineNumber(int line) 
- 
setColumnNumberpublic void setColumnNumber(int column) 
- 
setLocator
- 
setSourceLocator
- 
getLocator
- 
setErrorCode
- 
setErrorCodeQName
- 
getErrorCodeGet the error code associated with the validity error. This is relevant only when validation is run from within XSLT or XQuery, which define different error codes for validation errors- Specified by:
- getErrorCodein interface- Invalidity
- Returns:
- the error code associated with the error, if any. The error is returned as a simple string if it is in the standard error namespace, or as an EQName (that is Q{uri}local) otherwise.
 
- 
getErrorCodeQName
- 
setSchemaType
- 
getSchemaType
- 
makeException
- 
asAtomicCalling 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.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. - Specified by:
- asAtomicin interface- ConversionResult
- Returns:
- the atomic value that results from the conversion if the conversion was successful
- Throws:
- ValidationException- if the conversion was not successful
 
- 
hasBeenReportedpublic boolean hasBeenReported()
- 
setHasBeenReportedpublic void setHasBeenReported(boolean reported) 
- 
getValidationLocationTextGet additional location text, if any. This gives extra information about the position of the error in textual form. Where XPath is embedded within a host language such as XSLT, the formal location information identifies the location of the error in the XSLT module, while this string locates the error within a specific XPath expression. The information is typically used only for static errors.- Returns:
- additional information about the location of the error, designed to be output as a prefix to the error message if desired. (It is not concatenated with the message, because it may be superfluous in an IDE environment.)
 
- 
getContextLocationTextGet additional location text, if any. This gives extra information about the position of the error in textual form. Where XPath is embedded within a host language such as XSLT, the formal location information identifies the location of the error in the XSLT module, while this string locates the error within a specific XPath expression. The information is typically used only for static errors.- Returns:
- additional information about the location of the error, designed to be output as a prefix to the error message if desired. (It is not concatenated with the message, because it may be superfluous in an IDE environment.)
 
- 
getAbsolutePathGet the location of the error as a structured path object- Returns:
- the location, as a structured path object indicating the position of the error within the containing document
 
 
-