public abstract class SchemaElement extends ElementImpl
Modifier and Type | Class and Description |
---|---|
protected class |
SchemaElement.XPathStaticContext |
Modifier and Type | Field and Description |
---|---|
protected static String |
NAMESPACE_ANY |
protected static String |
NAMESPACE_LOCAL |
protected static String |
NAMESPACE_OTHER |
protected static String |
NAMESPACE_TARGET |
static int |
REQUIRE_NULL_NS
Option indicating "no namespace prefix is allowed; the name is in the null Namespace"
|
static int |
REQUIRE_TARGET_NS
Option indicating "no namespace prefix is allowed; the name is in the targetNamespace"
|
static int |
USE_DEFAULT_NS
Option indicating "use the default element namespace when unprefixed"
|
static int |
USE_DEFAULT_NS_WITHOUT_IMPORT
Option indicating "use the default element namespace when unprefixed", but without a requirement
to have an xs:import
|
NODE_LETTER
ALL_NAMESPACES, IS_DTD_TYPE, IS_NILLED, LOCAL_NAMESPACES, NO_NAMESPACES
Constructor and Description |
---|
SchemaElement()
Construct a SchemaElement
|
Modifier and Type | Method and Description |
---|---|
protected void |
addChild(NodeImpl node,
int index)
Add a child node to this node.
|
protected int |
allocateAnonymousTypeCode()
Allocate a name to an anonymous type.
|
void |
allowAttributes(AttributeCollection 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 do
|
protected void |
checkOnlyChildIsAnnotation()
Check that the only child element of this element is an
(optional and non-repeatable) xs:annotation element
|
void |
checkPermittedType(int fp,
String name,
String role)
Check that a given type is a permitted type
|
void |
compact(int size)
Compact the space used by this node
|
protected void |
duplicate(String category,
String name)
This method is called when two objects in the same symbol space within
a schema have duplicate names
|
protected void |
duplicateElement(String name)
This method is called when two occurrences of a child element are found
and only one is allowed.
|
protected void |
error(SchemaException exception)
This method is called for a general error.
|
protected void |
error(String err)
This method is called for a general error.
|
protected UserComplexType |
getContainingComplexType()
Get the complexType associated with the containing xs:complexType element
|
protected SimpleTypeDefinition |
getContainingSimpleType()
Get the simpleTypeDefinition associated with the containing xs:simpleType element
|
protected 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.
|
NodeImpl |
getFirstChild()
Get the first child node of the element
|
NodeImpl |
getLastChild()
Get the last child node of the element
|
protected int |
getNameCode(String name,
int option)
This method is called to check that a QName is valid and allocate a
nameCode for the name in the namePool.
|
protected NodeImpl |
getNthChild(int n)
Get the nth child node of the element (numbering from 0)
|
int |
getNumberOfChildren()
Determine how many children the node has
|
protected int |
getRawSequenceNumber() |
protected SingleNamespaceSchema |
getSchema()
Get the schema corresponding to the contents of the schema document containing this element
|
SchemaNodeFactory |
getSchemaNodeFactory()
Get the nodeFactory used to create this element.
|
protected long |
getSequenceNumber()
Get the node sequence number (in document order).
|
String |
getStringValue()
Return the string-value of the node, that is, the concatenation
of the character content of all descendent elements and text nodes.
|
CharSequence |
getStringValueCS()
Get the value of the item as a CharSequence.
|
XSDSchema |
getXSDSchema()
Get the owning XSDSchema element.
|
boolean |
hasChildNodes()
Determine if the node has any children.
|
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 English
|
void |
insertChildren(NodeInfo[] source,
boolean atStart,
boolean inherit)
Insert a sequence of nodes as children of this node.
|
protected void |
insertChildrenAt(NodeInfo[] source,
int index,
boolean inherit)
Insert children before or after a given existing child
|
void |
invalidAttributeValue(String name,
String value,
String message)
This method is called when an invalid attribute value is found
|
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.
|
protected boolean |
isTopLevel()
Return true if this element is a child of xs:schema or xs:redefine
|
protected AxisIterator |
iterateChildren(NodeTest test)
Get an enumeration of the children of this node
|
protected SavedNamespaceContext |
makeNamespaceContext()
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 found
|
void |
missingChildElement(String name)
This method is called when a required child element is not found
|
protected void |
mustBeFirstElement(String name)
This method is called when a child element is required to be the first
child, but is found elsewhere
|
void |
mustBeLastElement(String name)
This method is called when a child element is required to be the first
child, but is found elsewhere
|
protected 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 coexist
|
protected void |
mutuallyExclusiveAttributes(String name1,
String name2)
This method is called when two attributes may not coexist
|
protected void |
mutuallyExclusiveElementAndAttribute(String elem,
String att)
This method is called when an attribute and a child elements may not coexist
|
boolean |
parseBooleanAttribute(String name,
String value)
Parse a boolean attribute value
|
int |
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.
|
abstract void |
prepareAttributes()
Set the attribute list for the element.
|
void |
processAllAttributes()
Process the attributes of this element and all its children
|
protected void |
processAllowedNamespaces(String attValue,
Wildcard wildcard)
Process the namespaces attribute of XSDAny or XSDAnyAttribute
|
protected void |
processDisallowedNamespaces(String attValue,
Wildcard wildcard)
Process the notNamespaces attribute of XSDAny or XSDAnyAttribute
|
protected void |
processDisallowedQNames(String attValue,
Wildcard wildcard)
Process the notQNames attribute of XSDAny or XSDAnyAttribute
|
void |
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
|
int |
processMaxOccurs(String attValue)
Process the value of a maxOccurs attribute on any element where it appears
|
int |
processMinOccurs(String attValue)
Process the value of a minOccurs attribute on any element where it appears
|
protected void |
removeChild(NodeImpl child)
Remove a given child
|
protected void |
replaceChildrenAt(NodeInfo[] source,
int index,
boolean inherit)
Replace child at a given index by new children
|
void |
requireAttribute(AttributeCollection atts,
String required)
Indicate that a particular attribute is required
|
protected void |
setChildren(Object children)
Set the children of this node
|
protected void |
setRawSequenceNumber(int seq) |
void |
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 nodes
|
protected void |
warning(String err)
Report a warning
|
addAttribute, addNamespace, copy, delete, fixupInsertedNamespaces, generateId, getAttributeList, getAttributeValue, getAttributeValue, getBaseURI, getColumnNumber, getDeclaredNamespaces, getDocumentRoot, getLineNumber, getNameCode, getNamespaceList, getNodeKind, getRoot, getSchemaType, getSystemId, getTypeAnnotation, getURIForPrefix, gsetAttributeCollection, initialise, isId, isInScopeNamespace, isNilled, iteratePrefixes, removeAttribute, removeTypeAnnotation, rename, replaceStringValue, setAttributeList, setLocation, setNameCode, setNamespaceDeclarations, setNamespaceList, setSystemId, setTypeAnnotation
atomize, compareOrder, comparePosition, equals, getConfiguration, getDisplayName, getDocumentNumber, getFingerprint, getLocalPart, getNamePool, getNextInDocument, getNextSibling, getParent, getPhysicalRoot, getPrefix, getPreviousInDocument, getPreviousSibling, getPublicId, getRawParent, getSiblingPosition, getSuccessorElement, getURI, head, insertSiblings, isDeleted, isIdref, isSameNodeInfo, iterate, iterateAxis, iterateAxis, newBuilder, replace, setRawParent, setSiblingPosition
public static final int USE_DEFAULT_NS
public static final int REQUIRE_TARGET_NS
public static final int REQUIRE_NULL_NS
public static final int USE_DEFAULT_NS_WITHOUT_IMPORT
protected static final String NAMESPACE_ANY
protected static final String NAMESPACE_LOCAL
protected static final String NAMESPACE_OTHER
protected static final String NAMESPACE_TARGET
protected boolean isTopLevel()
public void setSchemaNodeFactory(SchemaNodeFactory factory)
factory
- the schema node factorypublic SchemaNodeFactory getSchemaNodeFactory()
public void processAllAttributes() throws SchemaException
SchemaException
public abstract void prepareAttributes() throws SchemaException
SchemaException
public void allowAttributes(AttributeCollection atts, String[] allowed) throws SchemaException
atts
- the attributes actually presentallowed
- the attributes that are allowed for this element. They must
be listed in alphabetical orderSchemaException
public void requireAttribute(AttributeCollection atts, String required) throws SchemaException
atts
- the attribtue collectionrequired
- the local name of the required attribute, which must be in the null namespaceSchemaException
public void validateSubtree(SchemaCompiler compiler) throws SchemaException
compiler
- used for error reportingSchemaException
protected void validateChildren(SchemaCompiler compiler) throws SchemaException
compiler
- used for error reportingSchemaException
- if the subtree is not validpublic void validate(SchemaCompiler compiler) throws SchemaException
compiler
- used for error reportingSchemaException
- if the subtree is not validpublic void postValidate(SchemaCompiler compiler) throws SchemaException
compiler
- used for error reportingSchemaException
- if errors are foundpublic XSDSchema getXSDSchema() throws SchemaException
SchemaException
- if none is found (which means the schema is invalid)protected SingleNamespaceSchema getSchema() throws SchemaException
SchemaException
- if the containing PreparedSchema cannot be foundprotected UserComplexType getContainingComplexType() throws SchemaException
SchemaException
- if the element is not contained in an xs:complexTypeprotected SimpleTypeDefinition getContainingSimpleType() throws SchemaException
SchemaException
- if not contained in an xs:simpleTypeprotected SavedNamespaceContext makeNamespaceContext()
public void checkPermittedType(int fp, String name, String role) throws SchemaException
SchemaException
public boolean parseBooleanAttribute(String name, String value) throws SchemaException
name
- the name of the attribute (for diagnostics)value
- the string value of the attribute (need not be trimmed)SchemaException
- if the value is not a valid booleanprotected void error(String err) throws SchemaException
err
- the error message to reportSchemaException
protected void error(SchemaException exception) throws SchemaException
exception
- the error message to reportSchemaException
protected void warning(String err)
err
- the warning messageprotected int getFingerprint(String name, int option) throws SchemaException
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.SchemaException
- if the QName is invalid.protected int getNameCode(String name, int option) throws SchemaException
name
- The QNameoption
- The option for handling unprefixed names. Options are
to use the default namespace USE_DEFAULT_NS
,
the target namespace REQUIRE_TARGET_NS
, or the null namespace
REQUIRE_NULL_NS
SchemaException
- if the QName is invalid.protected void checkOnlyChildIsAnnotation() throws SchemaException
SchemaException
protected void illegalElement(NodeInfo child) throws SchemaException
child
- The child element whose presence is an errorSchemaException
- thrown if the errorListener
decides that it's a fatal error.protected void duplicateElement(String name) throws SchemaException
name
- the name of the illegal elementSchemaException
- thrown if the errorListener
decides that it's a fatal error.protected void duplicate(String category, String name) throws SchemaException
category
- the name of the first attributename
- the name of the second attributeSchemaException
- thrown if the errorListener
decides that it's a fatal error.protected void mutuallyExclusive(String name1, String name2) throws SchemaException
name1
- the name of the first elementname2
- the name of the second elementSchemaException
- thrown if the errorListener
decides that it's a fatal error.protected void mutuallyExclusiveElementAndAttribute(String elem, String att) throws SchemaException
elem
- the name of the elementatt
- the name of the attributeSchemaException
- thrown if the errorListener
decides that it's a fatal error.protected void mutuallyExclusiveAttributes(String name1, String name2) throws SchemaException
name1
- the name of the first attributename2
- the name of the second attributeSchemaException
- thrown if the errorListener
decides that it's a fatal error.protected void checkMutuallyExclusiveAttributes(String name1, String name2) throws SchemaException
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)SchemaException
protected void mustPrecede(String name1, String name2) throws SchemaException
name1
- the name of the element that should be firstname2
- the name of the element that should be secondSchemaException
- thrown if the errorListener
decides that it's a fatal error.protected void mustBeFirstElement(String name) throws SchemaException
name
- the name of the illegal elementSchemaException
- thrown if the errorListener
decides that it's a fatal error.protected String indefiniteArticle(String word, String start)
word
- The word to follow the articlestart
- Typically "a" or "A"public void mustBeLastElement(String name) throws SchemaException
name
- the name of the illegal elementSchemaException
- thrown if the errorListener
decides that it's a fatal error.public void invalidAttributeValue(String name, String value, String message) throws SchemaException
name
- the name of the attributevalue
- the supplied value of the attributemessage
- additional explanation of why it's wrong. May be null.SchemaException
- thrown if the errorListener
decides that it's a fatal error.public void missingAttribute(String name) throws SchemaException
name
- the name of the attributeSchemaException
- thrown if the errorListener
decides that it's a fatal error.public void missingChildElement(String name) throws SchemaException
name
- the name of the required child elementSchemaException
- thrown if the errorListener
decides that it's a fatal error.public int parseFinalOrBlock(String attrName, String finalValue, int allowed) throws SchemaException
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.SchemaException
- if the value of the attribute is invalidpublic void processId() throws SchemaException
SchemaException
- if the id is present and is invalid or is a duplicateprotected int allocateAnonymousTypeCode()
public int processMaxOccurs(String attValue) throws SchemaException
attValue
- the value of the attribute as written, either "unbounded" or an integerSchemaException
- 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".public int processMinOccurs(String attValue) throws SchemaException
attValue
- the value of the attribute as written, an integerSchemaException
- 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.protected void checkContentModel(int[][] stateTerms, int[][] stateTargets, boolean allowWildcards) throws SchemaException
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.
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
- SchemaException
- if the schema being processed does not conform to the required content modelprotected boolean isFinalState(int state)
state
- the state to be testedprotected void processAllowedNamespaces(String attValue, Wildcard wildcard) throws SchemaException
attValue
- the value of the attributewildcard
- the wildcard object being constructedSchemaException
- if the attribute is in errorprotected void processDisallowedNamespaces(String attValue, Wildcard wildcard) throws SchemaException
attValue
- the value of the attributewildcard
- the wildcard object being constructedSchemaException
- if the attribute is in errorprotected void processDisallowedQNames(String attValue, Wildcard wildcard) throws SchemaException
attValue
- the value of the attributewildcard
- the wildcard object being constructedSchemaException
- if the attribute is in errorpublic void checkLocalTargetNamespace(String elementOrAttribute) throws SchemaException
elementOrAttribute
- the string "element" or "attribute" for error messagesSchemaException
- if the rules are not satisfiedprotected final long getSequenceNumber()
getSequenceNumber
in class NodeImpl
protected final int getRawSequenceNumber()
protected final void setRawSequenceNumber(int seq)
protected final void setChildren(Object children)
children
- null if there are no children, a single NodeInfo if there is one child, an array of NodeInfo
if there are multiple childrenpublic final boolean hasChildNodes()
hasChildNodes
in interface NodeInfo
hasChildNodes
in class NodeImpl
true
if the node has any children,
false
if the node has no children.public final int getNumberOfChildren()
protected final AxisIterator iterateChildren(NodeTest test)
test
- A NodeTest to be satisfied by the child nodes, or null
if all child node are to be returnedpublic final NodeImpl getFirstChild()
getFirstChild
in interface SteppingNode<NodeImpl>
getFirstChild
in class NodeImpl
public final NodeImpl getLastChild()
getLastChild
in class NodeImpl
protected final NodeImpl getNthChild(int n)
n
- identifies the required childprotected void removeChild(NodeImpl child)
child
- the child to be removedpublic String getStringValue()
Item.getStringValueCS()
public CharSequence getStringValueCS()
NodeImpl
getStringValueCS
in interface Item
getStringValueCS
in class NodeImpl
Item.getStringValue()
protected void addChild(NodeImpl node, int index)
node
- the node to be added as a child of this node. This must be an instance of
NodeImpl
. It will be modified as a result of this call (by setting its
parent property and sibling position)index
- the position where the child is to be addedpublic void insertChildren(NodeInfo[] source, boolean atStart, boolean inherit)
This method takes no action unless the target node is a document node or element node. It also takes no action in respect of any supplied nodes that are not elements, text nodes, comments, or processing instructions.
The supplied nodes will form the new children. Adjacent text nodes will be merged, and zero-length text nodes removed. The supplied nodes may be modified in situ, for example to change their parent property and to add namespace bindings, or they may be copied, at the discretion of the implementation.
insertChildren
in interface MutableNodeInfo
insertChildren
in class NodeImpl
source
- the nodes to be inserted. The implementation determines what implementation classes
of node it will accept; this implementation will accept text, comment, and processing instruction
nodes belonging to any implementation, but elements must be instances of ElementImpl
.
The supplied nodes will be modified in situ, for example
to change their parent property and to add namespace bindings, if they are instances of
ElementImpl
; otherwise they will be copied. If the nodes are copied, then on return
the supplied source array will contain the copy rather than the original.atStart
- true if the new nodes are to be inserted before existing children; false if they are
to be inserted after existing childreninherit
- true if the inserted nodes are to inherit the namespaces of their new parent; false
if such namespaces are to be undeclaredIllegalArgumentException
- if the supplied nodes use a node implementation that this
implementation does not accept.protected void insertChildrenAt(NodeInfo[] source, int index, boolean inherit)
source
- the children to be inserted. We allow any kind of text, comment, or processing instruction
node, but element nodes must be instances of this NodeInfo implementation.index
- the position before which they are to be inserted: 0 indicates insertion before the
first child, 1 insertion before the second child, and so on.inherit
- true if the inserted nodes are to inherit the namespaces that are in-scope for their
new parent; false if such namespaces should be undeclared on the childrenprotected void replaceChildrenAt(NodeInfo[] source, int index, boolean inherit)
source
- the children to be insertedindex
- the position at which they are to be inserted: 0 indicates replacement of the
first child, replacement of the second child, and so on. The effect is undefined if index
is out of rangeinherit
- set to true if the new child elements are to inherit the in-scope namespaces
of their new parentIllegalArgumentException
- if any of the replacement nodes is not an element, text,
comment, or processing instruction nodepublic void compact(int size)
size
- the number of actual childrenCopyright (c) 2004-2014 Saxonica Limited. All rights reserved.