Search in sources :

Example 6 with OMFactory

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

the class OMAttributeHelperTest method testImportOMAttribute.

public void testImportOMAttribute() {
    //Convert from OM to DOOM.
    OMFactory omf = OMAbstractFactory.getOMFactory();
    OMNamespace ns1 = omf.createOMNamespace("http://nsurl", "prefix");
    OMAttribute attr1 = omf.createOMAttribute("attr1", ns1, "attr1value");
    OMFactory doomf = OMAbstractFactory.getMetaFactory(OMAbstractFactory.FEATURE_DOM).getOMFactory();
    OMElement ome1 = doomf.createOMElement("element", ns1.getNamespaceURI(), ns1.getPrefix());
    AttributeHelper.importOMAttribute(attr1, ome1);
    assertNotSame(attr1, ome1.getAttribute(attr1.getQName()));
    assertEquals(attr1.getAttributeValue(), ome1.getAttribute(attr1.getQName()).getAttributeValue());
    //Convert from DOOM to OM.
    OMNamespace ns2 = doomf.createOMNamespace("http://nsurl", "prefix");
    OMAttribute attr2 = doomf.createOMAttribute("attr2", ns2, "attr2value");
    OMElement ome2 = omf.createOMElement("element", ns2.getNamespaceURI(), ns2.getPrefix());
    AttributeHelper.importOMAttribute(attr2, ome2);
    assertNotSame(attr2, ome2.getAttribute(attr2.getQName()));
    assertEquals(attr2.getAttributeValue(), ome2.getAttribute(attr2.getQName()).getAttributeValue());
    //OM only.
    OMNamespace ns3 = omf.createOMNamespace("http://nsurl", "prefix");
    OMAttribute attr3 = omf.createOMAttribute("attr3", ns3, "attr3value");
    OMElement ome3 = omf.createOMElement("element", ns3.getNamespaceURI(), ns3.getPrefix());
    AttributeHelper.importOMAttribute(attr3, ome3);
    assertSame(attr3, ome3.getAttribute(attr3.getQName()));
    //DOOM only.
    OMNamespace ns4 = doomf.createOMNamespace("http://nsurl", "prefix");
    OMAttribute attr4 = doomf.createOMAttribute("attr4", ns4, "attr4value");
    OMElement ome4 = doomf.createOMElement("element", ns4.getNamespaceURI(), ns4.getPrefix());
    AttributeHelper.importOMAttribute(attr4, ome4);
    assertSame(attr4, ome4.getAttribute(attr4.getQName()));
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) OMElement(org.apache.axiom.om.OMElement) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 7 with OMFactory

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

the class TestGetNameFromJAXBElement method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory omFactory = metaFactory.getOMFactory();
    ObjectFactory objectFactory = new ObjectFactory();
    JAXBContext context = JAXBContext.newInstance(ObjectFactory.class);
    JAXBElement<LinkIdentitiesType> jaxbElement = objectFactory.createLinkIdentities(new LinkIdentitiesType());
    OMSourcedElement element = omFactory.createOMElement(new JAXBOMDataSource(context, jaxbElement));
    assertEquals("http://www.example.org/identity", element.getNamespaceURI());
    assertEquals("LinkIdentities", element.getLocalName());
    assertFalse(element.isExpanded());
    // Force expansion so that OMSourcedElement compares the namespace URI and local name
    // provided by JAXBOMDataSource with the actual name of the element
    element.getFirstOMChild();
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) ObjectFactory(org.example.identity.ObjectFactory) JAXBContext(javax.xml.bind.JAXBContext) LinkIdentitiesType(org.example.identity.LinkIdentitiesType) OMSourcedElement(org.apache.axiom.om.OMSourcedElement) JAXBOMDataSource(org.apache.axiom.om.ds.jaxb.JAXBOMDataSource)

Example 8 with OMFactory

use of org.apache.axiom.om.OMFactory 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)

Example 9 with OMFactory

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

the class TestGetName method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement root = factory.createOMElement("root", null);
    OMSourcedElement el = factory.createOMElement(new PullOMDataSource("<p:el xmlns:p='urn:ns'>content</p:el>"), "el", factory.createOMNamespace("urn:ns", null));
    root.addChild(el);
    XMLStreamReader reader = root.getXMLStreamReader();
    assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
    assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
    QName name = reader.getName();
    assertEquals("p", name.getPrefix());
    assertEquals("urn:ns", name.getNamespaceURI());
    assertEquals("el", name.getLocalPart());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) PullOMDataSource(org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource) XMLStreamReader(javax.xml.stream.XMLStreamReader) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) OMSourcedElement(org.apache.axiom.om.OMSourcedElement)

Example 10 with OMFactory

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

the class TestBase64StreamingWithGetSAXSource method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement elem = factory.createOMElement("test", null);
    // Create a data source that would eat up all memory when loaded. If the test
    // doesn't fail with an OutOfMemoryError, we know that the OMText implementation
    // supports streaming.
    DataSource ds = new RandomDataSource(654321L, Runtime.getRuntime().maxMemory());
    OMText text = factory.createOMText(new DataHandler(ds), false);
    elem.addChild(text);
    SAXSource saxSource = elem.getSAXSource(true);
    XMLReader xmlReader = saxSource.getXMLReader();
    xmlReader.setContentHandler(new Base64Comparator(ds.getInputStream()));
    xmlReader.parse(saxSource.getInputSource());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) RandomDataSource(org.apache.axiom.testutils.activation.RandomDataSource) SAXSource(javax.xml.transform.sax.SAXSource) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement) DataHandler(javax.activation.DataHandler) XMLReader(org.xml.sax.XMLReader) RandomDataSource(org.apache.axiom.testutils.activation.RandomDataSource) DataSource(javax.activation.DataSource)

Aggregations

OMFactory (org.apache.axiom.om.OMFactory)254 OMElement (org.apache.axiom.om.OMElement)189 OMNamespace (org.apache.axiom.om.OMNamespace)94 QName (javax.xml.namespace.QName)62 StringReader (java.io.StringReader)37 OMText (org.apache.axiom.om.OMText)35 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)32 OMAttribute (org.apache.axiom.om.OMAttribute)31 PullOMDataSource (org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource)26 StringWriter (java.io.StringWriter)18 OMDocument (org.apache.axiom.om.OMDocument)18 XMLStreamReader (javax.xml.stream.XMLStreamReader)14 OMNode (org.apache.axiom.om.OMNode)14 DataHandler (javax.activation.DataHandler)12 OMException (org.apache.axiom.om.OMException)12 DataSource (javax.activation.DataSource)11 StringOMDataSource (org.apache.axiom.om.ds.StringOMDataSource)9 RandomDataSource (org.apache.axiom.testutils.activation.RandomDataSource)9 OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)8 Element (org.w3c.dom.Element)8