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
-
- All Implemented Interfaces:
javax.xml.transform.Result
,Receiver
- Direct Known Subclasses:
AttributeValidator
,LaxValidator
,SkipValidator
public abstract class ContentValidator extends ValidatingFilter
This class is an abstract superclass for all the validators. The class includes factory methods for constructing a validator.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ContentValidator.Nillability
-
Field Summary
Fields Modifier and Type Field Description protected ContentValidator
childValidator
protected boolean
nilled
protected java.util.List<java.lang.String>
pendingMessages
-
Fields inherited from class net.sf.saxon.event.ProxyReceiver
nextReceiver
-
Fields inherited from class net.sf.saxon.event.SequenceReceiver
pipelineConfiguration, previousAtomic, systemId
-
-
Constructor Summary
Constructors Constructor Description ContentValidator(Receiver next)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected 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
endDocument()
Notify the end of a document nodeprotected SchemaType
getAnnotation()
Get the type annotation code to be used on elements validated by this validatorprotected abstract ContentValidator
getChildValidator()
Get a validator to handle the children of the current element.StructuredQName
getContainingElement()
Get the name of the element being validated (for diagnostics).Location
getContainingElementLocationId()
Get the location of the element being validatedprotected java.lang.String
getContainingElementName()
Get the containing element name, for use in error messages.protected ElementDecl
getElementDeclaration()
Get the element declaration that this validator is validating againstNamespaceResolver
getNamespaceResolver()
Get the namespace resolverContentValidator.Nillability
getNillability()
Determine whether this type permits xsi:nil = true BlockComabstract SchemaType
getSchemaType()
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, java.util.List<ValidationFailure> failures)
Factory method to make a validator for a particular elementstatic ContentValidator
makeValidatorForType(ElementDecl elementDecl, SchemaType schemaType, PipelineConfiguration pipe, Receiver nextReceiver, java.util.List<ValidationFailure> failures)
Factory method to create a validator for elements of a given typeprotected 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
setElementDeclaration(ElementDecl decl)
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 validatedAttributeMap
validateAttributes(AttributeMap attributes, java.util.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 Detail
-
childValidator
protected ContentValidator childValidator
-
nilled
protected boolean nilled
-
pendingMessages
protected java.util.List<java.lang.String> pendingMessages
-
-
Constructor Detail
-
ContentValidator
public ContentValidator(Receiver next)
-
-
Method Detail
-
setContainingElement
public void setContainingElement(StructuredQName name, Location locationId)
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
protected void setElementDeclaration(ElementDecl decl)
Set the element declaration that this validator is validating against- Parameters:
decl
- the element declaration
-
getElementDeclaration
protected ElementDecl getElementDeclaration()
Get the element declaration that this validator is validating against- Returns:
- the element declaration
-
getContainingElement
public StructuredQName getContainingElement()
Get the name of the element being validated (for diagnostics).- Returns:
- the element name, or null if not available.
-
getContainingElementLocationId
public Location getContainingElementLocationId()
Get the location of the element being validated- Returns:
- the location, or 0 if not available
-
getContainingElementName
protected java.lang.String 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
public abstract SchemaType 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
protected final void setAnnotation(SchemaType annotation)
Set the type annotation code to be allocated by this validator- Parameters:
annotation
- the integer fingerprint of the name of the type
-
getAnnotation
protected final SchemaType 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
public NamespaceResolver getNamespaceResolver()
Get the namespace resolver- Returns:
- the namespace resolver
-
setNillability
public void setNillability(ContentValidator.Nillability nillability)
Set whether this type permits xsi:nil = true- Parameters:
nillability
- one ofContentValidator.Nillability.IGNORED
,ContentValidator.Nillability.ALLOWED
,ContentValidator.Nillability.DISALLOWED
-
getNillability
public ContentValidator.Nillability 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, java.util.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
protected abstract ContentValidator 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, java.util.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
public void endDocument() throws XPathException
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, java.util.List<NamespaceBinding> additionalNamespaces) throws XPathException
- Throws:
XPathException
-
checkNoChildrenWhenNil
protected void checkNoChildrenWhenNil(Location location) throws XPathException
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
protected void checkNoCharactersWhenNil(Location location) throws XPathException
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
-
-