public class ValidationFailure extends java.lang.Object implements Location, ConversionResult, Invalidity
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 and Description |
---|
ValidationFailure(java.lang.String message)
Creates a new ValidationException with the given message.
|
Modifier and Type | Method and Description |
---|---|
void |
addOffendingNode(NodeInfo node)
Add information about an "offending node".
|
AtomicValue |
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(java.lang.Exception exception)
Creates a new ValidationFailure with the given nested
exception.
|
AbsolutePath |
getAbsolutePath()
Get the location of the error as a structured path object
|
int |
getColumnNumber()
Get the column number.
|
java.lang.String |
getConstraintClauseNumber()
Get the constraint clause number
|
java.lang.String |
getConstraintName()
Get the constraint name
|
java.lang.String |
getConstraintReference()
Get the constraint name and clause in the format defined in XML Schema Part C (Outcome Tabulations).
|
java.lang.String |
getConstraintReferenceMessage()
Get the constraint reference as a string for inserting into an error message.
|
java.lang.String |
getContextLocationText()
Get additional location text, if any.
|
AbsolutePath |
getContextPath()
Get a hierarchic path giving the logical position in the instance document where the
validation error was found
|
java.lang.String |
getErrorCode()
Get the error code associated with the validity error.
|
StructuredQName |
getErrorCodeQName() |
NodeInfo |
getInvalidNode() |
int |
getLineNumber()
Get the line number.
|
Location |
getLocator() |
java.lang.String |
getMessage()
Get the text of a message explaining what is wrong
|
java.util.List<NodeInfo> |
getOffendingNodes()
Get the list of "offending nodes".
|
AbsolutePath |
getPath()
Get a hierarchic path giving the logical position in the instance document where the
validation error was found
|
java.lang.String |
getPublicId()
Get the Public ID
|
int |
getSchemaPart()
Get the "schema part" component of the constraint reference
|
SchemaType |
getSchemaType() |
java.lang.String |
getSystemId()
Get the system ID.
|
java.lang.String |
getValidationLocationText()
Get additional location text, if any.
|
boolean |
hasBeenReported() |
ValidationException |
makeException() |
Location |
saveLocation()
Get an immutable copy of this Location object.
|
void |
setColumnNumber(int column) |
void |
setConstraintReference(int schemaPart,
java.lang.String constraintName,
java.lang.String clause)
Set a reference to the constraint in XML Schema that is not satisfied
|
void |
setConstraintReference(ValidationFailure e)
Copy the constraint reference from another exception object
|
void |
setContextPath(AbsolutePath contextPath) |
void |
setErrorCode(java.lang.String errorCode) |
void |
setErrorCodeQName(StructuredQName errorCode) |
void |
setHasBeenReported(boolean reported) |
void |
setInvalidNode(NodeInfo invalidNode) |
void |
setLineNumber(int line) |
void |
setLocator(javax.xml.transform.SourceLocator locator) |
void |
setMessage(java.lang.String message) |
void |
setPath(AbsolutePath path) |
void |
setPublicId(java.lang.String id) |
void |
setSchemaType(SchemaType type) |
void |
setSourceLocator(javax.xml.transform.SourceLocator locator) |
void |
setSystemId(java.lang.String id) |
java.lang.String |
toString()
Returns the String representation of this Exception
|
public ValidationFailure(java.lang.String message)
message
- the message for this Exceptionpublic static ValidationFailure fromException(java.lang.Exception exception)
exception
- the nested exceptionpublic void setConstraintReference(int schemaPart, java.lang.String constraintName, java.lang.String clause)
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 constraintpublic void setConstraintReference(ValidationFailure e)
e
- the other exception object from which to copy the informationpublic int getSchemaPart()
getSchemaPart
in interface Invalidity
public java.lang.String getConstraintName()
getConstraintName
in interface Invalidity
public java.lang.String getConstraintClauseNumber()
getConstraintClauseNumber
in interface Invalidity
public java.lang.String getConstraintReference()
getConstraintReference
in interface Invalidity
public java.lang.String getConstraintReferenceMessage()
public void addOffendingNode(NodeInfo node)
every $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.node
- a node that fails to satisfy the conditions specified in an assertionpublic java.util.List<NodeInfo> getOffendingNodes()
every $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.public AbsolutePath getPath()
Invalidity
getPath
in interface Invalidity
public void setPath(AbsolutePath path)
public AbsolutePath getContextPath()
Invalidity
getContextPath
in interface Invalidity
public void setContextPath(AbsolutePath contextPath)
public NodeInfo getInvalidNode()
public void setInvalidNode(NodeInfo invalidNode)
public java.lang.String getMessage()
Invalidity
getMessage
in interface Invalidity
public void setMessage(java.lang.String message)
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String getPublicId()
Location
getPublicId
in interface javax.xml.transform.SourceLocator
getPublicId
in interface Location
getPublicId
in interface org.xml.sax.Locator
public java.lang.String getSystemId()
Location
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.
getSystemId
in interface javax.xml.transform.SourceLocator
getSystemId
in interface Location
getSystemId
in interface org.xml.sax.Locator
public int getLineNumber()
Location
getLineNumber
in interface javax.xml.transform.SourceLocator
getLineNumber
in interface Location
getLineNumber
in interface org.xml.sax.Locator
public int getColumnNumber()
Location
getColumnNumber
in interface javax.xml.transform.SourceLocator
getColumnNumber
in interface Location
getColumnNumber
in interface org.xml.sax.Locator
public Location saveLocation()
saveLocation
in interface Location
public void setPublicId(java.lang.String id)
public void setSystemId(java.lang.String id)
public void setLineNumber(int line)
public void setColumnNumber(int column)
public void setLocator(javax.xml.transform.SourceLocator locator)
public void setSourceLocator(javax.xml.transform.SourceLocator locator)
public Location getLocator()
public void setErrorCode(java.lang.String errorCode)
public void setErrorCodeQName(StructuredQName errorCode)
public java.lang.String getErrorCode()
getErrorCode
in interface Invalidity
public StructuredQName getErrorCodeQName()
public void setSchemaType(SchemaType type)
public SchemaType getSchemaType()
public ValidationException makeException()
public AtomicValue asAtomic() throws ValidationException
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.
asAtomic
in interface ConversionResult
ValidationException
- if the conversion was not successfulpublic boolean hasBeenReported()
public void setHasBeenReported(boolean reported)
public java.lang.String getValidationLocationText()
public java.lang.String getContextLocationText()
public AbsolutePath getAbsolutePath()
Copyright (c) 2004-2020 Saxonica Limited. All rights reserved.