Search in sources :

Example 6 with CoreModelException

use of org.apache.axiom.core.CoreModelException in project webservices-axiom by apache.

the class XMLReaderImpl method parse.

private void parse() throws SAXException {
    XmlHandler handler = new ContentHandlerXmlHandler(contentHandler, lexicalHandler);
    CoreElement contextElement = root.getContextElement();
    if (contextElement != null) {
        handler = new NamespaceContextPreservationFilterHandler(handler, contextElement);
    }
    try {
        root.internalSerialize(handler, cache);
    } catch (CoreModelException ex) {
        throw new SAXException(ex);
    } catch (StreamException ex) {
        throw (SAXException) ex.getCause();
    }
}
Also used : CoreElement(org.apache.axiom.core.CoreElement) NamespaceContextPreservationFilterHandler(org.apache.axiom.om.impl.stream.NamespaceContextPreservationFilterHandler) ContentHandlerXmlHandler(org.apache.axiom.core.stream.sax.ContentHandlerXmlHandler) XmlHandler(org.apache.axiom.core.stream.XmlHandler) CoreModelException(org.apache.axiom.core.CoreModelException) ContentHandlerXmlHandler(org.apache.axiom.core.stream.sax.ContentHandlerXmlHandler) SAXException(org.xml.sax.SAXException) StreamException(org.apache.axiom.core.stream.StreamException)

Example 7 with CoreModelException

use of org.apache.axiom.core.CoreModelException in project webservices-axiom by apache.

the class NamespaceContextPreservationFilterHandler method attributesCompleted.

@Override
public void attributesCompleted() throws StreamException {
    if (!done) {
        try {
            CoreElement current = contextElement;
            while (true) {
                CoreAttribute attr = current.coreGetFirstAttribute();
                while (attr != null) {
                    if (attr instanceof CoreNamespaceDeclaration) {
                        CoreNamespaceDeclaration decl = (CoreNamespaceDeclaration) attr;
                        String prefix = decl.coreGetDeclaredPrefix();
                        if (prefixesAlreadyBound.add(prefix)) {
                            super.processNamespaceDeclaration(prefix, decl.coreGetCharacterData().toString());
                        }
                    }
                    attr = attr.coreGetNextAttribute();
                }
                CoreParentNode parent = current.coreGetParent();
                if (!(parent instanceof CoreElement)) {
                    break;
                }
                current = (CoreElement) parent;
            }
            prefixesAlreadyBound = null;
            done = true;
        } catch (CoreModelException ex) {
            throw new StreamException(ex);
        }
    }
    super.attributesCompleted();
}
Also used : CoreParentNode(org.apache.axiom.core.CoreParentNode) CoreAttribute(org.apache.axiom.core.CoreAttribute) CoreElement(org.apache.axiom.core.CoreElement) CoreModelException(org.apache.axiom.core.CoreModelException) CoreNamespaceDeclaration(org.apache.axiom.core.CoreNamespaceDeclaration) StreamException(org.apache.axiom.core.stream.StreamException)

Example 8 with CoreModelException

use of org.apache.axiom.core.CoreModelException in project webservices-axiom by apache.

the class OMFactoryImpl method createOMAttribute.

@Override
public final OMAttribute createOMAttribute(String localName, OMNamespace ns, String value) {
    if (ns != null && ns.getPrefix() == null) {
        String namespaceURI = ns.getNamespaceURI();
        if (namespaceURI.length() == 0) {
            ns = null;
        } else {
            ns = new OMNamespaceImpl(namespaceURI, generatePrefix(namespaceURI));
        }
    }
    if (ns != null) {
        if (ns.getNamespaceURI().length() == 0) {
            if (ns.getPrefix().length() > 0) {
                throw new IllegalArgumentException("Cannot create a prefixed attribute with an empty namespace name");
            } else {
                ns = null;
            }
        } else if (ns.getPrefix().length() == 0) {
            throw new IllegalArgumentException("Cannot create an unprefixed attribute with a namespace");
        }
    }
    AxiomAttribute attr = createNode(AxiomAttribute.class);
    attr.internalSetLocalName(localName);
    try {
        attr.coreSetCharacterData(value, AxiomSemantics.INSTANCE);
    } catch (CoreModelException ex) {
        throw AxiomExceptionTranslator.translate(ex);
    }
    attr.internalSetNamespace(ns);
    attr.coreSetType("CDATA");
    return attr;
}
Also used : CoreModelException(org.apache.axiom.core.CoreModelException) AxiomAttribute(org.apache.axiom.om.impl.intf.AxiomAttribute) OMNamespaceImpl(org.apache.axiom.om.impl.common.OMNamespaceImpl)

Example 9 with CoreModelException

use of org.apache.axiom.core.CoreModelException in project webservices-axiom by apache.

the class TreeWalkerImpl method proceed.

@Override
public boolean proceed() throws StreamException {
    if (incremental && !handler.drain()) {
        return false;
    }
    try {
        // Determine the next node (i.e. the node for which the next event is generated) and
        // update the state
        final CoreNode previousNode = node;
        final CoreNode nextNode;
        if (state == STATE_PASS_THROUGH || state == STATE_STREAMING) {
            nextNode = previousNode;
        } else if (previousNode == null) {
            if (state == STATE_NONE && !(root instanceof CoreDocument)) {
                nextNode = null;
                state = STATE_START_FRAGMENT;
            } else {
                nextNode = root;
                state = STATE_NOT_VISITED;
            }
        } else if (state == STATE_VISITED && previousNode == root) {
            nextNode = null;
        } else if (state == STATE_NOT_VISITED && previousNode instanceof CoreElement) {
            final CoreElement element = (CoreElement) previousNode;
            // TODO: handle case with preserve == false
            CoreAttribute firstAttribute = element.coreGetFirstAttribute();
            if (firstAttribute == null) {
                nextNode = element;
                state = STATE_ATTRIBUTES_VISITED;
            } else {
                nextNode = firstAttribute;
                state = STATE_NOT_VISITED;
            }
        } else if (state == STATE_NOT_VISITED || state == STATE_ATTRIBUTES_VISITED) {
            final CoreParentNode parent = (CoreParentNode) previousNode;
            int nodeState = parent.getState();
            if (preserve || nodeState == CoreParentNode.COMPLETE || nodeState == CoreParentNode.COMPACT) {
                // TODO: bad because it will expand the node if the state is COMPACT
                CoreChildNode child = parent.coreGetFirstChild();
                if (child == null) {
                    nextNode = parent;
                    state = STATE_VISITED;
                } else {
                    nextNode = child;
                    state = STATE_NOT_VISITED;
                }
            } else {
                CoreChildNode child = parent.coreGetFirstChildIfAvailable();
                if (child == null) {
                    nextNode = parent;
                    if (nodeState == CoreParentNode.DISCARDING || nodeState == CoreParentNode.DISCARDED) {
                        throw new NodeConsumedException();
                    }
                    parent.coreGetInputContext().setPassThroughHandler(handler);
                    state = STATE_PASS_THROUGH;
                } else {
                    nextNode = child;
                    state = STATE_NOT_VISITED;
                }
            }
        } else if (previousNode instanceof CoreChildNode) {
            final CoreChildNode previousChildNode = (CoreChildNode) previousNode;
            if (preserve) {
                CoreChildNode sibling = previousChildNode.coreGetNextSibling();
                if (sibling == null) {
                    nextNode = previousChildNode.coreGetParent();
                    state = STATE_VISITED;
                } else {
                    nextNode = sibling;
                    state = STATE_NOT_VISITED;
                }
            } else {
                CoreChildNode sibling = previousChildNode.coreGetNextSiblingIfAvailable();
                if (sibling == null) {
                    CoreParentNode parent = previousChildNode.coreGetParent();
                    nextNode = parent;
                    int nodeState = parent.getState();
                    // TODO: <hack>
                    if (nodeState == CoreParentNode.INCOMPLETE && parent.coreGetInputContext() == null) {
                        nodeState = CoreParentNode.COMPLETE;
                    }
                    if (nodeState == CoreParentNode.COMPLETE) {
                        state = STATE_VISITED;
                    } else if (nodeState == CoreParentNode.DISCARDING || nodeState == CoreParentNode.DISCARDED) {
                        throw new NodeConsumedException();
                    } else {
                        parent.coreGetInputContext().setPassThroughHandler(handler);
                        state = STATE_PASS_THROUGH;
                    }
                } else {
                    nextNode = sibling;
                    state = STATE_NOT_VISITED;
                }
            }
        } else {
            final CoreAttribute attribute = (CoreAttribute) previousNode;
            // TODO: handle case with preserve == false
            CoreAttribute nextAttribute = attribute.coreGetNextAttribute();
            if (nextAttribute == null) {
                nextNode = attribute.coreGetOwnerElement();
                state = STATE_ATTRIBUTES_VISITED;
            } else {
                nextNode = nextAttribute;
                state = STATE_NOT_VISITED;
            }
        }
        // been visited yet. It may be a sourced element or a leaf node
        if (state == STATE_NOT_VISITED) {
            if (nextNode instanceof CoreNSAwareElement) {
                XmlInput input = ((CoreNSAwareElement) nextNode).getXmlInput(preserve, incremental);
                if (input != null) {
                    reader = input.createReader(new DocumentElementExtractingFilterHandler(handler));
                    state = STATE_STREAMING;
                }
            } else if (nextNode instanceof CoreLeafNode) {
                state = STATE_LEAF;
            } else if (nextNode instanceof CoreAttribute) {
                state = STATE_ATTRIBUTE;
            }
        }
        switch(state) {
            case STATE_START_FRAGMENT:
                handler.startFragment();
                break;
            case STATE_LEAF:
                ((CoreLeafNode) nextNode).internalSerialize(handler, preserve);
                break;
            case STATE_ATTRIBUTE:
                ((CoreAttribute) nextNode).internalSerialize(handler, preserve);
                break;
            case STATE_NOT_VISITED:
                ((CoreParentNode) nextNode).serializeStartEvent(handler);
                break;
            case STATE_ATTRIBUTES_VISITED:
                handler.attributesCompleted();
                break;
            case STATE_VISITED:
                if (nextNode == null) {
                    handler.completed();
                } else {
                    ((CoreParentNode) nextNode).serializeEndEvent(handler);
                }
                break;
            case STATE_PASS_THROUGH:
                {
                    CoreParentNode parent = (CoreParentNode) nextNode;
                    parent.coreGetInputContext().getBuilder().next();
                    if (parent.coreGetInputContext() == null) {
                        state = STATE_VISITED;
                    }
                    break;
                }
            case STATE_STREAMING:
                if (reader.proceed()) {
                    state = STATE_VISITED;
                    reader = null;
                }
                break;
            default:
                throw new IllegalStateException();
        }
        node = nextNode;
        return state == STATE_VISITED && (nextNode == null || nextNode instanceof CoreDocument);
    } catch (CoreModelException ex) {
        throw new CoreModelStreamException(ex);
    }
}
Also used : CoreParentNode(org.apache.axiom.core.CoreParentNode) CoreAttribute(org.apache.axiom.core.CoreAttribute) XmlInput(org.apache.axiom.core.stream.XmlInput) CoreElement(org.apache.axiom.core.CoreElement) DocumentElementExtractingFilterHandler(org.apache.axiom.core.stream.DocumentElementExtractingFilterHandler) CoreDocument(org.apache.axiom.core.CoreDocument) CoreLeafNode(org.apache.axiom.core.CoreLeafNode) CoreModelStreamException(org.apache.axiom.core.CoreModelStreamException) CoreNSAwareElement(org.apache.axiom.core.CoreNSAwareElement) NodeConsumedException(org.apache.axiom.core.NodeConsumedException) CoreModelException(org.apache.axiom.core.CoreModelException) CoreChildNode(org.apache.axiom.core.CoreChildNode) CoreNode(org.apache.axiom.core.CoreNode)

Example 10 with CoreModelException

use of org.apache.axiom.core.CoreModelException in project webservices-axiom by apache.

the class XsiTypeFilterHandler method attributesCompleted.

@Override
public void attributesCompleted() throws StreamException {
    try {
        if (xsiType != null) {
            int idx = xsiType.indexOf(':');
            String prefix = idx == -1 ? "" : xsiType.substring(0, idx);
            boolean bound = false;
            for (int i = 0; i < prefixCount; i++) {
                if (prefixes[i] == prefix) {
                    bound = true;
                    break;
                }
            }
            if (!bound) {
                String namespaceURI = contextElement.coreLookupNamespaceURI(prefix, AxiomSemantics.INSTANCE);
                if (namespaceURI != null && !namespaceURI.isEmpty()) {
                    processNamespaceDeclaration(prefix, namespaceURI);
                }
            }
        }
    } catch (CoreModelException ex) {
        throw new StreamException(ex);
    }
    super.attributesCompleted();
    xsiType = null;
}
Also used : CoreModelException(org.apache.axiom.core.CoreModelException) StreamException(org.apache.axiom.core.stream.StreamException)

Aggregations

CoreModelException (org.apache.axiom.core.CoreModelException)11 CoreElement (org.apache.axiom.core.CoreElement)4 CoreModelStreamException (org.apache.axiom.core.CoreModelStreamException)3 CoreParentNode (org.apache.axiom.core.CoreParentNode)3 StreamException (org.apache.axiom.core.stream.StreamException)3 CoreAttribute (org.apache.axiom.core.CoreAttribute)2 CoreChildNode (org.apache.axiom.core.CoreChildNode)2 CoreNode (org.apache.axiom.core.CoreNode)2 OMNamespaceImpl (org.apache.axiom.om.impl.common.OMNamespaceImpl)2 ConcurrentModificationException (java.util.ConcurrentModificationException)1 CoreDocument (org.apache.axiom.core.CoreDocument)1 CoreLeafNode (org.apache.axiom.core.CoreLeafNode)1 CoreNSAwareElement (org.apache.axiom.core.CoreNSAwareElement)1 CoreNSUnawareAttribute (org.apache.axiom.core.CoreNSUnawareAttribute)1 CoreNamespaceDeclaration (org.apache.axiom.core.CoreNamespaceDeclaration)1 NodeConsumedException (org.apache.axiom.core.NodeConsumedException)1 DocumentElementExtractingFilterHandler (org.apache.axiom.core.stream.DocumentElementExtractingFilterHandler)1 XmlHandler (org.apache.axiom.core.stream.XmlHandler)1 XmlInput (org.apache.axiom.core.stream.XmlInput)1 ContentHandlerXmlHandler (org.apache.axiom.core.stream.sax.ContentHandlerXmlHandler)1