Class XmlSchemaPathFinder<U,V>
java.lang.Object
org.xml.sax.helpers.DefaultHandler
org.apache.ws.commons.schema.docpath.XmlSchemaPathFinder<U,V>
- All Implemented Interfaces:
ContentHandler,DTDHandler,EntityResolver,ErrorHandler
Performs a SAX-based walk through the XML document, determining the
interpretation ("path") that best matches the XML Schema.
This is a traditional DefaultHandler that can be attached to either a
SAXParser during a parse, or to
SaxWalkerOverDom to find paths through an
Document.
Because this is a SAX-based walk, the source information need not be an XML document. It can be any data that can be interpreted via a SAX walk. This can be helpful when trying to confirm the source data can be converted back into XML.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classprivate static enumprivate static final classprivate static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate XmlSchemaPathNode<U, V> private ArrayList<XmlSchemaPathFinder.DecisionPoint<U, V>> private static final intprivate final XmlSchemaNamespaceContextprivate XmlSchemaPathManager<U, V> private XmlSchemaPathNode<U, V> -
Constructor Summary
ConstructorsConstructorDescriptionCreates a newXmlToAvroPathCreatorwith the rootXmlSchemaStateMachineNodeto start from when evaluating documents. -
Method Summary
Modifier and TypeMethodDescriptionvoidcharacters(char[] ch, int start, int length) Adds a newXmlSchemaPathNode.Direction.CONTENTXmlSchemaPathNodeto the path.voidCalled when the XML Document traversal is complete.voidendElement(String uri, String localName, String qName) Ends the current element.voidendPrefixMapping(String prefix) Handles the end of a prefix mapping in the SAX walk.private List<XmlSchemaPathFinder.PathSegment<U, V>> find(XmlSchemaPathNode<U, V> startNode, QName elemQName) private List<XmlSchemaPathFinder.PathSegment<U, V>> find(XmlSchemaPathNode<U, V> startNode, QName elemQName, int currDepth) private List<XmlSchemaPathFinder.PathSegment<U, V>> find(XmlSchemaPathNode<U, V> startNode, QName elemQName, XmlSchemaStateMachineNode doNotFollow) private voidprivate Stringprivate Stringprivate XmlSchemaStateMachineNodeOnce a traversal completes successfully, this method may be called to retrieve the relevant interpretation of the path through theXmlSchemaStateMachineNodes.private static <U,V> XmlSchemaPathFinder.Fulfillment isPositionFulfilled(XmlSchemaPathNode<U, V> currentPath, List<Integer> possiblePaths) voidKick-starts a new SAX walk, building newXmlSchemaPathNodeandXmlSchemaDocumentNodetraversals in the process.voidstartElement(String uri, String localName, String qName, Attributes atts) Find the path through the XML Schema that best matches this element, traversing any relevant groups, and backtracking if necessary.voidstartPrefixMapping(String prefix, String uri) Handles a new prefix mapping in the SAX walk.private voidvalidateAttributes(Attributes attrs) private voidverifyCurrentPositionIsAtElement(String errMsgPrefix) private voidwalkUpToElement(QName element) private voidwalkUpTree(QName currElem) Methods inherited from class org.xml.sax.helpers.DefaultHandler
error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, unparsedEntityDecl, warning
-
Field Details
-
MAX_DEPTH
private static final int MAX_DEPTH- See Also:
-
nsContext
-
rootPathNode
-
currentPath
-
traversedElements
-
decisionPoints
-
elementStack
-
anyStack
-
pathMgr
-
-
Constructor Details
-
XmlSchemaPathFinder
Creates a newXmlToAvroPathCreatorwith the rootXmlSchemaStateMachineNodeto start from when evaluating documents.
-
-
Method Details
-
startDocument
Kick-starts a new SAX walk, building newXmlSchemaPathNodeandXmlSchemaDocumentNodetraversals in the process.- Specified by:
startDocumentin interfaceContentHandler- Overrides:
startDocumentin classDefaultHandler- Throws:
SAXException- See Also:
-
startPrefixMapping
Handles a new prefix mapping in the SAX walk.- Specified by:
startPrefixMappingin interfaceContentHandler- Overrides:
startPrefixMappingin classDefaultHandler- Throws:
SAXException- See Also:
-
endPrefixMapping
Handles the end of a prefix mapping in the SAX walk.- Specified by:
endPrefixMappingin interfaceContentHandler- Overrides:
endPrefixMappingin classDefaultHandler- Throws:
SAXException- See Also:
-
startElement
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException Find the path through the XML Schema that best matches this element, traversing any relevant groups, and backtracking if necessary.- Specified by:
startElementin interfaceContentHandler- Overrides:
startElementin classDefaultHandler- Throws:
SAXException- See Also:
-
characters
Adds a newXmlSchemaPathNode.Direction.CONTENTXmlSchemaPathNodeto the path. Throws anIllegalStateExceptionif the owning element should not receive content, or the content is empty when it should not be.- Specified by:
charactersin interfaceContentHandler- Overrides:
charactersin classDefaultHandler- Throws:
SAXException- See Also:
-
endElement
Ends the current element. If the current element is not of the provideduriandlocalName, throws anIllegalStateException.- Specified by:
endElementin interfaceContentHandler- Overrides:
endElementin classDefaultHandler- Throws:
SAXException- See Also:
-
endDocument
Called when the XML Document traversal is complete.Confirms all open elements have been closed. If not, throws an
IllegalStateException.- Specified by:
endDocumentin interfaceContentHandler- Overrides:
endDocumentin classDefaultHandler- Throws:
SAXException
-
getXmlSchemaTraversal
Once a traversal completes successfully, this method may be called to retrieve the relevant interpretation of the path through theXmlSchemaStateMachineNodes.XmlSchemaPathNode.getDocumentNode()can be called to retrieve the interpretation of the XML Schema as applied to the document; meanwhile the walk throughXmlSchemaPathNodes will show how that schema was traversed. -
isPositionFulfilled
private static <U,V> XmlSchemaPathFinder.Fulfillment isPositionFulfilled(XmlSchemaPathNode<U, V> currentPath, List<Integer> possiblePaths) -
find
private List<XmlSchemaPathFinder.PathSegment<U,V>> find(XmlSchemaPathNode<U, V> startNode, QName elemQName) -
find
private List<XmlSchemaPathFinder.PathSegment<U,V>> find(XmlSchemaPathNode<U, V> startNode, QName elemQName, XmlSchemaStateMachineNode doNotFollow) -
find
private List<XmlSchemaPathFinder.PathSegment<U,V>> find(XmlSchemaPathNode<U, V> startNode, QName elemQName, int currDepth) -
walkUpTree
-
walkUpToElement
-
followPath
-
getElementsTraversedAsString
-
verifyCurrentPositionIsAtElement
-
getLeafNodeName
-
getStateMachineOfOwningElement
-
validateAttributes
-