Package com.saxonica.ee.validate
Class ContentValidator
java.lang.Object
net.sf.saxon.event.SequenceReceiver
net.sf.saxon.event.ProxyReceiver
com.saxonica.ee.validate.ValidatingFilter
com.saxonica.ee.validate.ContentValidator
- Direct Known Subclasses:
AttributeValidator
,LaxValidator
,SkipValidator
This class is an abstract superclass for all the validators.
The class includes factory methods for constructing a validator.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsFields inherited from class net.sf.saxon.event.ProxyReceiver
nextReceiver
Fields inherited from class net.sf.saxon.event.SequenceReceiver
pipelineConfiguration, previousAtomic, systemId
Fields inherited from interface javax.xml.transform.Result
PI_DISABLE_OUTPUT_ESCAPING, PI_ENABLE_OUTPUT_ESCAPING
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
checkNoCharactersWhenNil
(Location location) Character content was encountered; check that this does not conflict with an xsi:nil=true attributeprotected void
checkNoChildrenWhenNil
(Location location) A child element was encountered; check that this does not conflict with an xsi:nil=true attributevoid
Notify the end of a document nodeprotected final SchemaType
Get the type annotation code to be used on elements validated by this validatorprotected abstract ContentValidator
Get a validator to handle the children of the current element.Get the name of the element being validated (for diagnostics).Get the location of the element being validatedprotected String
Get the containing element name, for use in error messages.protected ElementDecl
Get the element declaration that this validator is validating againstGet the namespace resolverDetermine whether this type permits xsi:nil = true BlockComabstract SchemaType
Get the schema type against which we are validating, if anyboolean
isNilled()
Determine whether xsi:nil = true was set on this elementprotected void
makeChildValidator
(ElementDecl decl, StructuredQName elementName, Location locationId, int process) Make a validator for the children of the element whose start tag is currently being processed.static ContentValidator
makeValidator
(ElementDecl decl, StructuredQName elementName, Location locationId, ValidationContext validationContext, SchemaType governingType, int validation, PipelineConfiguration pipe, Receiver nextReceiver, List<ValidationFailure> failures) Factory method to make a validator for a particular elementstatic ContentValidator
makeValidatorForType
(ElementDecl elementDecl, SchemaType schemaType, PipelineConfiguration pipe, Receiver nextReceiver, List<ValidationFailure> failures) Factory method to create a validator for elements of a given typeprotected final void
setAnnotation
(SchemaType annotation) Set the type annotation code to be allocated by this validatorvoid
setContainingElement
(StructuredQName name, Location locationId) Set the name of the containing element (for diagnostics)protected void
Set the element declaration that this validator is validating againstvoid
setNillability
(ContentValidator.Nillability nillability) Set whether this type permits xsi:nil = truevoid
setNilled
(boolean nilled) Tell this validator whether xsi:nil="true" was specified on the element being validatedvoid
startElement
(NodeName elemName, SchemaType type, AttributeMap attributes, NamespaceMap namespaces, Location location, int properties) Handle the start tag for a child element of the element being validatedvalidateAttributes
(AttributeMap attributes, List<NamespaceBinding> additionalNamespaces) Methods inherited from class com.saxonica.ee.validate.ValidatingFilter
append, getAttributeInheritor, getConstraintChecker, getValidationContext, reportIfInvalid, reportValidationError, setConstraintChecker, setStartTagBuffer, setValidationContext, usesTypeAnnotations
Methods inherited from class net.sf.saxon.event.ProxyReceiver
characters, close, comment, endElement, getNamePool, getNextReceiver, open, processingInstruction, setPipelineConfiguration, setSystemId, setUnderlyingReceiver, setUnparsedEntity, startDocument
Methods inherited from class net.sf.saxon.event.SequenceReceiver
append, decompose, flatten, getConfiguration, getErrorCodeForDecomposingFunctionItems, getPipelineConfiguration, getSystemId, handlesAppend
-
Field Details
-
childValidator
-
nilled
protected boolean nilled -
pendingMessages
-
-
Constructor Details
-
ContentValidator
-
-
Method Details
-
setContainingElement
Set the name of the containing element (for diagnostics)- Parameters:
name
- identifies the name of the containing elementlocationId
- identifies the location of the containing element
-
setElementDeclaration
Set the element declaration that this validator is validating against- Parameters:
decl
- the element declaration
-
getElementDeclaration
Get the element declaration that this validator is validating against- Returns:
- the element declaration
-
getContainingElement
Get the name of the element being validated (for diagnostics).- Returns:
- the element name, or null if not available.
-
getContainingElementLocationId
Get the location of the element being validated- Returns:
- the location, or 0 if not available
-
getContainingElementName
Get the containing element name, for use in error messages.- Returns:
- the name of the containing element (plus surrounding punctuation), or the string "element" if not available
-
getSchemaType
Get the schema type against which we are validating, if any- Returns:
- the schema type that this validator is validating against, or null
-
setAnnotation
Set the type annotation code to be allocated by this validator- Parameters:
annotation
- the integer fingerprint of the name of the type
-
getAnnotation
Get the type annotation code to be used on elements validated by this validator- Returns:
- the integer fingerprint of the name of the type
-
getNamespaceResolver
Get the namespace resolver- Returns:
- the namespace resolver
-
setNillability
Set whether this type permits xsi:nil = true- Parameters:
nillability
- one ofContentValidator.Nillability.IGNORED
,ContentValidator.Nillability.ALLOWED
,ContentValidator.Nillability.DISALLOWED
-
getNillability
Determine whether this type permits xsi:nil = true BlockCom -
setNilled
public void setNilled(boolean nilled) Tell this validator whether xsi:nil="true" was specified on the element being validated- Parameters:
nilled
- true if xsi:nil="true" was specified on the element being validated
-
isNilled
public boolean isNilled()Determine whether xsi:nil = true was set on this element- Returns:
- true if xsi:nil="true" was set
-
startElement
public void startElement(NodeName elemName, SchemaType type, AttributeMap attributes, NamespaceMap namespaces, Location location, int properties) throws XPathException Handle the start tag for a child element of the element being validated- Specified by:
startElement
in interfaceReceiver
- Overrides:
startElement
in classProxyReceiver
- Parameters:
elemName
- the name of the element.type
- the type annotation of the element.attributes
- the attributes of this elementnamespaces
- the in-scope namespaces of this element: generally this is all the in-scope namespaces, without relying on inheriting namespaces from parent elementslocation
- an object providing information about the module, line, and column where the node originatedproperties
- bit-significant properties of the element node. If there are no relevant properties, zero is supplied. The definitions of the bits are in classReceiverOption
- Throws:
XPathException
- if an error occurs
-
makeValidator
public static ContentValidator makeValidator(ElementDecl decl, StructuredQName elementName, Location locationId, ValidationContext validationContext, SchemaType governingType, int validation, PipelineConfiguration pipe, Receiver nextReceiver, List<ValidationFailure> failures) throws MissingComponentException Factory method to make a validator for a particular element- Parameters:
decl
- the element declaration to validate against. May be null.elementName
- the name of the element (used only for diagnostics)locationId
- the location of the element, or of the stylesheet instruction that generated this element (or zero)validationContext
- information about the validation episodegoverningType
- the type identified by xsi:type, if specified; otherwise nullvalidation
- the validation mode (strict, lax, preserve, strip)pipe
- the pipeline configurationnextReceiver
- the next receiver in the pipelinefailures
- a list which the method will populate with ValidationFailure objects in the event that a validity error is detected. (This is used to avoid throwing exceptions in the case where validation failures are a normal event)- Returns:
- a Validator suitable for validating the content of this element
- Throws:
MissingComponentException
-
getChildValidator
Get a validator to handle the children of the current element. This is called immediately on return from the startElement call that starts this element.- Returns:
- the validator to be used to handle the children
-
makeValidatorForType
public static ContentValidator makeValidatorForType(ElementDecl elementDecl, SchemaType schemaType, PipelineConfiguration pipe, Receiver nextReceiver, List<ValidationFailure> failures) throws MissingComponentException Factory method to create a validator for elements of a given type- Parameters:
elementDecl
- the element declaration if available, otherwise null (there will be no element declaration, for example, when doing lax validation against an xsi:type)schemaType
- the simple or complex type against which the content of the element is to be validatedpipe
- the pipeline configurationnextReceiver
- the next receiver in the pipelinefailures
- a list which the method will populate with any validity errors discovered by the method- Returns:
- a Validator that can sit in the event pipeline to perform local validation of elements declared to have this type, or null if any validity errors were found
- Throws:
MissingComponentException
- if validation requires components that are missing from the schema. Note that unresolved references are errors only if the component is actually used, so they are detected during validation.
-
endDocument
Notify the end of a document node- Specified by:
endDocument
in interfaceReceiver
- Overrides:
endDocument
in classProxyReceiver
- Throws:
XPathException
- if an error occurs
-
makeChildValidator
protected void makeChildValidator(ElementDecl decl, StructuredQName elementName, Location locationId, int process) throws XPathException Make a validator for the children of the element whose start tag is currently being processed. This will always set some kind of validator for the children in the field childValidator, even if the method fails- Parameters:
decl
- the element declaration for this element, if applicableelementName
- the name of this element, used for diagnosticslocationId
- location information, used for diagnostics- Throws:
XPathException
- if a validation error occurs and if recovery from validation errors has not been requested. The error will always have been reported.
-
validateAttributes
public AttributeMap validateAttributes(AttributeMap attributes, List<NamespaceBinding> additionalNamespaces) throws XPathException - Throws:
XPathException
-
checkNoChildrenWhenNil
A child element was encountered; check that this does not conflict with an xsi:nil=true attribute- Parameters:
location
- the location to be used in any error report- Throws:
XPathException
- if processing should terminate, for example because of too many errors
-
checkNoCharactersWhenNil
Character content was encountered; check that this does not conflict with an xsi:nil=true attribute- Parameters:
location
- the location to be used in any error report- Throws:
XPathException
- if processing should terminate, for example because of too many errors
-