com.saxonica.sdoc
Class SchemaElement

java.lang.Object
  extended by net.sf.saxon.tree.NodeImpl
      extended by net.sf.saxon.tree.ElementImpl
          extended by net.sf.saxon.tree.ElementWithAttributes
              extended by com.saxonica.sdoc.SchemaElement
All Implemented Interfaces:
Source, SourceLocator, PullEvent, FingerprintedNode, Item, NamespaceResolver, NodeInfo, ValueRepresentation
Direct Known Subclasses:
AnnotationParent, UnknownElement, XSDAnnotation, XSDAttribute, XSDAttributeGroup, XSDComplexContent, XSDComplexContentRestriction, XSDComplexType, XSDCompositor, XSDDocumentation, XSDElement, XSDExtension, XSDGroup, XSDIdentityConstraint, XSDList, XSDRedefine, XSDSchema, XSDSimpleContent, XSDSimpleContentRestriction, XSDSimpleType, XSDSimpleTypeRestriction, XSDUnion

public abstract class SchemaElement
extends ElementWithAttributes

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


Field Summary
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"
 
Fields inherited from class net.sf.saxon.tree.NodeImpl
NODE_LETTER
 
Fields inherited from interface net.sf.saxon.om.NodeInfo
ALL_NAMESPACES, EMPTY_NAMESPACE_LIST, IS_DTD_TYPE, IS_NILLED, LOCAL_NAMESPACES, NO_NAMESPACES
 
Fields inherited from interface net.sf.saxon.om.ValueRepresentation
EMPTY_VALUE_ARRAY
 
Constructor Summary
SchemaElement()
          Construct a SchemaElement
 
Method Summary
 void addChild(NodeImpl node, int index)
          Add a child node to this node.
 void allowAttributes(AttributeCollection atts, String[] allowed)
          Check the attributes of an element against a list of allowed attributes.
 void compact(int size)
          Compact the space used by this node
 NodeInfo getFirstChild()
          Get the first child node of the element
 NodeInfo getLastChild()
          Get the last child node of the element
 int getLineNumber()
          Get the line number
 SchemaNodeFactory getSchemaNodeFactory()
          Get the nodeFactory used to create this element.
 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.
 boolean hasChildNodes()
          Determine if the node has any children.
 void invalidAttributeValue(String name, String value, String message)
          This method is called when an invalid attribute value is found
 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
 void mustBeLastElement(String name)
          This method is called when a child element is required to be the first child, but is found elsewhere
 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
 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
 void requireAttribute(AttributeCollection atts, String required)
          Indicate that a particular attribute is required
 void setLineNumber(int line)
          Set the line number
 void setSchemaNodeFactory(SchemaNodeFactory factory)
          Set the nodeFactory used to create this element.
 void validate(SchemaCompiler compiler)
          Check that the schema element is valid.
 void validateSubtree(SchemaCompiler compiler)
          Recursive walk through the schema to validate all nodes
 
Methods inherited from class net.sf.saxon.tree.ElementWithAttributes
copy, getAttributeList, getAttributeValue, getDeclaredNamespaces, getInScopeNamespaceCodes, getPrefixForURI, getURICodeForPrefix, getURIForPrefix, initialise, iteratePrefixes, setNamespaceDeclarations
 
Methods inherited from class net.sf.saxon.tree.ElementImpl
generateId, getBaseURI, getDocumentRoot, getNameCode, getNodeKind, getRoot, getSystemId, setNameCode, setSystemId
 
Methods inherited from class net.sf.saxon.tree.NodeImpl
atomize, compareOrder, equals, getColumnNumber, getConfiguration, getDisplayName, getDocumentNumber, getFingerprint, getLocalPart, getNamePool, getNextInDocument, getNextSibling, getParent, getPrefix, getPreviousInDocument, getPreviousSibling, getPublicId, getTypeAnnotation, getTypedValue, getURI, hashCode, isSameNodeInfo, iterateAxis, iterateAxis
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

USE_DEFAULT_NS

public static final int USE_DEFAULT_NS
Option indicating "use the default element namespace when unprefixed"

See Also:
Constant Field Values

REQUIRE_TARGET_NS

public static final int REQUIRE_TARGET_NS
Option indicating "no namespace prefix is allowed; the name is in the targetNamespace"

See Also:
Constant Field Values

REQUIRE_NULL_NS

public static final int REQUIRE_NULL_NS
Option indicating "no namespace prefix is allowed; the name is in the null Namespace"

See Also:
Constant Field Values
Constructor Detail

SchemaElement

public SchemaElement()
Construct a SchemaElement

Method Detail

setSchemaNodeFactory

public void setSchemaNodeFactory(SchemaNodeFactory factory)
Set the nodeFactory used to create this element.

Parameters:
factory - the schema node factory

getSchemaNodeFactory

public SchemaNodeFactory 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

setLineNumber

public void setLineNumber(int line)
Set the line number

Overrides:
setLineNumber in class ElementImpl
Parameters:
line - the line number

getLineNumber

public int getLineNumber()
Get the line number

Specified by:
getLineNumber in interface SourceLocator
Specified by:
getLineNumber in interface NodeInfo
Overrides:
getLineNumber in class ElementImpl
Returns:
the line number of the node in its original source document; or -1 if not available

processAllAttributes

public void processAllAttributes()
                          throws SchemaException
Process the attributes of this element and all its children

Throws:
SchemaException

prepareAttributes

public abstract void prepareAttributes()
                                throws SchemaException
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

public void allowAttributes(AttributeCollection atts,
                            String[] allowed)
                     throws SchemaException
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 present
allowed - the attributes that are allowed for this element. Note that
Throws:
SchemaException

requireAttribute

public void requireAttribute(AttributeCollection atts,
                             String required)
                      throws SchemaException
Indicate that a particular attribute is required

Parameters:
atts - the attribtue collection
required - the local name of the required attribute, which must be in the null namespace
Throws:
SchemaException

validateSubtree

public void validateSubtree(SchemaCompiler compiler)
                     throws SchemaException
Recursive walk through the schema to validate all nodes

Parameters:
compiler - used for error reporting
Throws:
SchemaException

validate

public void validate(SchemaCompiler compiler)
              throws SchemaException
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

public void postValidate(SchemaCompiler compiler)
                  throws SchemaException
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

mustBeLastElement

public void mustBeLastElement(String name)
                       throws SchemaException
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.

invalidAttributeValue

public void invalidAttributeValue(String name,
                                  String value,
                                  String message)
                           throws SchemaException
This method is called when an invalid attribute value is found

Parameters:
name - the name of the attribute
value - the supplied value of the attribute
message - additional explanation of why it's wrong. May be null.
Throws:
SchemaException - thrown if the errorListener decides that it's a fatal error.

missingAttribute

public void missingAttribute(String name)
                      throws SchemaException
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

public void missingChildElement(String name)
                         throws SchemaException
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 parsed
finalValue - 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

processId

public void processId()
               throws SchemaException
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

processMaxOccurs

public int processMaxOccurs(String attValue)
                     throws SchemaException
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

public int processMinOccurs(String attValue)
                     throws SchemaException
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.

hasChildNodes

public final boolean hasChildNodes()
Determine if the node has any children.

Specified by:
hasChildNodes in interface NodeInfo
Overrides:
hasChildNodes in class NodeImpl
Returns:
true if the node has any children, false if the node has no children.

getFirstChild

public final NodeInfo getFirstChild()
Get the first child node of the element

Overrides:
getFirstChild in class NodeImpl
Returns:
the first child node of the required type, or null if there are no children

getLastChild

public final NodeInfo getLastChild()
Get the last child node of the element

Overrides:
getLastChild in class NodeImpl
Returns:
the last child of the element, or null if there are no children

getStringValue

public String getStringValue()
Return the string-value of the node, that is, the concatenation of the character content of all descendent elements and text nodes.

Returns:
the accumulated character content of the element, including descendant elements.
See Also:
Item.getStringValueCS()

getStringValueCS

public CharSequence getStringValueCS()
Description copied from class: NodeImpl
Get the value of the item as a CharSequence. This is in some cases more efficient than the version of the method that returns a String.

Specified by:
getStringValueCS in interface Item
Specified by:
getStringValueCS in interface ValueRepresentation
Overrides:
getStringValueCS in class NodeImpl
Returns:
the string value of the item
See Also:
Item.getStringValue()

addChild

public void addChild(NodeImpl node,
                     int index)
Add a child node to this node. For system use only. Note: normalizing adjacent text nodes is the responsibility of the caller.

Parameters:
node - the node to be added as a child of this node
index - the position where the child is to be added

compact

public void compact(int size)
Compact the space used by this node

Parameters:
size - the number of actual children


Copyright (C) Michael H. Kay. All rights reserved.