Search in sources :

Example 1 with OMCloneOptions

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

the class TestClone method runTest.

@Override
protected void runTest() throws Throwable {
    OMDocument original = file.getAdapter(XMLSampleAdapter.class).getDocument(metaFactory);
    OMDocument clone = (OMDocument) original.clone(new OMCloneOptions());
    assertAbout(xml()).that(xml(OMDocument.class, clone)).hasSameContentAs(xml(OMDocument.class, original));
}
Also used : OMCloneOptions(org.apache.axiom.om.OMCloneOptions) XMLSampleAdapter(org.apache.axiom.ts.om.XMLSampleAdapter) OMDocument(org.apache.axiom.om.OMDocument)

Example 2 with OMCloneOptions

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

the class TestCloneUnknownName method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMDataSource ds = new StringOMDataSource("<p:element xmlns:p='urn:ns'>test</p:element>");
    OMSourcedElement element = factory.createOMElement(ds);
    OMCloneOptions options = new OMCloneOptions();
    options.setCopyOMDataSources(true);
    OMElement clone = (OMElement) element.clone(options);
    assertTrue(clone instanceof OMSourcedElement);
    assertFalse(element.isExpanded());
    OMNamespace expectedNS = factory.createOMNamespace("urn:ns", "p");
    assertEquals("element", element.getLocalName());
    assertEquals("element", clone.getLocalName());
    assertEquals(expectedNS, element.getNamespace());
    assertEquals(expectedNS, clone.getNamespace());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) OMDataSource(org.apache.axiom.om.OMDataSource) StringOMDataSource(org.apache.axiom.om.ds.StringOMDataSource) StringOMDataSource(org.apache.axiom.om.ds.StringOMDataSource) OMCloneOptions(org.apache.axiom.om.OMCloneOptions) OMElement(org.apache.axiom.om.OMElement) OMSourcedElement(org.apache.axiom.om.OMSourcedElement)

Example 3 with OMCloneOptions

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

the class TestClone method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPMessage message = soapFactory.createSOAPMessage();
    message.addChild(soapFactory.getDefaultEnvelope());
    OMCloneOptions options = new OMCloneOptions();
    options.setPreserveModel(preserveModel);
    OMInformationItem clone = message.clone(options);
    if (preserveModel) {
        assertTrue(clone instanceof SOAPMessage);
    } else {
        assertTrue(clone instanceof OMDocument);
        assertFalse(clone instanceof SOAPMessage);
    }
    OMElement envelope = ((OMDocument) clone).getOMDocumentElement();
    if (preserveModel) {
        assertTrue(envelope instanceof SOAPEnvelope);
    } else {
        assertFalse(envelope instanceof SOAPEnvelope);
    }
    assertEquals("Envelope", envelope.getLocalName());
    assertEquals(spec.getEnvelopeNamespaceURI(), envelope.getNamespaceURI());
}
Also used : OMInformationItem(org.apache.axiom.om.OMInformationItem) OMCloneOptions(org.apache.axiom.om.OMCloneOptions) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPMessage(org.apache.axiom.soap.SOAPMessage) OMDocument(org.apache.axiom.om.OMDocument)

Example 4 with OMCloneOptions

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

the class TestCloneIncomplete method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPMessage message = SOAPSampleSet.WSA.getMessage(spec).getAdapter(SOAPSampleAdapter.class).getSOAPMessage(metaFactory);
    OMCloneOptions options = new OMCloneOptions();
    options.setPreserveModel(preserveModel);
    OMInformationItem clone = message.clone(options);
    if (preserveModel) {
        assertTrue(clone instanceof SOAPMessage);
        assertSame(soapFactory, clone.getOMFactory());
    } else {
        assertTrue(clone instanceof OMDocument);
        assertFalse(clone instanceof SOAPMessage);
    }
}
Also used : OMInformationItem(org.apache.axiom.om.OMInformationItem) OMCloneOptions(org.apache.axiom.om.OMCloneOptions) SOAPSampleAdapter(org.apache.axiom.ts.soap.SOAPSampleAdapter) SOAPMessage(org.apache.axiom.soap.SOAPMessage) OMDocument(org.apache.axiom.om.OMDocument)

Example 5 with OMCloneOptions

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

the class TestCloneNonDestructive method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMDataSource ds = new WrappedTextNodeOMDataSourceFromDataSource(new QName("wrapper"), new ByteArrayDataSource("test".getBytes("utf-8")), Charset.forName("utf-8"));
    OMSourcedElement element = factory.createOMElement(ds);
    OMCloneOptions options = new OMCloneOptions();
    options.setCopyOMDataSources(copyOMDataSources);
    OMElement clone = (OMElement) element.clone(options);
    if (copyOMDataSources) {
        assertTrue(clone instanceof OMSourcedElement);
        assertFalse(element.isExpanded());
    } else {
        assertFalse(clone instanceof OMSourcedElement);
        assertTrue(clone.isComplete());
    }
    assertEquals("test", clone.getText());
    assertEquals("wrapper", clone.getLocalName());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMDataSource(org.apache.axiom.om.OMDataSource) QName(javax.xml.namespace.QName) OMCloneOptions(org.apache.axiom.om.OMCloneOptions) WrappedTextNodeOMDataSourceFromDataSource(org.apache.axiom.om.ds.WrappedTextNodeOMDataSourceFromDataSource) OMElement(org.apache.axiom.om.OMElement) OMSourcedElement(org.apache.axiom.om.OMSourcedElement) ByteArrayDataSource(org.apache.axiom.attachments.ByteArrayDataSource)

Aggregations

OMCloneOptions (org.apache.axiom.om.OMCloneOptions)6 OMElement (org.apache.axiom.om.OMElement)4 OMDocument (org.apache.axiom.om.OMDocument)3 OMDataSource (org.apache.axiom.om.OMDataSource)2 OMFactory (org.apache.axiom.om.OMFactory)2 OMInformationItem (org.apache.axiom.om.OMInformationItem)2 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)2 SOAPMessage (org.apache.axiom.soap.SOAPMessage)2 StringReader (java.io.StringReader)1 DataHandler (javax.activation.DataHandler)1 QName (javax.xml.namespace.QName)1 StreamSource (javax.xml.transform.stream.StreamSource)1 ByteArrayDataSource (org.apache.axiom.attachments.ByteArrayDataSource)1 OMNamespace (org.apache.axiom.om.OMNamespace)1 OMText (org.apache.axiom.om.OMText)1 StringOMDataSource (org.apache.axiom.om.ds.StringOMDataSource)1 WrappedTextNodeOMDataSourceFromDataSource (org.apache.axiom.om.ds.WrappedTextNodeOMDataSourceFromDataSource)1 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)1 RandomDataSource (org.apache.axiom.testutils.activation.RandomDataSource)1 XMLSampleAdapter (org.apache.axiom.ts.om.XMLSampleAdapter)1