Package org.apache.axiom.om

Examples of org.apache.axiom.om.OMFactory


        }
        fail("Empty localname was accepted!");
    }

    public void testWhitespaceLocalName() throws Exception {
        OMFactory factory = OMAbstractFactory.getOMFactory();
        try {
            factory.createOMAttribute("    ", null, null);
        } catch (IllegalArgumentException e) {
            return;
        }
        fail("Whitespace localname was accepted!");
    }
View Full Code Here


        root.addChild(elt12);
        root.serialize(writer);
    }

    public void testDualNamespaces2() throws Exception {
        OMFactory factory = OMAbstractFactory.getOMFactory();
        OMNamespace ns1 = factory.createOMNamespace("bar", "x");
        OMElement root = factory.createOMElement("root", ns1);
        OMNamespace ns2 = root.declareNamespace("bar", "y");
        OMElement elt1 = factory.createOMElement("foo", ns1);
        OMElement elt2 = factory.createOMElement("yuck", ns2);
        OMText txt1 = factory.createOMText(elt2, "blah");
        elt2.addChild(txt1);
        elt1.addChild(elt2);
        root.addChild(elt1);
        root.serialize(writer);
    }
View Full Code Here

        assertEquals(addAttributeMethod1(xmlString), addAttributeMethod2(xmlString));
    }

    public void testDefaultAttributeType() throws Exception {
        OMFactory factory = OMAbstractFactory.getOMFactory();
        OMNamespace ns = factory.createOMNamespace("http://www.me.com", "axiom");
        OMAttribute at = factory.createOMAttribute("id", ns, "value");

        assertEquals(at.getAttributeType(), "CDATA");
    }
View Full Code Here

    public TestAddAttributeWithExistingNamespaceDeclarationOnSameElement(OMMetaFactory metaFactory) {
        super(metaFactory);
    }

    protected void runTest() throws Throwable {
        OMFactory factory = metaFactory.getOMFactory();
        OMElement element = factory.createOMElement(new QName("test"));
        OMNamespace ns = factory.createOMNamespace("urn:ns", "p");
        element.declareNamespace(ns);
        OMAttribute att = factory.createOMAttribute("test", ns, "test");
        element.addAttribute(att);
        Iterator it = element.getAllDeclaredNamespaces();
        assertTrue(it.hasNext());
        assertEquals(ns, it.next());
        assertFalse(it.hasNext());
View Full Code Here

    private String addAttributeMethod1(String xmlString) throws Exception {
        OMXMLParserWrapper builder2 = OMXMLBuilderFactory.createOMBuilder(new StringReader(xmlString));
        OMElement doc = builder2.getDocumentElement();

        OMFactory factory = OMAbstractFactory.getOMFactory();
        OMNamespace ns = factory.createOMNamespace("http://www.me.com", "axiom");

        //code line to be tested
        OMAttribute at = factory.createOMAttribute("id", ns, "value");
        doc.addAttribute(at);

        return doc.toString();
    }
View Full Code Here

    private String addAttributeMethod2(String xmlString) throws Exception {
        OMXMLParserWrapper builder2 = OMXMLBuilderFactory.createOMBuilder(new StringReader(xmlString));
        OMElement doc = builder2.getDocumentElement();

        OMFactory factory = OMAbstractFactory.getOMFactory();
        OMNamespace ns = factory.createOMNamespace("http://www.me.com", "axiom");

        //code line to be tested
        doc.addAttribute("id", "value", ns);

        return doc.toString();
View Full Code Here

public class OMAttributeHelperTest extends TestCase {

    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()));
    }
View Full Code Here

     */
    protected void setUp() throws Exception {
        super.setUp();
        DataHandler dataHandler;

        OMFactory fac = OMAbstractFactory.getOMFactory();

        OMNamespace soap = fac.createOMNamespace(
                "http://schemas.xmlsoap.org/soap/envelope/", "soap");
        envelope = fac.createOMElement("Envelope", soap);
        OMElement body = fac.createOMElement("Body", soap);

        OMNamespace dataName = fac.createOMNamespace(
                "http://www.example.org/stuff", "m");
        OMElement data = fac.createOMElement("data", dataName);

        OMNamespace mime = fac.createOMNamespace(
                "http://www.w3.org/2003/06/xmlmime", "mime");

        OMElement text = fac.createOMElement("name", dataName);
        OMAttribute cType1 = fac.createOMAttribute("contentType", mime,
                                                 "text/plain");
        text.addAttribute(cType1);
        byte[] byteArray = new byte[] { 13, 56, 65, 32, 12, 12, 7, -3, -2, -1,
                98 };
        dataHandler = new DataHandler(new ByteArrayDataSource(byteArray));
        OMText textData = fac.createOMText(dataHandler, false);

        envelope.addChild(body);
        body.addChild(data);
        data.addChild(text);
        text.addChild(textData);
View Full Code Here

    public TestCloneOMElementNamespaceRepairing(OMMetaFactory metaFactory) {
        super(metaFactory);
    }

    protected void runTest() throws Throwable {
        OMFactory factory = metaFactory.getOMFactory();
       
        // Create a root element on which we declare the namespaces
        OMElement root = factory.createOMElement("root", null);
        OMNamespace ns1 = root.declareNamespace("urn:ns1", "ns1");
        OMNamespace ns2 = root.declareNamespace("urn:ns2", "ns2");
        root.declareNamespace("urn:ns3", "ns3");
       
        // Create a child that uses these namespaces (in the element name and in the name of an attribute)
        OMElement child = factory.createOMElement("child", ns1, root);
        child.addAttribute("attr", "value", ns2);
       
        // Check that the child has no namespace declarations (to validate the correctness of the test)
        assertFalse(child.getAllDeclaredNamespaces().hasNext());
       
View Full Code Here

        String sampleXMLOne = "<ChildOne><Name>ChildName</Name></ChildOne>";
        String sampleXMLTwo = "<ChildTwo><Name>ChildName</Name></ChildTwo>";

        String expectedXML =
                "<Root><ChildOne><Name>ChildName</Name></ChildOne><ChildTwo><Name>ChildName</Name></ChildTwo></Root>";
        OMFactory omFactory = metaFactory.getOMFactory();

        OMElement rootElement = omFactory.createOMElement("Root", null);
        OMElement childOne = OMXMLBuilderFactory.createOMBuilder(omFactory,
                new StringReader(sampleXMLOne)).getDocumentElement(true);
        rootElement.addChild(childOne);
        OMElement childTwo = OMXMLBuilderFactory.createOMBuilder(omFactory,
                new StringReader(sampleXMLTwo)).getDocumentElement(true);
View Full Code Here

TOP

Related Classes of org.apache.axiom.om.OMFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.