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);
}
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());
}
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());
}
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());
}
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);
}
Aggregations