Package com.saxonica.ee.schema.sdoc
Class SchemaElement
java.lang.Object
net.sf.saxon.tree.linked.NodeImpl
net.sf.saxon.tree.linked.ParentNodeImpl
net.sf.saxon.tree.linked.ElementImpl
com.saxonica.ee.schema.sdoc.SchemaElement
- All Implemented Interfaces:
Source
,SourceLocator
,ActiveSource
,GroundedValue
,Item
,MutableNodeInfo
,NamespaceResolver
,NodeInfo
,Sequence
,Location
,SteppingNode
,SiblingCountingNode
,Locator
- Direct Known Subclasses:
AnnotationParent
,UnknownElement
,XSDAnnotation
,XSDAttribute
,XSDAttributeGroup
,XSDComplexContent
,XSDComplexContentRestriction
,XSDComplexType
,XSDCompositor
,XSDDocumentation
,XSDElement
,XSDExtension
,XSDGroup
,XSDIdentityConstraint
,XSDList
,XSDOverride
,XSDRedefine
,XSDSchema
,XSDSimpleContent
,XSDSimpleContentRestriction
,XSDSimpleType
,XSDSimpleTypeRestriction
,XSDUnion
An element in an XML Schema document. This is an abstract superclass for the elements
in the schema document; many of its methods are designed to be called from the subclasses
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final String
protected static final String
protected static final String
protected static final String
static final int
Option indicating "no namespace prefix is allowed; the name is in the null Namespace"static final int
Option indicating "no namespace prefix is allowed; the name is in the targetNamespace"static final int
Option indicating "use the default element namespace when unprefixed"static final int
Option indicating "use the default element namespace when unprefixed", but without a requirement to have an xs:importFields inherited from class net.sf.saxon.tree.linked.NodeImpl
NODE_LETTER
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected NodeName
Allocate a name to an anonymous type.void
allowAttributes
(AttributeMap atts, String[] allowed) Check the attributes of an element against a list of allowed attributes.protected void
checkContentModel
(int[][] stateTerms, int[][] stateTargets, boolean allowWildcards) Check the content model of an element in the schema.void
checkLocalTargetNamespace
(String elementOrAttribute) For an element or attribute declaration with a targetNamespace attribute (XSD 1.1), check the highly-paternalistic rules for when this attribute is permitted.protected void
checkMutuallyExclusiveAttributes
(String name1, String name2) This method tests whether two attributes coexist and reports an error if they doprotected void
Check that the only child element of this element is an (optional and non-repeatable) xs:annotation elementvoid
checkPermittedType
(int fp, String name, String role) Check that a given type is a permitted typeprotected void
This method is called when two objects in the same symbol space within a schema have duplicate namesprotected void
duplicateElement
(String name) This method is called when two occurrences of a child element are found and only one is allowed.protected void
This method is called for a general error.protected void
error
(SchemaException exception) This method is called for a general error.protected StructuredQName
getComponentName
(String name, int option) This method is called to check that a lexical QName is valid and allocate a nameCode for the name in the namePool.protected UserComplexType
Get the complexType associated with the containing xs:complexType elementprotected SimpleTypeDefinition
Get the simpleTypeDefinition associated with the containing xs:simpleType elementprotected int
getFingerprint
(String name, int option) This method is called to check that a QName is valid and allocate a fingerprint for the name in the namePool.Get the schema corresponding to the contents of the schema document containing this elementGet the nodeFactory used to create this element.Get the owning XSDSchema element.protected void
illegalElement
(NodeInfo child) This method is called when an illegal Element is encountered.protected String
indefiniteArticle
(String word, String start) Construct an indefinite article in Englishvoid
invalidAttributeValue
(String name, String value, String message) This method is called when an invalid attribute value is foundprotected boolean
isFinalState
(int state) For elements whose content model is parsed using a finite state machine, test whether a given state is a final state.protected boolean
Return true if this element is a child of xs:schema or xs:redefineprotected NamespaceResolver
Make a NamespaceContext object representing the list of in-scope namespaces.void
missingAttribute
(String name) This method is called when a required attribute is not foundvoid
missingChildElement
(String name) This method is called when a required child element is not foundprotected void
mustBeFirstElement
(String name) This method is called when a child element is required to be the first child, but is found elsewhereprotected void
mustPrecede
(String name1, String name2) This method is called when two child elements are found in the wrong order.protected void
mutuallyExclusive
(String name1, String name2) This method is called when two child elements may not coexistprotected void
mutuallyExclusiveAttributes
(String name1, String name2) This method is called when two attributes may not coexistprotected void
mutuallyExclusiveElementAndAttribute
(String elem, String att) This method is called when an attribute and a child elements may not coexistboolean
parseBooleanAttribute
(String name, String value) Parse a boolean attribute valueint
parseFinalOrBlock
(String attrName, String finalValue, int allowed) Parse a list of blocked or final derivations.void
postValidate
(SchemaCompiler compiler) Hook to allow additional validation of a parent element immediately after its children have been validated.protected abstract void
Set the attribute list for the element.void
Process the attributes of this element and all its childrenprotected void
processAllowedNamespaces
(String attValue, Wildcard wildcard) Process the namespaces attribute of XSDAny or XSDAnyAttributeprotected void
processDisallowedNamespaces
(String attValue, Wildcard wildcard) Process the notNamespaces attribute of XSDAny or XSDAnyAttributeprotected void
processDisallowedQNames
(String attValue, Wildcard wildcard) Process the notQNames attribute of XSDAny or XSDAnyAttributevoid
Process an @id attribute on the schema element: if present, check that it is a valid ID, and that it is unique in the schema documentint
processMaxOccurs
(String attValue) Process the value of a maxOccurs attribute on any element where it appearsint
processMinOccurs
(String attValue) Process the value of a minOccurs attribute on any element where it appearsvoid
requireAttribute
(AttributeMap atts, String required) Indicate that a particular attribute is requiredvoid
setSchemaNodeFactory
(SchemaNodeFactory factory) Set the nodeFactory used to create this element.void
validate
(SchemaCompiler compiler) Check that the schema element is valid.protected void
validateChildren
(SchemaCompiler compiler) Validate the children of this node, recursively.void
validateSubtree
(SchemaCompiler compiler) Recursive walk through the schema to validate all nodesprotected void
Report a warningMethods inherited from class net.sf.saxon.tree.linked.ElementImpl
addAttribute, addNamespace, addNamespace, attributes, checkNotNamespaceSensitiveElement, copy, delete, fixupInsertedNamespaces, generateId, getAllNamespaces, getAttributeValue, getBaseURI, getColumnNumber, getDeclaredNamespaces, getLineNumber, getNodeKind, getNodeName, getRoot, getSchemaType, getSystemId, getURIForPrefix, initialise, isId, isIdref, isIdRefNode, isInScopeNamespace, isNilled, iteratePrefixes, removeAttribute, removeNamespace, removeTypeAnnotation, rename, replaceStringValue, setAttributeInfo, setAttributes, setLocation, setNamespaceMap, setNilled, setNodeName, setSystemId, setTypeAnnotation
Methods inherited from class net.sf.saxon.tree.linked.ParentNodeImpl
addChild, compact, getFirstChild, getLastChild, getNthChild, getNumberOfChildren, getRawSequenceNumber, getSequenceNumber, getUnicodeStringValue, hasChildNodes, insertChildren, insertChildrenAt, iterateChildren, removeChild, replaceChildrenAt, setChildren, setRawSequenceNumber
Methods inherited from class net.sf.saxon.tree.linked.NodeImpl
atomize, compareOrder, effectiveBooleanValue, equals, getConfiguration, getDisplayName, getFingerprint, getLocalPart, getNamePool, getNamespaceUri, getNextInDocument, getNextSibling, getParent, getPhysicalRoot, getPrefix, getPreviousInDocument, getPreviousSibling, getRawParent, getSiblingPosition, getSuccessorElement, getTreeInfo, hasFingerprint, hashCode, head, insertSiblings, isDeleted, iterateAxis, iterateAxis, newBuilder, replace, saveLocation, setRawParent, setSiblingPosition
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.sf.saxon.om.GroundedValue
asIterable, concatenate, containsNode, materialize
Methods inherited from interface net.sf.saxon.om.Item
getLength, getStringValue, itemAt, iterate, reduce, subsequence
Methods inherited from interface net.sf.saxon.om.NodeInfo
asActiveSource, children, children, deliver, getAttributeValue, getGenre, getPublicId, getURI, isSameNodeInfo, isStreamed, toShortString
Methods inherited from interface net.sf.saxon.om.Sequence
makeRepeatable
-
Field Details
-
USE_DEFAULT_NS
public static final int USE_DEFAULT_NSOption indicating "use the default element namespace when unprefixed"- See Also:
-
REQUIRE_TARGET_NS
public static final int REQUIRE_TARGET_NSOption indicating "no namespace prefix is allowed; the name is in the targetNamespace"- See Also:
-
REQUIRE_NULL_NS
public static final int REQUIRE_NULL_NSOption indicating "no namespace prefix is allowed; the name is in the null Namespace"- See Also:
-
USE_DEFAULT_NS_WITHOUT_IMPORT
public static final int USE_DEFAULT_NS_WITHOUT_IMPORTOption indicating "use the default element namespace when unprefixed", but without a requirement to have an xs:import- See Also:
-
NAMESPACE_ANY
- See Also:
-
NAMESPACE_LOCAL
- See Also:
-
NAMESPACE_OTHER
- See Also:
-
NAMESPACE_TARGET
- See Also:
-
-
Constructor Details
-
SchemaElement
public SchemaElement()Construct a SchemaElement
-
-
Method Details
-
isTopLevel
protected boolean isTopLevel()Return true if this element is a child of xs:schema or xs:redefine- Returns:
- true if this element is a child of xs:schema or xs:redefine
-
setSchemaNodeFactory
Set the nodeFactory used to create this element.- Parameters:
factory
- the schema node factory
-
getSchemaNodeFactory
Get the nodeFactory used to create this element. This nodeFactory is used to keep track of any errors encountered during construction of the schema document- Returns:
- factory the schema node factory
-
processAllAttributes
Process the attributes of this element and all its children- Throws:
SchemaException
-
prepareAttributes
Set the attribute list for the element. This is called to process the attributes (note the distinction from processAttributes in the superclass). Must be supplied in a subclass- Throws:
SchemaException
-
allowAttributes
Check the attributes of an element against a list of allowed attributes. Report an error if any extraneous attribute is present- Parameters:
atts
- the attributes actually presentallowed
- the attributes that are allowed for this element. They must be listed in alphabetical order- Throws:
SchemaException
-
requireAttribute
Indicate that a particular attribute is required- Parameters:
atts
- the attribtue collectionrequired
- the local name of the required attribute, which must be in the null namespace- Throws:
SchemaException
-
validateSubtree
Recursive walk through the schema to validate all nodes- Parameters:
compiler
- used for error reporting- Throws:
SchemaException
-
validateChildren
Validate the children of this node, recursively.- Parameters:
compiler
- used for error reporting- Throws:
SchemaException
- if the subtree is not valid
-
validate
Check that the schema element is valid. This is called once for each element, after the entire tree has been built. As well as validation, it can perform first-time initialisation. The default implementation does nothing; it is normally overriden in subclasses.- Parameters:
compiler
- used for error reporting- Throws:
SchemaException
- if the subtree is not valid
-
postValidate
Hook to allow additional validation of a parent element immediately after its children have been validated.- Parameters:
compiler
- used for error reporting- Throws:
SchemaException
- if errors are found
-
getXSDSchema
Get the owning XSDSchema element.- Returns:
- the containing xs:schema element
- Throws:
SchemaException
- if none is found (which means the schema is invalid)
-
getSchema
Get the schema corresponding to the contents of the schema document containing this element- Returns:
- the PreparedSchema object used to assemble the schema components defined in the schema document that contains this element.
- Throws:
SchemaException
- if the containing PreparedSchema cannot be found
-
getContainingComplexType
Get the complexType associated with the containing xs:complexType element- Returns:
- the UserComplexType object representing the containing complex type
- Throws:
SchemaException
- if the element is not contained in an xs:complexType
-
getContainingSimpleType
Get the simpleTypeDefinition associated with the containing xs:simpleType element- Returns:
- the schema component representing the containing simple type
- Throws:
SchemaException
- if not contained in an xs:simpleType
-
makeNamespaceContext
Make a NamespaceContext object representing the list of in-scope namespaces. The NamePool used for numeric codes in the NamespaceContext will be the target name pool.- Returns:
- a copy of the namespace context for this element
-
checkPermittedType
Check that a given type is a permitted type- Throws:
SchemaException
-
parseBooleanAttribute
Parse a boolean attribute value- Parameters:
name
- the name of the attribute (for diagnostics)value
- the string value of the attribute (need not be trimmed)- Returns:
- the boolean value of the attribute if it is valid
- Throws:
SchemaException
- if the value is not a valid boolean
-
error
This method is called for a general error. The location of this message is the current element.- Parameters:
err
- the error message to report- Throws:
SchemaException
-
error
This method is called for a general error. The location of this message is the current element.- Parameters:
exception
- the error message to report- Throws:
SchemaException
- if the user-written error handler chooses to treat the error as fatal
-
warning
Report a warning- Parameters:
err
- the warning message- Throws:
SchemaException
- if the user-supplied error handler chooses to treat the warning as fatal
-
getFingerprint
This method is called to check that a QName is valid and allocate a fingerprint for the name in the namePool. If the QName isn't valid, the method throws an exception: it is the caller's responsibility to call the error handler and recover from the error. The method makes use of the namespace context information for the schema element.- Parameters:
name
- The QNameoption
- The option for handling unprefixed names. Options are to use the default namespace, the target namespace, or the null namespace Note that this method assumes the name, if unprefixed, is in the default namespace: NOT the targetNamespace of the schema.- Returns:
- a fingerprint
- Throws:
SchemaException
- if the QName is invalid.
-
getComponentName
This method is called to check that a lexical QName is valid and allocate a nameCode for the name in the namePool. If the QName isn't valid, the method throws an exception: it is the caller's responsibility to call the error handler and recover from the error. The method makes use of the namespace context information for the schema element.- Parameters:
name
- The QName as written in the schemaoption
- The option for handling unprefixed names. Options are to use the default namespaceUSE_DEFAULT_NS
, the target namespaceREQUIRE_TARGET_NS
, or the null namespaceREQUIRE_NULL_NS
- Returns:
- an integer name code
- Throws:
SchemaException
- if the QName is invalid.
-
checkOnlyChildIsAnnotation
Check that the only child element of this element is an (optional and non-repeatable) xs:annotation element- Throws:
SchemaException
-
illegalElement
This method is called when an illegal Element is encountered.- Parameters:
child
- The child element whose presence is an error- Throws:
SchemaException
- thrown if the errorListener decides that it's a fatal error.
-
duplicateElement
This method is called when two occurrences of a child element are found and only one is allowed.- Parameters:
name
- the name of the illegal element- Throws:
SchemaException
- thrown if the errorListener decides that it's a fatal error.
-
duplicate
This method is called when two objects in the same symbol space within a schema have duplicate names- Parameters:
category
- the name of the first attributename
- the name of the second attribute- Throws:
SchemaException
- thrown if the errorListener decides that it's a fatal error.
-
mutuallyExclusive
This method is called when two child elements may not coexist- Parameters:
name1
- the name of the first elementname2
- the name of the second element- Throws:
SchemaException
- thrown if the errorListener decides that it's a fatal error.
-
mutuallyExclusiveElementAndAttribute
This method is called when an attribute and a child elements may not coexist- Parameters:
elem
- the name of the elementatt
- the name of the attribute- Throws:
SchemaException
- thrown if the errorListener decides that it's a fatal error.
-
mutuallyExclusiveAttributes
This method is called when two attributes may not coexist- Parameters:
name1
- the name of the first attributename2
- the name of the second attribute- Throws:
SchemaException
- thrown if the errorListener decides that it's a fatal error.
-
checkMutuallyExclusiveAttributes
This method tests whether two attributes coexist and reports an error if they do- Parameters:
name1
- the local name of the first attribute (must be in the null namespace)name2
- the local name of the second attribute (must be in the null namespace)- Throws:
SchemaException
-
mustPrecede
This method is called when two child elements are found in the wrong order.- Parameters:
name1
- the name of the element that should be firstname2
- the name of the element that should be second- Throws:
SchemaException
- thrown if the errorListener decides that it's a fatal error.
-
mustBeFirstElement
This method is called when a child element is required to be the first child, but is found elsewhere- Parameters:
name
- the name of the illegal element- Throws:
SchemaException
- thrown if the errorListener decides that it's a fatal error.
-
indefiniteArticle
Construct an indefinite article in English- Parameters:
word
- The word to follow the articlestart
- Typically "a" or "A"- Returns:
- the indefinite article
-
invalidAttributeValue
This method is called when an invalid attribute value is found- Parameters:
name
- the name of the attributevalue
- the supplied value of the attributemessage
- additional explanation of why it's wrong. May be null.- Throws:
SchemaException
- thrown if the errorListener decides that it's a fatal error.
-
missingAttribute
This method is called when a required attribute is not found- Parameters:
name
- the name of the attribute- Throws:
SchemaException
- thrown if the errorListener decides that it's a fatal error.
-
missingChildElement
This method is called when a required child element is not found- Parameters:
name
- the name of the required child element- Throws:
SchemaException
- thrown if the errorListener decides that it's a fatal error.
-
parseFinalOrBlock
public int parseFinalOrBlock(String attrName, String finalValue, int allowed) throws SchemaException Parse a list of blocked or final derivations. Used to process the block, final, blockDefault, and finalDefault attributes.- Parameters:
attrName
- the name of the attribute being parsedfinalValue
- A list of values to be parsed, as a string, for example "extension restriction"allowed
- The permitted values, as a bit-significant integer. For example the value (DERIVE_BY_EXTENSION | DERIVE_BY_RESTRICTION) allows the values "extension" and "restriction" to appear.- Returns:
- The final/blocked values, as a bit-significant integer
- Throws:
SchemaException
- if the value of the attribute is invalid
-
processId
Process an @id attribute on the schema element: if present, check that it is a valid ID, and that it is unique in the schema document- Throws:
SchemaException
- if the id is present and is invalid or is a duplicate
-
allocateAnonymousTypeCode
Allocate a name to an anonymous type. It's important that the name allocated should be repeatable, because it can be referenced as a type annotation in a SEF document.- Returns:
- the name code of the allocated name
-
processMaxOccurs
Process the value of a maxOccurs attribute on any element where it appears- Parameters:
attValue
- the value of the attribute as written, either "unbounded" or an integer- Returns:
- the value of the attribute as an integer, or -1 indicating "unbounded"
- Throws:
SchemaException
- if the value is invalid (in which case the error will have been reported). If the value is a very high integer (greater than Integer.MAX_VALUE), the method outputs a warning and treats the value as "unbounded".
-
processMinOccurs
Process the value of a minOccurs attribute on any element where it appears- Parameters:
attValue
- the value of the attribute as written, an integer- Returns:
- the value of the attribute as an integer
- Throws:
SchemaException
- if the value is invalid (in which case the error will have been reported). If the value is a very high integer (greater than Integer.MAX_VALUE), the method outputs a warning and treats the value as Integer.MAX_VALUE.
-
checkContentModel
protected void checkContentModel(int[][] stateTerms, int[][] stateTargets, boolean allowWildcards) throws SchemaException Check the content model of an element in the schema. This uses a finite state machine generated into the Java source code by applying an XSLT transformation to the schema component model for the Schema for Schemas.The finite state machine is generated as follows: First process the S4S to create an SCM model, then apply the stylesheet generate-S4S-code in the build directory with type=complexType, for example. The value of the type parameter can be either the name of the type or its ID in the SCM file.
- Parameters:
stateTerms
- an array of states, and for each state, an array containing the fingerprints of elements allowed to appear in that statestateTargets
- an array of states, and for each state, an array containing the destinations of transitions when the corresponding term from stateTerms is encounteredallowWildcards
- true if wildcard transitions are allowed- Throws:
SchemaException
- if the schema being processed does not conform to the required content model
-
isFinalState
protected boolean isFinalState(int state) For elements whose content model is parsed using a finite state machine, test whether a given state is a final state. The default implementation of this method is never used; it exists for the benefit of subclasses that do not use this mechanism- Parameters:
state
- the state to be tested- Returns:
- true if the given state is a final state
-
processAllowedNamespaces
Process the namespaces attribute of XSDAny or XSDAnyAttribute- Parameters:
attValue
- the value of the attributewildcard
- the wildcard object being constructed- Throws:
SchemaException
- if the attribute is in error
-
processDisallowedNamespaces
protected void processDisallowedNamespaces(String attValue, Wildcard wildcard) throws SchemaException Process the notNamespaces attribute of XSDAny or XSDAnyAttribute- Parameters:
attValue
- the value of the attributewildcard
- the wildcard object being constructed- Throws:
SchemaException
- if the attribute is in error
-
processDisallowedQNames
Process the notQNames attribute of XSDAny or XSDAnyAttribute- Parameters:
attValue
- the value of the attributewildcard
- the wildcard object being constructed- Throws:
SchemaException
- if the attribute is in error
-
checkLocalTargetNamespace
For an element or attribute declaration with a targetNamespace attribute (XSD 1.1), check the highly-paternalistic rules for when this attribute is permitted.- Parameters:
elementOrAttribute
- the string "element" or "attribute" for error messages- Throws:
SchemaException
- if the rules are not satisfied
-