Package org.jibx.extras

Examples of org.jibx.extras.JDOMWriter


     * Test valid constructor usages.
     */
    public void testValidContructorUsage() throws Exception {
        Element element;
        Document document;
        JDOMWriter jdomWriter = null;
       
        // valid
        jdomWriter = new JDOMWriter(STD_NAMESPACES);
        jdomWriter = new JDOMWriter(new String[] { EMPTY_NAMESPACE, XML_NAMESPACE, "urn:myNs1", "urn:myNs2" });
       
        document = new Document();
       
        // valid
        jdomWriter = new JDOMWriter(STD_NAMESPACES, document);
       
        element = new Element("element");
        document = new Document(element);
       
        // valid
        jdomWriter = new JDOMWriter(STD_NAMESPACES, document);
        jdomWriter = new JDOMWriter(STD_NAMESPACES, element);
       
        assertNotNull(jdomWriter);
    }
View Full Code Here


   
    /**
     * Test invalid constructor usages.
     */
    public void testInvalidConstructorUsage() throws Exception {
        JDOMWriter jdomWriter = null;
      
        // invalid: empty and xml namespace have to be defined
        try {
            jdomWriter = new JDOMWriter(new String[0]);
            fail("expected ArrayIndexOutOfBoundsException");
        } catch(ArrayIndexOutOfBoundsException e) {}
        try {
            jdomWriter = new JDOMWriter(new String[1]);
            fail("expected ArrayIndexOutOfBoundsException");
        } catch(ArrayIndexOutOfBoundsException e) {}
       
        // invalid: Document is null
        try {
            jdomWriter = new JDOMWriter(STD_NAMESPACES, (Document) null);
            fail("expected NullPointerException");
        } catch(NullPointerException e) {}
       
        // invalid: Element is null
        try {
            jdomWriter = new JDOMWriter(STD_NAMESPACES, (Element) null);
            fail("expected NullPointerException");
        } catch(NullPointerException e) {}
       
        // invalid: Element has no parent Document
        try {
            jdomWriter = new JDOMWriter(STD_NAMESPACES, new Element("element"));
            fail("expected NullPointerException");
        } catch(NullPointerException e) {}
       
        assertNull(jdomWriter);
    }
View Full Code Here

   
    /**
     * Test adding and removing extension namespaces.
     */
    public void testExtensionNamespaces() throws Exception {
        final JDOMWriter jdomWriter = new JDOMWriter(STD_NAMESPACES);
        String[][] ns;

        ns = jdomWriter.getExtensionNamespaces();
        assertNull(ns);
       
        jdomWriter.pushExtensionNamespaces(new String[] { "urn:myNs1", "urn:myNs2" });
       
        ns = jdomWriter.getExtensionNamespaces();
        assertEquals(1, ns.length);
        assertEquals("urn:myNs1", ns[0][0]);
        assertEquals("urn:myNs2", ns[0][1]);
       
        jdomWriter.pushExtensionNamespaces(new String[] { "urn:myNs3" });
       
        ns = jdomWriter.getExtensionNamespaces();
        assertEquals(2, ns.length);
        assertEquals(2, ns[0].length);
        assertEquals(1, ns[1].length);
        assertEquals("urn:myNs1", ns[0][0]);
        assertEquals("urn:myNs2", ns[0][1]);
        assertEquals("urn:myNs3", ns[1][0]);
       
        jdomWriter.popExtensionNamespaces();
       
        ns = jdomWriter.getExtensionNamespaces();
        assertEquals(1, ns.length);
        assertEquals(2, ns[0].length);
        assertEquals("urn:myNs1", ns[0][0]);
        assertEquals("urn:myNs2", ns[0][1]);
       
        jdomWriter.popExtensionNamespaces();
       
        ns = jdomWriter.getExtensionNamespaces();
        assertNull(ns);
    }
View Full Code Here

   
    /**
     * Test changing namespace prefixes.
     */
    public void testNamespacePrefixes() throws Exception {
        JDOMWriter jdomWriter = new JDOMWriter(new String[] { EMPTY_NAMESPACE, XML_NAMESPACE, "urn:myNs1", "urn:myNs2" });
       
        assertEquals("", jdomWriter.getNamespaceUri(0));
        assertEquals("http://www.w3.org/XML/1998/namespace", jdomWriter.getNamespaceUri(1));
        assertEquals("urn:myNs1", jdomWriter.getNamespaceUri(2));
        assertEquals("urn:myNs2", jdomWriter.getNamespaceUri(3));
       
        assertEquals("", jdomWriter.getNamespacePrefix(0));
        assertEquals("xml", jdomWriter.getNamespacePrefix(1));
        assertNull("unexpected prefix defined", jdomWriter.getNamespacePrefix(2));
        assertNull("unexpected prefix defined", jdomWriter.getNamespacePrefix(3));
       
        jdomWriter.startTagNamespaces(0, "element1", new int[] {2, 3}, new String[] {"myns1", "myns2"});
        jdomWriter.closeStartTag();

        assertEquals("myns1", jdomWriter.getNamespacePrefix(2));
        assertEquals("myns2", jdomWriter.getNamespacePrefix(3));
       
        jdomWriter.startTagNamespaces(0, "element2", new int[] {2}, new String[] {"prefix"});
       
        assertEquals("prefix", jdomWriter.getNamespacePrefix(2));
        assertEquals("myns2", jdomWriter.getNamespacePrefix(3));
       
        jdomWriter.closeEmptyTag();
       
        assertEquals("myns1", jdomWriter.getNamespacePrefix(2));
        assertEquals("myns2", jdomWriter.getNamespacePrefix(3));
       
        jdomWriter.endTag(0, "element1");
       
        assertNull("unexpected prefix defined", jdomWriter.getNamespacePrefix(2));
        assertNull("unexpected prefix defined", jdomWriter.getNamespacePrefix(3));
    }
View Full Code Here

     */
    private static Document marshalActualDocument(Object root) throws JiBXException {
        final IBindingFactory bfact = BindingDirectory.getFactory(root.getClass());
        final IMarshallingContext mctx = bfact.createMarshallingContext();
       
        final JDOMWriter jdomWriter = new JDOMWriter(bfact.getNamespaces());
       
        return marshalDocument(root, mctx, jdomWriter);
    }
View Full Code Here

   
    private static Document marshalActualDocument(Object root, Document document) throws JiBXException {
        final IBindingFactory bfact = BindingDirectory.getFactory(root.getClass());
        final IMarshallingContext mctx = bfact.createMarshallingContext();
       
        final JDOMWriter jdomWriter = new JDOMWriter(bfact.getNamespaces(), document);
       
        return marshalDocument(root, mctx, jdomWriter);
    }
View Full Code Here

   
    private static Document marshalActualDocument(Object root, Element element) throws JiBXException {
        final IBindingFactory bfact = BindingDirectory.getFactory(root.getClass());
        final IMarshallingContext mctx = bfact.createMarshallingContext();
       
        final JDOMWriter jdomWriter = new JDOMWriter(bfact.getNamespaces(), element);
       
        return marshalDocument(root, mctx, jdomWriter);
    }
View Full Code Here

TOP

Related Classes of org.jibx.extras.JDOMWriter

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.