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 Summary
ConstructorsConstructorDescriptionValidationFailure
(String message) Creates a new ValidationException with the given message.ValidationFailure
(String message, String errorCode) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addOffendingNode
(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 ValidationFailure
fromException
(Exception exception) Creates a new ValidationFailure with the given nested exception.Get the location of the error as a structured path objectint
Get 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).int
Get 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 IDint
Get the "schema part" component of the constraint referenceGet the system ID.Get additional location text, if any.boolean
Get an immutable copy of this Location object.void
setColumnNumber
(int column) void
setConstraintReference
(int schemaPart, String constraintName, String clause) Set a reference to the constraint in XML Schema that is not satisfiedvoid
Copy the constraint reference from another exception objectvoid
setContextPath
(AbsolutePath contextPath) void
setErrorCode
(String errorCode) void
setErrorCodeQName
(StructuredQName errorCode) void
setHasBeenReported
(boolean reported) void
setInvalidNode
(NodeInfo invalidNode) void
setLineNumber
(int line) void
setLocator
(SourceLocator locator) void
setMessage
(String message) void
setPath
(AbsolutePath path) void
setPublicId
(String id) void
setSchemaType
(SchemaType type) void
setSourceLocator
(SourceLocator locator) void
setSystemId
(String id) toString()
Returns the String representation of this Exception
-
Constructor Details
-
ValidationFailure
Creates a new ValidationException with the given message.- Parameters:
message
- the message for this Exception
-
ValidationFailure
-
-
Method Details
-
fromException
Creates a new ValidationFailure with the given nested exception.- Parameters:
exception
- the nested exception
-
setConstraintReference
Set 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 2constraintName
- - the short name of the constraint in XMLSchema, as a fragment identifier in the HTML of the XML Schema Part 1 specificationclause
- - the clause number within the description of that constraint
-
setConstraintReference
Copy the constraint reference from another exception object- Parameters:
e
- the other exception object from which to copy the information
-
getSchemaPart
public int getSchemaPart()Get the "schema part" component of the constraint reference- Specified by:
getSchemaPart
in interfaceInvalidity
- 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
-
getConstraintName
Get the constraint name- Specified by:
getConstraintName
in interfaceInvalidity
- 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.
-
getConstraintClauseNumber
Get the constraint clause number- Specified by:
getConstraintClauseNumber
in interfaceInvalidity
- 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.
-
getConstraintReference
Get 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:
getConstraintReference
in interfaceInvalidity
- Returns:
- the constraint reference, for example "cos-ct-extends.1.2"; or null if the reference is not known.
-
getConstraintReferenceMessage
Get 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
-
addOffendingNode
Add 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
-
getOffendingNodes
Get 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
-
getPath
Description copied from interface:Invalidity
Get a hierarchic path giving the logical position in the instance document where the validation error was found- Specified by:
getPath
in interfaceInvalidity
- 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
-
getContextPath
Description copied from interface:Invalidity
Get 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 avalidate
expression.- Specified by:
getContextPath
in interfaceInvalidity
- Returns:
- a path to the location in the document
-
setContextPath
-
getInvalidNode
Description copied from interface:Invalidity
Get 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:
getInvalidNode
in interfaceInvalidity
- Returns:
- the invalid node, if it is known, or null
-
setInvalidNode
-
getMessage
Description copied from interface:Invalidity
Get the text of a message explaining what is wrong- Specified by:
getMessage
in interfaceInvalidity
- Returns:
- a human-readable message explaining the validity error
-
setMessage
-
toString
Returns the String representation of this Exception -
getPublicId
Description copied from interface:Location
Get the Public ID- Specified by:
getPublicId
in interfaceLocation
- Specified by:
getPublicId
in interfaceLocator
- Specified by:
getPublicId
in interfaceSourceLocator
- Returns:
- usually null
-
getSystemId
Description copied from interface:Location
Get 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:
getSystemId
in interfaceLocation
- Specified by:
getSystemId
in interfaceLocator
- Specified by:
getSystemId
in interfaceSourceLocator
- Returns:
- the system ID, or null if the information is not available.
-
getLineNumber
public int getLineNumber()Description copied from interface:Location
Get 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:
getLineNumber
in interfaceLocation
- Specified by:
getLineNumber
in interfaceLocator
- Specified by:
getLineNumber
in interfaceSourceLocator
- Returns:
- the line number, or -1 if the information is not available.
-
getColumnNumber
public int getColumnNumber()Description copied from interface:Location
Get the column number. This column number is relative to the line identified by the line number. Column numbers start at 1.- Specified by:
getColumnNumber
in interfaceLocation
- Specified by:
getColumnNumber
in interfaceLocator
- Specified by:
getColumnNumber
in interfaceSourceLocator
- Returns:
- the column number, or -1 if the information is not available.
-
saveLocation
Get 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:
saveLocation
in interfaceLocation
- Returns:
- an immutable copy (which may be the original object, if it is already immutable)
-
setPublicId
-
setSystemId
-
setLineNumber
public void setLineNumber(int line) -
setColumnNumber
public void setColumnNumber(int column) -
setLocator
-
setSourceLocator
-
getLocator
-
setErrorCode
-
setErrorCodeQName
-
getErrorCode
Get 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:
getErrorCode
in interfaceInvalidity
- 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
-
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.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:
asAtomic
in interfaceConversionResult
- Returns:
- the atomic value that results from the conversion if the conversion was successful
- Throws:
ValidationException
- if the conversion was not successful
-
hasBeenReported
public boolean hasBeenReported() -
setHasBeenReported
public void setHasBeenReported(boolean reported) -
getValidationLocationText
Get 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.)
-
getContextLocationText
Get 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.)
-
getAbsolutePath
Get 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
-