public class XSDCompiler
extends java.lang.Object
For example, in the "Russian Doll" style, the schemaRoot has one global element definition and all other definitions are local, contained in a nested tree. In the "Salami" style, all element definitions are global at the top level, but their internal type structure uses references to refer to other elements. In the "Venetian Blind" style, there is a single global element definition, with all other elements defined locally; however the types of each element are separately defined in the global namespace. The job of XSDCompiler is to build either a single-rooted tree of grammar rules, or a multiple-rooted graph of shared rules, where the Schema provides more than one possible entry point into the grammar.
The result of processing the schemaRoot is an XML grammar, represented as a graph of GrammarRule objects. XSDCompiler verifies that each GrammarRule is properly defined, such that every element identifier encountered in a production also has a corresponding ElementRule definition; and it verifies that the grammar is fully connected, such that no unreachable ElementRule objects exist.
Modifier and Type | Field and Description |
---|---|
private java.util.Map<java.lang.String,AttributeRule> |
attributeRules
A dictionary of global AttributeRule objects, indexed by XSD attribute
name.
|
private java.util.Map<java.lang.String,ElementRule> |
elementRules
A dictionary of ElementRule objects, indexed by XSD element name.
|
private Element |
schemaRoot
The XML schema root analysed by this XSDCompiler.
|
private java.util.Map<java.lang.String,Filter> |
simpleFilters
A dictionary of Filter objects, indexed by XSD simple type name.
|
Constructor and Description |
---|
XSDCompiler(XMLSchema schema)
Creates an XSDCompiler to analyse the given XML Schema.
|
Modifier and Type | Method and Description |
---|---|
private AttributeRule |
analyseAttribute(Element node)
Creates an AttributeRule for an XSD attribute node.
|
private java.util.List<GrammarRule> |
analyseAttributeGroupRef(Element node)
Creates a list of AttributeRules for an XSD attributeGroup reference.
|
private AttributeRule |
analyseAttributeRef(Element node)
Looks up a global XSD attribute reference.
|
private CompoundRule |
analyseComplexContent(Element node)
Creates a CompoundRule for an XSD complexContent node.
|
private java.util.List<GrammarRule> |
analyseComplexType(Element node)
Creates a List of GrammarRules corresponding to an XSD complex type.
|
private GrammarRule |
analyseCompoundContent(Element node)
Creates a GrammarRule for some nested XSD element or compound node.
|
private CompoundRule |
analyseCompoundType(Element node)
Creates a CompoundRule for a given XSD sequence, choice, or all node.
|
private void |
analyseDocument(Element node)
Analyses the top-level global definitions under the XSD schemaRoot node.
|
private ElementRule |
analyseElement(Element node)
Creates an ElementRule for an XSD element node.
|
private ElementRule |
analyseElementRef(Element node)
Looks up a global XSD element reference.
|
private Filter |
analyseEnumeration(Element node)
Creates a RangeFilter for an XSD restriction which contains XSD
enumeration children nodes.
|
private CompoundRule |
analyseGroupRef(Element node)
Creates a CompoundRule for an XSD group reference.
|
private Filter |
analyseListType(Element node)
Determines what filter to return for an XSD list or XSD union type.
|
private GrammarRule |
analyseMultiplicity(Element node)
Secret method that optionally creates an IterationRule if one is needed.
|
private Filter |
analysePattern(Element node)
Creates a PatternFilter for an XSD restriction which contains an XSD
pattern child node.
|
private Filter |
analyseRestriction(Element node)
Creates a RestrictFilter or a WidthFilter for any other kind of XSD
restriction.
|
private java.util.List<GrammarRule> |
analyseSimpleContent(Element node)
Creates a list of GrammarRules for an XSD simpleContent node.
|
private Filter |
analyseSimpleType(Element node)
Determines the Filter to use for any XSD simple type.
|
private java.lang.String |
getContext(Content node)
Returns the context of an error message as an XPath-style string.
|
private Element |
lookup(java.lang.String elementKind,
java.lang.String nameValue)
Searches the schemaRoot for an Element of a given kind, with a given
value for its name attribute.
|
private int |
parseOccurrence(java.lang.String value)
Converts an occurrence attribute value into an integer multiplicity.
|
java.util.Map<java.lang.String,ElementRule> |
readGrammar()
Analyses the grammar specified by the XML Schema to build a grammar
rooted in one or more ElementRules.
|
private void |
semanticError(java.lang.String message,
Element node)
Throws a SemanticError giving full diagnostic information.
|
private Element schemaRoot
private java.util.Map<java.lang.String,ElementRule> elementRules
private java.util.Map<java.lang.String,AttributeRule> attributeRules
private java.util.Map<java.lang.String,Filter> simpleFilters
public XSDCompiler(XMLSchema schema)
schema
- the XML Schema.public java.util.Map<java.lang.String,ElementRule> readGrammar() throws SemanticError
SemanticError
- if the XSD contains semantic errors.private void semanticError(java.lang.String message, Element node) throws SemanticError
message
- the error message.node
- the erroneous schemaRoot Element.SemanticError
- deliberately.private java.lang.String getContext(Content node)
node
- the context of an error.private Element lookup(java.lang.String elementKind, java.lang.String nameValue)
elementKind
- the name of the kind of Element.nameValue
- the value of the Element's name.private void analyseDocument(Element node)
node
- the XSD schemaRoot node.private ElementRule analyseElementRef(Element node)
node
- the XSD element node.private ElementRule analyseElement(Element node)
node
- the XSD element node.private AttributeRule analyseAttributeRef(Element node)
node
- the XSD attribute node.private AttributeRule analyseAttribute(Element node)
node
- the XSD attribute node.private java.util.List<GrammarRule> analyseComplexType(Element node)
node
- the XSD complexType node.private CompoundRule analyseCompoundType(Element node)
node
- the XSD sequence, choice or all node.private GrammarRule analyseCompoundContent(Element node)
node
- an XSD element, group or compound specifier node.private CompoundRule analyseGroupRef(Element node)
node
- the XSD group reference node.private java.util.List<GrammarRule> analyseAttributeGroupRef(Element node)
node
- the XSD attributeGroup reference node.private java.util.List<GrammarRule> analyseSimpleContent(Element node)
node
- the XSD simpleContent node.private CompoundRule analyseComplexContent(Element node)
node
- the XSD complexContent node.private Filter analyseSimpleType(Element node)
node
- the XSD simpleType node.private Filter analyseListType(Element node) throws SemanticError
node
- the XSD list, or XSD union node.SemanticError
- if the component types are not basic types.private Filter analyseEnumeration(Element node)
node
- the XSD restriction node.private Filter analysePattern(Element node)
node
- the XSD restriction node.private Filter analyseRestriction(Element node)
node
- the XSD restriction nodeprivate GrammarRule analyseMultiplicity(Element node) throws SemanticError
node
- an XSD grammar node.SemanticError
- if the occurrence constraint is invalid.private int parseOccurrence(java.lang.String value) throws java.lang.NumberFormatException
value
- the value of 'minOccurs' or 'maxOccurs'.java.lang.NumberFormatException
- if the String cannot be converted into
a number.