Package org.apache.axiom.om

Examples of org.apache.axiom.om.OMSourcedElement


    }
   
    void next() throws XMLStreamException {
        if (nextNode()) {
            if (node instanceof OMSourcedElement) {
                OMSourcedElement element = (OMSourcedElement)node;
                if (!element.isExpanded()) {
                    OMDataSource ds = element.getDataSource();
                    if (ds != null) {
                        if (serializer.isDataSourceALeaf()) {
                            this.ds = ds;
                            currentEvent = -1;
                            // Mark the node as visited so that we continue with the next sibling
View Full Code Here


        // This is possible because JiBXDataSource is non destructive and implements the copy()
        // method.
        OMCloneOptions options = new OMCloneOptions();
        options.setCopyOMDataSources(true);
        boolean oldExpanded = element.isExpanded();
        OMSourcedElement clone = (OMSourcedElement)element.clone(options);
        if (element.isExpanded() != oldExpanded) {
            throw new AxisFault("Ooops! Accidentally expanded the original OMSourcedElement; this is unexpected...");
        }
        // Force OMSourcedElement to get the element name via QNameAwareOMDataSource
        log.info("Found OMSourcedElement: name=" + clone.getLocalName()
                + "; namespace=" + clone.getNamespaceURI()
                + "; prefix=" + clone.getPrefix());
        // The OMSourcedElement should still be unexpanded
        if (clone.isExpanded()) {
            throw new AxisFault("OMSourcedElement unexpectedly expanded!");
        }
        // Now force expansion to let OMSourcedElement validate that the name is correct
        clone.getFirstOMChild();
    }
View Full Code Here

        ParserInputStreamCustomBuilder customBuilder = new ParserInputStreamCustomBuilder("UTF-8");
        InputStream payload = new ByteArrayInputStream(mockPayload.getBytes());
        OMElement om= customBuilder.create("urn:sample", "invokeOp",(OMContainer) body, parser, OMAbstractFactory.getOMFactory(), payload);
        assertTrue(om!=null);
        assertTrue(om instanceof OMSourcedElement);
        OMSourcedElement ose = (OMSourcedElement)om;
        assertNotNull(ose.getDataSource());
        assertTrue((ose.getDataSource()) instanceof ParserInputStreamDataSource);
  }
View Full Code Here

        return TextFileDataSource.createOMSourcedElement(tmp, charset);
    }
   
    public void testWithXMLChars() throws Exception {
        String testString = "Test string with ampersand (&)";
        OMSourcedElement element = createSourcedElement(testString, UTF8);
        assertEquals(testString, element.getText());
    }
View Full Code Here

        OMSourcedElement element = createSourcedElement(testString, UTF8);
        assertEquals(testString, element.getText());
    }
   
    public void testSerializeToBytes() throws Exception {
        OMSourcedElement element = createSourcedElement("test", UTF8);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        element.serialize(baos);
        byte[] actual = baos.toByteArray();
        baos.reset();
        // We validate the result by creating an equivalent OMElement
        // and calling serialize on it. The two results must be identical.
        element.cloneOMElement().serialize(baos);
        byte[] expected = baos.toByteArray();
        assertTrue(Arrays.equals(expected, actual));
    }
View Full Code Here

        byte[] expected = baos.toByteArray();
        assertTrue(Arrays.equals(expected, actual));
    }
   
    public void testSerializeToChars() throws Exception {
        OMSourcedElement element = createSourcedElement("test", UTF8);
        StringWriter sw = new StringWriter();
        element.serialize(sw);
        String actual = sw.toString();
        sw.getBuffer().setLength(0);
        // Compare with the behavior of an equivalent OMElement
        element.cloneOMElement().serialize(sw);
        String expected = sw.toString();
        assertEquals(expected, actual);
    }
View Full Code Here

        if (targetDS == null) {
            copyOMElement(factory, targetParent, sourceOMSE);
            return;
        }
        // Otherwise create a target OMSE with the copied DataSource
        OMSourcedElement targetOMSE =
            factory.createOMElement(targetDS,
                                    sourceOMSE.getLocalName(),
                                    sourceOMSE.getNamespace());
        targetParent.addChild(targetOMSE);
View Full Code Here

        // Create a payload
        String text = "<tns:payload xmlns:tns=\"urn://test\">Hello World</tns:payload>";
        String encoding = "UTF-8";
        ByteArrayDataSource bads = new ByteArrayDataSource(text.getBytes(encoding), encoding);
        OMNamespace ns = body.getOMFactory().createOMNamespace("urn://test", "tns");
        OMSourcedElement omse =body.getOMFactory().createOMElement(bads, "payload", ns);
        body.addChild(omse);
        copyAndCheck(sourceEnv, true);
    }
View Full Code Here

       
        // Create a payload
        String text = "<tns:payload xmlns:tns=\"urn://test\">Hello World</tns:payload>";
        ByteArrayDataSource bads = new ByteArrayDataSource(text.getBytes(encoding), encoding);
        OMNamespace ns = body.getOMFactory().createOMNamespace("urn://test", "tns");
        OMSourcedElement omse =body.getOMFactory().createOMElement(bads, "payload", ns);
        body.addChild(omse);
       
        copyAndCheck(sourceEnv, true);
       
        // The source SOAPHeaderBlock should not be expanded in the process
View Full Code Here

        // Create a payload
        String text = "<tns:payload xmlns:tns=\"urn://test\">Hello World</tns:payload>";
        String encoding = "UTF-8";
        ByteArrayDataSource bads = new ByteArrayDataSource(text.getBytes(encoding), encoding);
        OMNamespace ns = body.getOMFactory().createOMNamespace("urn://test", "tns");
        OMSourcedElement omse =body.getOMFactory().createOMElement(bads, "payload", ns);
        body.addChild(omse);
        copyAndCheck(sourceEnv, true);
    }
View Full Code Here

TOP

Related Classes of org.apache.axiom.om.OMSourcedElement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.