Search in sources :

Example 51 with OMException

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

the class StAXPullReader method processText.

private void processText(int textType) throws StreamException {
    if (textType == XMLStreamConstants.CHARACTERS && dataHandlerReader != null && dataHandlerReader.isBinary()) {
        TextContent data;
        if (dataHandlerReader.isDeferred()) {
            data = new TextContent(dataHandlerReader.getContentID(), dataHandlerReader.getDataHandlerProvider(), dataHandlerReader.isOptimized());
        } else {
            try {
                data = new TextContent(dataHandlerReader.getContentID(), dataHandlerReader.getDataHandler(), dataHandlerReader.isOptimized());
            } catch (XMLStreamException ex) {
                throw new OMException(ex);
            }
        }
        handler.processCharacterData(data, false);
    } else {
        // Some parsers (like Woodstox) parse text nodes lazily and may throw a
        // RuntimeException in getText()
        String text;
        try {
            text = parser.getText();
        } catch (RuntimeException ex) {
            parserException = ex;
            throw ex;
        }
        switch(textType) {
            case XMLStreamConstants.CHARACTERS:
                handler.processCharacterData(text, false);
                break;
            case XMLStreamConstants.SPACE:
                handler.processCharacterData(text, true);
                break;
            case XMLStreamConstants.CDATA:
                handler.startCDATASection();
                handler.processCharacterData(text, false);
                handler.endCDATASection();
                break;
            default:
                throw new IllegalStateException();
        }
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) TextContent(org.apache.axiom.om.impl.intf.TextContent) OMException(org.apache.axiom.om.OMException)

Example 52 with OMException

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

the class DetachableReader method detach.

@Override
public void detach() {
    MemoryBlob blob = Blobs.createMemoryBlob();
    Writer out = new OutputStreamWriter(blob.getOutputStream(), UTF8);
    char[] buffer = new char[2048];
    int c;
    try {
        while ((c = target.read(buffer)) != -1) {
            out.write(buffer, 0, c);
        }
        out.close();
    } catch (IOException ex) {
        throw new OMException(ex);
    }
    target = new InputStreamReader(blob.readOnce(), UTF8);
}
Also used : InputStreamReader(java.io.InputStreamReader) MemoryBlob(org.apache.axiom.blob.MemoryBlob) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) OMException(org.apache.axiom.om.OMException) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 53 with OMException

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

the class TestDeclareDefaultNamespaceConflict2 method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMNamespace ns = factory.createOMNamespace("urn:ns1", "");
    OMElement element = factory.createOMElement("test", ns);
    try {
        element.declareDefaultNamespace("urn:ns2");
        fail("Expected OMException");
    } catch (OMException ex) {
    // Expected
    }
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) OMElement(org.apache.axiom.om.OMElement) OMException(org.apache.axiom.om.OMException)

Example 54 with OMException

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

the class TestInsertSiblingBeforeOnSelf method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement parent = factory.createOMElement("test", null);
    OMText text = factory.createOMText("test");
    parent.addChild(text);
    try {
        text.insertSiblingBefore(text);
        fail("Expected OMException");
    } catch (OMException ex) {
    // Expected
    }
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement) OMException(org.apache.axiom.om.OMException)

Example 55 with OMException

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

the class TestInsertSiblingAfterOnSelf method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement parent = factory.createOMElement("test", null);
    OMText text = factory.createOMText("test");
    parent.addChild(text);
    try {
        text.insertSiblingAfter(text);
        fail("Expected OMException");
    } catch (OMException ex) {
    // Expected
    }
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement) OMException(org.apache.axiom.om.OMException)

Aggregations

OMException (org.apache.axiom.om.OMException)89 OMElement (org.apache.axiom.om.OMElement)35 XMLStreamException (javax.xml.stream.XMLStreamException)31 IOException (java.io.IOException)30 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)21 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)18 InputStream (java.io.InputStream)16 QName (javax.xml.namespace.QName)13 OMFactory (org.apache.axiom.om.OMFactory)12 ArrayList (java.util.ArrayList)11 MalformedURLException (java.net.MalformedURLException)10 Test (org.junit.Test)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)9 ParseException (org.json.simple.parser.ParseException)9 APIMgtResourceAlreadyExistsException (org.wso2.carbon.apimgt.api.APIMgtResourceAlreadyExistsException)9 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)9 FaultGatewaysException (org.wso2.carbon.apimgt.api.FaultGatewaysException)9 MonetizationException (org.wso2.carbon.apimgt.api.MonetizationException)9 UnsupportedPolicyTypeException (org.wso2.carbon.apimgt.api.UnsupportedPolicyTypeException)9