Search in sources :

Example 11 with OMContainer

use of org.apache.axiom.om.OMContainer in project webservices-axiom by apache.

the class OMXMLReader method generateParentPrefixMappingEvents.

private void generateParentPrefixMappingEvents(OMElement omElement, boolean start) throws SAXException {
    if (!(omElement.getParent() instanceof OMElement)) {
        return;
    }
    // Maintain a set of the prefixes we have already seen. This is required to take into
    // account that a namespace mapping declared on an element can hide another one declared
    // for the same prefix on an ancestor of the element.
    Set /*<String>*/
    seenPrefixes = new HashSet();
    for (Iterator it = omElement.getAllDeclaredNamespaces(); it.hasNext(); ) {
        seenPrefixes.add(((OMNamespace) it.next()).getPrefix());
    }
    OMElement current = omElement;
    while (true) {
        OMContainer parent = current.getParent();
        if (!(parent instanceof OMElement)) {
            return;
        }
        current = (OMElement) parent;
        for (Iterator it = current.getAllDeclaredNamespaces(); it.hasNext(); ) {
            OMNamespace ns = (OMNamespace) it.next();
            if (seenPrefixes.add(ns.getPrefix())) {
                generatePrefixMappingEvents(ns, start);
            }
        }
    }
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) HashSet(java.util.HashSet) Set(java.util.Set) Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement) OMContainer(org.apache.axiom.om.OMContainer) HashSet(java.util.HashSet)

Aggregations

OMContainer (org.apache.axiom.om.OMContainer)11 OMElement (org.apache.axiom.om.OMElement)6 OMFactory (org.apache.axiom.om.OMFactory)4 StringReader (java.io.StringReader)3 OMNamespace (org.apache.axiom.om.OMNamespace)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 OMComment (org.apache.axiom.om.OMComment)2 OMDocument (org.apache.axiom.om.OMDocument)2 OMNode (org.apache.axiom.om.OMNode)2 XML (org.apache.axiom.ts.dimension.serialization.XML)2 InputSource (org.xml.sax.InputSource)2 URL (java.net.URL)1 Iterator (java.util.Iterator)1 Set (java.util.Set)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1 StreamException (org.apache.axiom.core.stream.StreamException)1 XmlHandler (org.apache.axiom.core.stream.XmlHandler)1 XmlHandlerWrapper (org.apache.axiom.core.stream.XmlHandlerWrapper)1