public class ValidationFailure extends 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(Exception exception)
Creates a new ValidationFailure with the given nested
exception.
|
ValidationFailure(String message)
Creates a new ValidationException with the given message.
|
Modifier and Type | Method and Description |
---|---|
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.
|
AbsolutePath |
getAbsolutePath()
Get the location of the error as a structured path object
|
int |
getColumnNumber()
Get the column number.
|
String |
getConstraintClauseNumber()
Get the constraint clause number
|
String |
getConstraintName()
Get the constraint name
|
String |
getConstraintReference()
Get the constraint name and clause in the format defined in XML Schema Part C (Outcome Tabulations).
|
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
|
String |
getErrorCode()
Get the error code associated with the validity error.
|
StructuredQName |
getErrorCodeQName() |
NodeInfo |
getInvalidNode() |
int |
getLineNumber()
Get the line number.
|
Location |
getLocator() |
String |
getMessage()
Get the text of a message explaining what is wrong
|
AbsolutePath |
getPath()
Get a hierarchic path giving the logical position in the instance document where the
validation error was found
|
String |
getPublicId()
Get the Public ID
|
int |
getSchemaPart()
Get the "schema part" component of the constraint reference
|
SchemaType |
getSchemaType() |
String |
getSystemId()
Get the system ID.
|
String |
getValidationLocationText()
Get additional location text, if any.
|
boolean |
hasBeenReported() |
ValidationException |
makeException() |
ValidationException |
makeException(String contextMessage) |
Location |
saveLocation()
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 satisfied
|
void |
setConstraintReference(ValidationFailure e)
Copy the constraint reference from another exception object
|
void |
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) |
String |
toString()
Returns the String representation of this Exception
|
public ValidationFailure(String message)
message
- the message for this Exceptionpublic ValidationFailure(Exception exception)
exception
- the nested exceptionpublic void setConstraintReference(int schemaPart, String constraintName, 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 String getConstraintName()
getConstraintName
in interface Invalidity
public String getConstraintClauseNumber()
getConstraintClauseNumber
in interface Invalidity
public String getConstraintReference()
getConstraintReference
in interface Invalidity
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 String getMessage()
Invalidity
getMessage
in interface Invalidity
public void setMessage(String message)
public String toString()
public String getPublicId()
Location
getPublicId
in interface SourceLocator
getPublicId
in interface Location
getPublicId
in interface Locator
public 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 SourceLocator
getSystemId
in interface Location
getSystemId
in interface Locator
public int getLineNumber()
Location
getLineNumber
in interface SourceLocator
getLineNumber
in interface Location
getLineNumber
in interface Locator
public int getColumnNumber()
Location
getColumnNumber
in interface SourceLocator
getColumnNumber
in interface Location
getColumnNumber
in interface Locator
public Location saveLocation()
saveLocation
in interface Location
public void setPublicId(String id)
public void setSystemId(String id)
public void setLineNumber(int line)
public void setColumnNumber(int column)
public void setLocator(SourceLocator locator)
public void setSourceLocator(SourceLocator locator)
public Location getLocator()
public void setErrorCode(String errorCode)
public void setErrorCodeQName(StructuredQName errorCode)
public String getErrorCode()
getErrorCode
in interface Invalidity
public StructuredQName getErrorCodeQName()
public void setSchemaType(SchemaType type)
public SchemaType getSchemaType()
public ValidationException makeException()
public ValidationException makeException(String contextMessage)
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 String getValidationLocationText()
public String getContextLocationText()
public AbsolutePath getAbsolutePath()
Copyright (c) 2004-2014 Saxonica Limited. All rights reserved.