Search in sources :

Example 1 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 2 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 3 with CoreModelException

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

the class CustomBuilderManager method getAction.

private Runnable getAction(CoreNode node, int depth, int firstCustomBuilder) {
    lastCandidateElement = null;
    lastCandidateDepth = -1;
    if (node instanceof AxiomElement && (node instanceof AxiomSOAPHeaderBlock || !(node instanceof AxiomSOAPElement))) {
        final AxiomElement element = (AxiomElement) node;
        if (registrations != null) {
            for (int i = firstCustomBuilder; i < registrations.size(); i++) {
                CustomBuilderRegistration registration = registrations.get(i);
                final String namespaceURI = element.coreGetNamespaceURI();
                final String localName = element.coreGetLocalName();
                if (registration.getSelector().accepts(element.getParent(), depth, namespaceURI, localName)) {
                    final CustomBuilder customBuilder = registration.getCustomBuilder();
                    if (log.isDebugEnabled()) {
                        log.debug("Custom builder " + customBuilder + " accepted element {" + namespaceURI + "}" + localName + " at depth " + depth);
                    }
                    return new Runnable() {

                        @Override
                        public void run() {
                            if (log.isDebugEnabled()) {
                                log.debug("Invoking custom builder " + customBuilder);
                            }
                            OMDataSource dataSource = customBuilder.create(element);
                            Class<? extends AxiomSourcedElement> type;
                            if (element instanceof AxiomSOAP11HeaderBlock) {
                                type = AxiomSOAP11HeaderBlock.class;
                            } else if (element instanceof AxiomSOAP12HeaderBlock) {
                                type = AxiomSOAP12HeaderBlock.class;
                            } else {
                                type = AxiomSourcedElement.class;
                            }
                            if (log.isDebugEnabled()) {
                                log.debug("Replacing element with new sourced element of type " + type);
                            }
                            AxiomSourcedElement newElement = element.coreCreateNode(type);
                            newElement.init(localName, new OMNamespaceImpl(namespaceURI, null), dataSource);
                            try {
                                element.coreReplaceWith(newElement, AxiomSemantics.INSTANCE);
                            } catch (CoreModelException ex) {
                                throw AxiomExceptionTranslator.translate(ex);
                            }
                        }
                    };
                }
            }
        }
        // Save a reference to the element so that we can process it when another custom builder is registered
        lastCandidateElement = element;
        lastCandidateDepth = depth;
    }
    return null;
}
Also used : OMDataSource(org.apache.axiom.om.OMDataSource) AxiomSOAPHeaderBlock(org.apache.axiom.soap.impl.intf.AxiomSOAPHeaderBlock) CustomBuilder(org.apache.axiom.om.ds.custombuilder.CustomBuilder) AxiomSOAP12HeaderBlock(org.apache.axiom.soap.impl.intf.AxiomSOAP12HeaderBlock) AxiomSOAPElement(org.apache.axiom.soap.impl.intf.AxiomSOAPElement) AxiomSourcedElement(org.apache.axiom.om.impl.intf.AxiomSourcedElement) CoreModelException(org.apache.axiom.core.CoreModelException) AxiomElement(org.apache.axiom.om.impl.intf.AxiomElement) AxiomSOAP11HeaderBlock(org.apache.axiom.soap.impl.intf.AxiomSOAP11HeaderBlock) OMNamespaceImpl(org.apache.axiom.om.impl.common.OMNamespaceImpl)

Example 4 with CoreModelException

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

the class OMXMLParserWrapperImpl method getDocumentElement.

@Override
public final OMElement getDocumentElement(boolean discardDocument) {
    try {
        OMDocument document = getDocument();
        OMElement element = document.getOMDocumentElement();
        if (discardDocument) {
            element.detach();
            ((AxiomDocument) document).coreDiscard(false);
        }
        return element;
    } catch (CoreModelException ex) {
        throw AxiomExceptionTranslator.translate(ex);
    }
}
Also used : AxiomDocument(org.apache.axiom.om.impl.intf.AxiomDocument) CoreModelException(org.apache.axiom.core.CoreModelException) OMElement(org.apache.axiom.om.OMElement) OMDocument(org.apache.axiom.om.OMDocument)

Example 5 with CoreModelException

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

the class BuildableContext method endContext.

private Context endContext() throws StreamException {
    target.coreSetState(CoreParentNode.COMPLETE);
    target.coreSetInputContext(null);
    if (pendingCharacterData != null) {
        try {
            target.coreSetCharacterData(pendingCharacterData, null);
        } catch (CoreModelException ex) {
            throw new CoreModelStreamException(ex);
        }
        pendingCharacterData = null;
    }
    target = null;
    builderHandler.decrementActiveContextCount();
    return parentContext;
}
Also used : CoreModelException(org.apache.axiom.core.CoreModelException) CoreModelStreamException(org.apache.axiom.core.CoreModelStreamException)

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