org.apache.ws.commons.schema.docpath
Class XmlSchemaPathFinder<U,V>

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by org.apache.ws.commons.schema.docpath.XmlSchemaPathFinder<U,V>
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler

public final class XmlSchemaPathFinder<U,V>
extends DefaultHandler

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.


Constructor Summary
XmlSchemaPathFinder(XmlSchemaStateMachineNode root)
          Creates a new XmlToAvroPathCreator with the root XmlSchemaStateMachineNode to start from when evaluating documents.
 
Method Summary
 void characters(char[] ch, int start, int length)
          Adds a new XmlSchemaPathNode.Direction.CONTENT XmlSchemaPathNode to the path.
 void endDocument()
          Called when the XML Document traversal is complete.
 void endElement(String uri, String localName, String qName)
          Ends the current element.
 void endPrefixMapping(String prefix)
          Handles the end of a prefix mapping in the SAX walk.
 XmlSchemaPathNode<U,V> getXmlSchemaTraversal()
          Once a traversal completes successfully, this method may be called to retrieve the relevant interpretation of the path through the XmlSchemaStateMachineNodes.
 void startDocument()
          Kick-starts a new SAX walk, building new XmlSchemaPathNode and XmlSchemaDocumentNode traversals in the process.
 void startElement(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.
 void startPrefixMapping(String prefix, String uri)
          Handles a new prefix mapping in the SAX walk.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlSchemaPathFinder

public XmlSchemaPathFinder(XmlSchemaStateMachineNode root)
Creates a new XmlToAvroPathCreator with the root XmlSchemaStateMachineNode to start from when evaluating documents.

Method Detail

startDocument

public void startDocument()
                   throws SAXException
Kick-starts a new SAX walk, building new XmlSchemaPathNode and XmlSchemaDocumentNode traversals in the process.

Specified by:
startDocument in interface ContentHandler
Overrides:
startDocument in class DefaultHandler
Throws:
SAXException
See Also:
DefaultHandler.startDocument()

startPrefixMapping

public void startPrefixMapping(String prefix,
                               String uri)
                        throws SAXException
Handles a new prefix mapping in the SAX walk.

Specified by:
startPrefixMapping in interface ContentHandler
Overrides:
startPrefixMapping in class DefaultHandler
Throws:
SAXException
See Also:
DefaultHandler.startPrefixMapping(String, String)

endPrefixMapping

public void endPrefixMapping(String prefix)
                      throws SAXException
Handles the end of a prefix mapping in the SAX walk.

Specified by:
endPrefixMapping in interface ContentHandler
Overrides:
endPrefixMapping in class DefaultHandler
Throws:
SAXException
See Also:
DefaultHandler.endPrefixMapping(String)

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:
startElement in interface ContentHandler
Overrides:
startElement in class DefaultHandler
Throws:
SAXException
See Also:
DefaultHandler.startElement(String, String, String, Attributes)

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws SAXException
Adds a new XmlSchemaPathNode.Direction.CONTENT XmlSchemaPathNode to the path. Throws an IllegalStateException if the owning element should not receive content, or the content is empty when it should not be.

Specified by:
characters in interface ContentHandler
Overrides:
characters in class DefaultHandler
Throws:
SAXException
See Also:
DefaultHandler.characters(char[], int, int)

endElement

public void endElement(String uri,
                       String localName,
                       String qName)
                throws SAXException
Ends the current element. If the current element is not of the provided uri and localName, throws an IllegalStateException.

Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class DefaultHandler
Throws:
SAXException
See Also:
DefaultHandler.endElement(String, String, String)

endDocument

public void endDocument()
                 throws SAXException
Called when the XML Document traversal is complete.

Confirms all open elements have been closed. If not, throws an IllegalStateException.

Specified by:
endDocument in interface ContentHandler
Overrides:
endDocument in class DefaultHandler
Throws:
SAXException

getXmlSchemaTraversal

public XmlSchemaPathNode<U,V> getXmlSchemaTraversal()
Once a traversal completes successfully, this method may be called to retrieve the relevant interpretation of the path through the XmlSchemaStateMachineNodes.

XmlSchemaPathNode.getDocumentNode() can be called to retrieve the interpretation of the XML Schema as applied to the document; meanwhile the walk through XmlSchemaPathNodes will show how that schema was traversed.



Copyright © 2004-2015 The Apache Software Foundation. All Rights Reserved.