Search in sources :

Example 16 with OMElement

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

the class OMAttributeHelperTest method testDetachedElement.

public void testDetachedElement() {
    OMNamespace top = OMAbstractFactory.getMetaFactory(OMAbstractFactory.FEATURE_DOM).getOMFactory().createOMNamespace("urn:test1", "t1");
    OMElement ome = OMAbstractFactory.getMetaFactory(OMAbstractFactory.FEATURE_DOM).getOMFactory().createOMElement("test", top);
    OMElement child = OMAbstractFactory.getMetaFactory(OMAbstractFactory.FEATURE_DOM).getOMFactory().createOMElement(new QName("test"), ome);
    OMAttribute oma = child.addAttribute("attr", "value", top);
    OMElement target = OMAbstractFactory.getOMFactory().createOMElement("test2", "urn:test2", "t2");
    AttributeHelper.importOMAttribute(oma, target);
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 17 with OMElement

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

the class EclipseTest method testDOOM.

@Test
public void testDOOM() throws Exception {
    DOMMetaFactory metaFactory = (DOMMetaFactory) OMAbstractFactory.getMetaFactory(OMAbstractFactory.FEATURE_DOM);
    Document document = metaFactory.newDocumentBuilderFactory().newDocumentBuilder().newDocument();
    Element element = document.createElementNS("urn:test", "p:root");
    assertEquals(new QName("urn:test", "root"), ((OMElement) element).getQName());
}
Also used : DOMMetaFactory(org.apache.axiom.om.dom.DOMMetaFactory) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 18 with OMElement

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

the class TestDataHandlerSerializationWithMTOM method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPFactory factory = metaFactory.getSOAP11Factory();
    JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
    // Construct the original message
    DocumentBean object = new DocumentBean();
    object.setId("123456");
    object.setContent(new DataHandler("some content", "text/plain; charset=utf-8"));
    SOAPEnvelope orgEnvelope = factory.getDefaultEnvelope();
    OMSourcedElement element = factory.createOMElement(new JAXBOMDataSource(context, object));
    orgEnvelope.getBody().addChild(element);
    // Serialize the message
    OMOutputFormat format = new OMOutputFormat();
    format.setDoOptimize(true);
    MemoryBlob blob = Blobs.createMemoryBlob();
    OutputStream out = blob.getOutputStream();
    orgEnvelope.serialize(out, format);
    out.close();
    assertFalse(element.isExpanded());
    // Parse the serialized message
    MultipartBody mb = MultipartBody.builder().setInputStream(blob.getInputStream()).setContentType(format.getContentType()).build();
    assertEquals(2, mb.getPartCount());
    SOAPEnvelope envelope = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, mb).getSOAPEnvelope();
    OMElement contentElement = envelope.getBody().getFirstElement().getFirstChildWithName(new QName("http://ws.apache.org/axiom/test/jaxb", "content"));
    OMText content = (OMText) contentElement.getFirstOMChild();
    assertTrue(content.isBinary());
    assertTrue(content.isOptimized());
    DataHandler dh = content.getDataHandler();
    assertEquals("some content", dh.getContent());
}
Also used : MemoryBlob(org.apache.axiom.blob.MemoryBlob) QName(javax.xml.namespace.QName) OutputStream(java.io.OutputStream) JAXBContext(javax.xml.bind.JAXBContext) OMElement(org.apache.axiom.om.OMElement) DataHandler(javax.activation.DataHandler) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) OMSourcedElement(org.apache.axiom.om.OMSourcedElement) SOAPFactory(org.apache.axiom.soap.SOAPFactory) JAXBOMDataSource(org.apache.axiom.om.ds.jaxb.JAXBOMDataSource) MultipartBody(org.apache.axiom.mime.MultipartBody) DocumentBean(org.apache.axiom.ts.jaxb.beans.DocumentBean) OMText(org.apache.axiom.om.OMText) OMOutputFormat(org.apache.axiom.om.OMOutputFormat)

Example 19 with OMElement

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

the class TestAddChildFromForeignDocument method runTest.

@Override
protected void runTest() throws Throwable {
    DocumentBuilder db = ((DOMMetaFactory) metaFactory).newDocumentBuilderFactory().newDocumentBuilder();
    Document document1 = db.newDocument();
    Element element1 = document1.createElementNS(null, "element1");
    Document document2 = db.newDocument();
    Element element2 = document2.createElementNS(null, "element2");
    ((OMElement) element1).addChild((OMElement) element2);
    // Assert that the new child is not a copy, but the original element
    assertSame(element2, element1.getFirstChild());
    // Assert that the owner document of element2 was changed
    assertSame(document1, element2.getOwnerDocument());
}
Also used : DocumentBuilder(javax.xml.parsers.DocumentBuilder) OMElement(org.apache.axiom.om.OMElement) Element(org.w3c.dom.Element) OMElement(org.apache.axiom.om.OMElement) Document(org.w3c.dom.Document)

Example 20 with OMElement

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

the class TestAddAttributeReplace method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element = factory.createOMElement("test", null);
    Document ownerDocument = ((Element) element).getOwnerDocument();
    assertNotNull(ownerDocument);
    OMAttribute attr1 = element.addAttribute("attr", "value1", null);
    assertSame(ownerDocument, ((Attr) attr1).getOwnerDocument());
    OMAttribute attr2 = factory.createOMAttribute("attr", null, "value2");
    element.addAttribute(attr2);
    Document newOwnerDocument = ((Attr) attr1).getOwnerDocument();
    assertNotNull(ownerDocument);
    assertNotSame(ownerDocument, newOwnerDocument);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMElement(org.apache.axiom.om.OMElement) Element(org.w3c.dom.Element) OMElement(org.apache.axiom.om.OMElement) Document(org.w3c.dom.Document) OMAttribute(org.apache.axiom.om.OMAttribute) Attr(org.w3c.dom.Attr)

Aggregations

OMElement (org.apache.axiom.om.OMElement)379 OMFactory (org.apache.axiom.om.OMFactory)189 OMNamespace (org.apache.axiom.om.OMNamespace)101 QName (javax.xml.namespace.QName)90 StringReader (java.io.StringReader)63 OMNode (org.apache.axiom.om.OMNode)42 OMText (org.apache.axiom.om.OMText)40 XMLStreamReader (javax.xml.stream.XMLStreamReader)37 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)28 OMAttribute (org.apache.axiom.om.OMAttribute)26 StringWriter (java.io.StringWriter)23 OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)21 OMDocument (org.apache.axiom.om.OMDocument)19 PullOMDataSource (org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource)18 Element (org.w3c.dom.Element)18 DataHandler (javax.activation.DataHandler)17 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)16 InputStream (java.io.InputStream)15 OMException (org.apache.axiom.om.OMException)13 SOAPBody (org.apache.axiom.soap.SOAPBody)13