Class ToXml<C,N>

Type Parameters:
C - container
N - node
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler, XMLFilter, XMLReader
Direct Known Subclasses:
Map2Xml, Tree2Xml

public abstract class ToXml<C,N> extends XmlAligner
Base class for XML Schema guided Object to XML conversion;
Author:
Gerrit van Brakel
  • Field Details

  • Constructor Details

    • ToXml

      public ToXml(ValidatorHandler validatorHandler, List<org.apache.xerces.xs.XSModel> schemaInformation)
  • Method Details

    • getNodeNamespaceURI

      public String getNodeNamespaceURI(N node)
      return namespace of node, if known. If not, it will be determined from the schema.
    • asSource

      public Source asSource(C container)
      Obtain the XmlAligner as a Source that can be used as input of a Transformer.
    • parse

      public void parse(InputSource input) throws SAXException, IOException
      Start the parse, obtain the container to parse from the InputSource when set by asSource(Object). Normally, the parse is started via {#startParse(C container)}, but this implementation allows asSource(Object) to function.
      Specified by:
      parse in interface XMLReader
      Overrides:
      parse in class XMLFilterImpl
      Throws:
      SAXException
      IOException
    • startParse

      public void startParse(C container) throws SAXException
      Align the XML according to the schema.
      Throws:
      SAXException
    • getRootNode

      public abstract N getRootNode(C container)
    • getAttributes

      public abstract Map<String,String> getAttributes(org.apache.xerces.xs.XSElementDeclaration elementDeclaration, N node) throws SAXException
      Throws:
      SAXException
    • hasChild

      public abstract boolean hasChild(org.apache.xerces.xs.XSElementDeclaration elementDeclaration, N node, String childName) throws SAXException
      Throws:
      SAXException
    • getChildrenByName

      public abstract Iterable<N> getChildrenByName(N node, org.apache.xerces.xs.XSElementDeclaration childElementDeclaration) throws SAXException
      Throws:
      SAXException
    • isNil

      public abstract boolean isNil(org.apache.xerces.xs.XSElementDeclaration elementDeclaration, N node)
    • getText

      public abstract String getText(org.apache.xerces.xs.XSElementDeclaration elementDeclaration, N node)
    • getUnprocessedChildElementNames

      protected Set<String> getUnprocessedChildElementNames(org.apache.xerces.xs.XSElementDeclaration elementDeclaration, N node, Set<String> processedChildren) throws SAXException
      Throws:
      SAXException
    • handleRootNode

      public void handleRootNode(C container, String name, String nodeNamespace) throws SAXException
      Pushes node through validator. Must push all nodes through validatorhandler, recursively, respecting the alignment request. Must set current=node before calling validatorHandler.startElement(), in order to get the right argument for the onStartElement / performAlignment callbacks.
      Throws:
      SAXException
    • handleElement

      public void handleElement(org.apache.xerces.xs.XSElementDeclaration elementDeclaration, N node) throws SAXException
      Throws:
      SAXException
    • handleElementContents

      public void handleElementContents(org.apache.xerces.xs.XSElementDeclaration elementDeclaration, N node) throws SAXException
      Throws:
      SAXException
    • handleComplexTypedElement

      protected void handleComplexTypedElement(org.apache.xerces.xs.XSElementDeclaration elementDeclaration, N node) throws SAXException
      Throws:
      SAXException
    • handleSimpleTypedElement

      protected void handleSimpleTypedElement(org.apache.xerces.xs.XSElementDeclaration elementDeclaration, org.apache.xerces.xs.XSSimpleTypeDefinition simpleTypeDefinition, N node) throws SAXException
      Throws:
      SAXException
    • processChildElement

      protected void processChildElement(N node, String parentName, org.apache.xerces.xs.XSElementDeclaration childElementDeclaration, boolean mandatory, Set<String> processedChildren) throws SAXException
      Throws:
      SAXException
    • getBestChildElementPath

      public List<org.apache.xerces.xs.XSParticle> getBestChildElementPath(org.apache.xerces.xs.XSElementDeclaration elementDeclaration, N node, boolean silent) throws SAXException
      Throws:
      SAXException
    • getBestMatchingElementPath

      public boolean getBestMatchingElementPath(org.apache.xerces.xs.XSElementDeclaration baseElementDeclaration, N baseNode, org.apache.xerces.xs.XSParticle particle, List<org.apache.xerces.xs.XSParticle> path, List<String> failureReasons) throws SAXException
      Parameters:
      baseElementDeclaration - TODO
      particle -
      failureReasons - returns the reasons why no match was found
      path - in this list the longest list of child elements, that matches the available, is maintained. Null if no matching.
      Returns:
      true when a matching path is found. if false, failureReasons will contain reasons why.
      Throws:
      SAXException
    • sendString

      protected void sendString(String string) throws SAXException
      Throws:
      SAXException
    • handleError

      public void handleError(String msg) throws SAXException
      Throws:
      SAXException
    • handleError

      public void handleError(SAXException e) throws SAXException
      Throws:
      SAXException
    • getQName

      public String getQName(String namespace, String name) throws SAXException
      Throws:
      SAXException
    • getNamespacePrefix

      public String getNamespacePrefix(String uri) throws SAXException
      Throws:
      SAXException
    • findNamespaceForName

      public String findNamespaceForName(String name) throws SAXException
      Throws:
      SAXException
    • translate

      public void translate(C data, ContentHandler handler) throws SAXException
      Throws:
      SAXException
    • translate

      public String translate(C data) throws SAXException
      Throws:
      SAXException
    • getRootElement

      public String getRootElement()
    • setRootElement

      public void setRootElement(String rootElement)
    • getTargetNamespace

      public String getTargetNamespace()
    • setTargetNamespace

      public void setTargetNamespace(String targetNamespace)
    • isDeepSearch

      public boolean isDeepSearch()
    • setDeepSearch

      public void setDeepSearch(boolean deepSearch)
    • isFailOnWildcards

      public boolean isFailOnWildcards()
    • setFailOnWildcards

      public void setFailOnWildcards(boolean failOnWildcards)