Search in sources :

Example 11 with OMNamespace

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

the class WriteNamespaceScenario method validate.

@Override
public void validate(OMElement element, boolean dataHandlersPreserved) throws Throwable {
    OMNamespace decl = null;
    Iterator<OMNamespace> it = element.getAllDeclaredNamespaces();
    while (it.hasNext()) {
        OMNamespace ns = it.next();
        if (!ns.getPrefix().equals("_p_")) {
            if (decl != null) {
                Assert.fail("Found unexpected namespace declaration");
            } else {
                decl = ns;
            }
        }
    }
    Assert.assertNotNull(decl);
    Assert.assertEquals(prefix, decl.getPrefix());
    Assert.assertEquals(namespaceURI, decl.getNamespaceURI());
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace)

Example 12 with OMNamespace

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

the class SetNamespaceTestCase method runTest.

@Override
protected final void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element;
    OMNamedInformationItem node;
    if (context()) {
        // To avoid collisions if prefixInScope is the empty string
        OMNamespace dummyNS = factory.createOMNamespace("__dummy__", "__dummy__");
        OMElement parent = factory.createOMElement("parent", dummyNS);
        element = factory.createOMElement("test", dummyNS, parent);
        if (prefixInScope != null) {
            if (prefixInScope.length() == 0) {
                parent.declareDefaultNamespace(namespaceURI);
            } else {
                parent.declareNamespace(namespaceURI, prefixInScope);
            }
        }
    } else {
        element = null;
    }
    node = node(factory, element);
    OMNamespace ns = namespaceURI == null ? null : factory.createOMNamespace(namespaceURI, prefix);
    try {
        setNamespace(node, ns);
        if (invalid) {
            fail("Expected IllegalArgumentException");
        }
    } catch (IllegalArgumentException ex) {
        if (invalid) {
            return;
        } else {
            throw ex;
        }
    }
    String expectedPrefix;
    if (this.expectedPrefix == null) {
        expectedPrefix = node.getPrefix();
        assertNotNull(expectedPrefix);
        assertFalse(expectedPrefix.length() == 0);
    } else {
        expectedPrefix = this.expectedPrefix;
        if (expectedPrefix.length() == 0) {
            assertNull(node.getPrefix());
        } else {
            assertEquals(expectedPrefix, node.getPrefix());
        }
    }
    if (namespaceURI == null || namespaceURI.length() == 0) {
        assertNull(node.getNamespace());
    } else {
        OMNamespace actualNS = node.getNamespace();
        assertEquals(expectedPrefix, actualNS.getPrefix());
        assertEquals(namespaceURI, actualNS.getNamespaceURI());
    }
    if (namespaceURI == null || namespaceURI.length() == 0) {
        assertNull(node.getNamespaceURI());
    } else {
        assertEquals(namespaceURI, node.getNamespaceURI());
    }
    QName qname = node.getQName();
    assertEquals(expectedPrefix, qname.getPrefix());
    assertEquals(namespaceURI == null ? "" : namespaceURI, qname.getNamespaceURI());
    if (element != null) {
        Iterator<OMNamespace> it = element.getAllDeclaredNamespaces();
        if (expectNSDecl) {
            assertTrue(it.hasNext());
            OMNamespace decl = it.next();
            assertEquals(expectedPrefix, decl.getPrefix());
            assertEquals(namespaceURI == null ? "" : namespaceURI, decl.getNamespaceURI());
        }
        assertFalse(it.hasNext());
    }
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamedInformationItem(org.apache.axiom.om.OMNamedInformationItem) OMNamespace(org.apache.axiom.om.OMNamespace) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement)

Example 13 with OMNamespace

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

the class TestGetAttributeTypeDefault method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMNamespace ns = factory.createOMNamespace("http://www.me.com", "axiom");
    OMAttribute at = factory.createOMAttribute("id", ns, "value");
    assertEquals("CDATA", at.getAttributeType());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 14 with OMNamespace

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

the class OMElementTest method testChildDetachment.

public void testChildDetachment() {
    OMNamespace testNamespace2 = factory.createOMNamespace("ftp://anotherTest.ws.org", "ws");
    secondElement.detach();
    assertTrue("OMElement children detachment has not worked properly", !secondElement.equals(firstElement.getFirstElement()));
    assertNull("First Element should not contain elements after detaching. ", firstElement.getFirstElement());
    assertNull("First Element should not contain elements after detaching. ", firstElement.getFirstOMChild());
    assertNull(secondElement.findNamespace(testNamespace2.getNamespaceURI(), testNamespace2.getPrefix()));
    firstElement.addChild(secondElement);
    factory.createOMText(firstElement, "Some Sample Text");
    assertTrue("First added child must be the first child", secondElement.equals(firstElement.getFirstOMChild()));
    Iterator children = firstElement.getChildren();
    int childCount = 0;
    while (children.hasNext()) {
        children.next();
        childCount++;
    }
    assertEquals("Children count should be two", childCount, 2);
    secondElement.detach();
    assertTrue("First child should be the text child", firstElement.getFirstOMChild() instanceof OMText);
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) Iterator(java.util.Iterator) OMText(org.apache.axiom.om.OMText)

Example 15 with OMNamespace

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

the class TestExtractAllHeaderBlocks method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPEnvelope envelope = soapFactory.createSOAPEnvelope();
    SOAPHeader header = soapFactory.createSOAPHeader(envelope);
    OMNamespace ns = soapFactory.createOMNamespace("urn:ns", "p");
    SOAPHeaderBlock h1 = header.addHeaderBlock("header1", ns);
    SOAPHeaderBlock h2 = header.addHeaderBlock("header2", ns);
    Iterator<SOAPHeaderBlock> it = header.extractAllHeaderBlocks();
    assertTrue(it.hasNext());
    assertSame(h1, it.next());
    assertTrue(it.hasNext());
    assertSame(h2, it.next());
    assertFalse(it.hasNext());
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPHeader(org.apache.axiom.soap.SOAPHeader)

Aggregations

OMNamespace (org.apache.axiom.om.OMNamespace)164 OMElement (org.apache.axiom.om.OMElement)101 OMFactory (org.apache.axiom.om.OMFactory)94 QName (javax.xml.namespace.QName)33 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)20 OMAttribute (org.apache.axiom.om.OMAttribute)18 PullOMDataSource (org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource)16 StringWriter (java.io.StringWriter)15 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)13 SOAPHeader (org.apache.axiom.soap.SOAPHeader)12 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)9 XMLStreamReader (javax.xml.stream.XMLStreamReader)8 OMText (org.apache.axiom.om.OMText)7 Iterator (java.util.Iterator)6 SOAPBody (org.apache.axiom.soap.SOAPBody)6 StringReader (java.io.StringReader)5 StringOMDataSource (org.apache.axiom.om.ds.StringOMDataSource)5 HashSet (java.util.HashSet)4 OMDataSource (org.apache.axiom.om.OMDataSource)4 OMNode (org.apache.axiom.om.OMNode)4