Package org.apache.commons.betwixt.io

Examples of org.apache.commons.betwixt.io.BeanWriter


     *
     * @see de.netseeker.ejoe.adapter.SerializeAdapter#write(java.lang.Object, java.io.OutputStream)
     */
    public void write( Object obj, OutputStream out ) throws Exception
    {
        BeanWriter beanWriter = new BeanWriter( out );
        beanWriter.getXMLIntrospector().setRegistry( getRegistry() );
        beanWriter.setWriteEmptyElements( true );
        beanWriter.writeXmlDeclaration( XML_DECLARATION );
        beanWriter.getBindingConfiguration().setMapIDs( false );
        try
        {
            beanWriter.write( obj.getClass().getName(), obj );
        }
        finally
        {
            if ( beanWriter != null ) beanWriter.close();
        }
    }
View Full Code Here


     * retrieved bean
     */
    private void write(Object bean, Writer out, boolean wrapIt)
    throws Exception
    {
        BeanWriter writer = new BeanWriter(out);
        writer.setWriteEmptyElements( true );
        writer.setXMLIntrospector(createXMLIntrospector());
        // specifies weather to use collection elements or not.
        writer.getXMLIntrospector().setWrapCollectionsInElement(wrapIt);
        // we don't want to write Id attributes to every element
        // we just want our opbject model written nothing more..
        writer.setWriteIDs(false);
        // the source has 2 spaces indention and \n as line seperator.
        writer.setIndent("  ");
        writer.setEndOfLine("\n");
        writer.write(bean);
    }
View Full Code Here

    {
        IdBean bean = new IdBean("Hello, World");
        bean.setNotId("Not ID");
        StringWriter out = new StringWriter();
        out.write("<?xml version='1.0'?>");
        BeanWriter writer = new BeanWriter(out);
        writer.setWriteEmptyElements( true );
        writer.getXMLIntrospector().setAttributesForPrimitives(true);
        writer.setWriteIDs(true);
        writer.write(bean);
       
        String xml = "<?xml version='1.0'?><IdBean notId='Not ID' id='Hello, World'/>";
       
        xmlAssertIsomorphic(parseString(xml), parseString(out.getBuffer().toString()), true);
    }   
View Full Code Here

        beta.addElement(gamma);
        gamma.addElement(epsilon);
        alpha.addElement(epsilon);
       
        StringWriter stringWriter = new StringWriter();
        BeanWriter writer = new BeanWriter(stringWriter);
        writer.setWriteEmptyElements( true );
        writer.setWriteIDs(false);
        writer.write(alpha);

        String xml = "<?xml version='1.0'?><Element><name>Alpha</name><elements><element>"
                    + "<name>Beta</name><elements><element><name>Gamma</name><elements>"
                    + "<element><name>Epsilon</name><elements/></element></elements>"
                    + "</element></elements></element><element><name>Epsilon</name>"
View Full Code Here

        beta.addElement(gamma);
        gamma.addElement(epsilon);
        epsilon.addElement(beta);
       
        StringWriter stringWriter = new StringWriter();
        BeanWriter writer = new BeanWriter(stringWriter);
        writer.setWriteEmptyElements( true );
        writer.setWriteIDs(false);
       
        //SimpleLog log = new SimpleLog("[testCyclicReferenceStack2:BeanWriter]");
        //log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
        //writer.setLog(log);
       
        //log = new SimpleLog("[testCyclicReferenceStack2:BeanWriter]");
        //log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
        //writer.setAbstractBeanWriterLog(log);
       
        try {
            writer.write(alpha);
            fail("Cycle was not detected!");
           
        } catch (CyclicReferenceException e) {
            // that's what we expected!
        }
View Full Code Here

        names.addName(new NameBean("Charles Hawtrey"));
       
        StringWriter out = new StringWriter();
        out.write("<?xml version='1.0'?>");

        BeanWriter writer = new BeanWriter(out);
        writer.setWriteEmptyElements(true);
        writer.getXMLIntrospector().setWrapCollectionsInElement(true);
        writer.setWriteIDs(false);
        writer.write("CarryOn", names);
       
        String xml = "<?xml version='1.0'?><CarryOn><names>"
         + "<name><name>Sid James</name></name>"
         + "<name><name>Kenneth Williams</name></name>"
         + "<name><name>Joan Simms</name></name>"
         + "<name><name>Charles Hawtrey</name></name>"
         + "</names>"
         +"</CarryOn>";
        
        xmlAssertIsomorphicContent(
                            parseString(out.getBuffer().toString()),
                            parseString(xml),
                            true);
                           
        out = new StringWriter();
        out.write("<?xml version='1.0'?>");

        writer = new BeanWriter(out);
        writer.setWriteEmptyElements(true);
        writer.getXMLIntrospector().setWrapCollectionsInElement(true);
        writer.setWriteIDs(false);
        writer.getXMLIntrospector().setElementNameMapper(new CapitalizeNameMapper());
        writer.write("CarryOn", names);
       
        xml = "<?xml version='1.0'?><CarryOn><Names>"
         + "<Name><Name>Sid James</Name></Name>"
         + "<Name><Name>Kenneth Williams</Name></Name>"
         + "<Name><Name>Joan Simms</Name></Name>"
         + "<Name><Name>Charles Hawtrey</Name></Name>"
         + "</Names>"
         +"</CarryOn>";
        
        xmlAssertIsomorphicContent(
                            parseString(out.getBuffer().toString()),
                            parseString(xml),
                            true);
                           
        ArrayList things = new ArrayList();
        things.add(new NameBean("Sugar"));
        things.add(new NameBean("Spice"));
        things.add(new NameBean("All Things Nice"));
       
        NoAdderBean bean = new NoAdderBean();
        bean.setThings(things);
       
        out = new StringWriter();
        out.write("<?xml version='1.0'?>");
        writer = new BeanWriter(out);
        writer.setWriteEmptyElements(true);
        writer.getXMLIntrospector().setWrapCollectionsInElement(true);
        writer.setWriteIDs(false);
        writer.write(bean);
       
        xml = "<?xml version='1.0'?><NoAdderBean><things>"
         + "<NameBean><name>Sugar</name></NameBean>"
         + "<NameBean><name>Spice</name></NameBean>"
         + "<NameBean><name>All Things Nice</name></NameBean>"
         + "</things>"
         +"</NoAdderBean>";
        
        xmlAssertIsomorphicContent(
                            parseString(out.getBuffer().toString()),
                            parseString(xml),
                            true);
       
        out = new StringWriter();
        out.write("<?xml version='1.0'?>");
        writer = new BeanWriter(out);
        writer.setWriteEmptyElements(true);
        writer.getXMLIntrospector().setWrapCollectionsInElement(true);
        writer.setWriteIDs(false);
        writer.getXMLIntrospector().setElementNameMapper(new CapitalizeNameMapper());
        writer.write(bean);
       
        xml = "<?xml version='1.0'?><NoAdderBean><Things>"
         + "<NameBean><Name>Sugar</Name></NameBean>"
         + "<NameBean><Name>Spice</Name></NameBean>"
         + "<NameBean><Name>All Things Nice</Name></NameBean>"
         + "</Things>"
         +"</NoAdderBean>";
        
        xmlAssertIsomorphicContent(
                            parseString(out.getBuffer().toString()),
                            parseString(xml),
                            true);
                           
        out = new StringWriter();
        out.write("<?xml version='1.0'?>");
        writer = new BeanWriter(out);
        writer.setWriteEmptyElements(true);
        writer.getXMLIntrospector().setWrapCollectionsInElement(true);
        writer.setWriteIDs(false);
        writer.getXMLIntrospector().setElementNameMapper(new HyphenatedNameMapper(false));
        writer.write(bean);
       
        xml = "<?xml version='1.0'?><no-adder-bean><things>"
         + "<name-bean><name>Sugar</name></name-bean>"
         + "<name-bean><name>Spice</name></name-bean>"
         + "<name-bean><name>All Things Nice</name></name-bean>"
View Full Code Here

        elements.addElement(new Element("a"));
        elements.addElement(new Element("b"));
        elements.addElement(new Element("c"));

        StringWriter out = new StringWriter();
        BeanWriter writer = newBeanWriter(out, mapper);
        writer.setWriteEmptyElements(true);
        writer.write(elements);
        writer.flush();
       
        String xmlOut = out.toString();
       
//        testLog.debug(xmlOut);
View Full Code Here

    private BeanWriter newBeanWriter(Writer writer, NameMapper mapper) {
//        SimpleLog log = new SimpleLog("[TextElementsIO:BeanWriter]");
//        log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
       
        BeanWriter result = new BeanWriter(writer);
        result.setWriteEmptyElements(true);
//        result.setLog(log);
       
//        log = new SimpleLog("[TextElementsIO:AbstractBeanWriter]");
//        log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
//        result.setAbstractBeanWriterLog(log);
       
        result.setXMLIntrospector(newXMLIntrospector(mapper));
        result.enablePrettyPrint();
        result.setWriteIDs(false);
        return result;
    }
View Full Code Here

//        SimpleLog log = new SimpleLog("[testCustomUpdaters:XMLIntrospector]");
//        log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
       
        StringWriter out = new StringWriter();
        out.write("<?xml version='1.0'?>");
        BeanWriter writer = new BeanWriter(out);
//        writer.getXMLIntrospector().setLog(log);

//        log = new SimpleLog("[testCustomUpdaters:XMLIntrospectorHelper]");
//        log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
//        XMLIntrospectorHelper.setLog(log);
       
        writer.setWriteIDs(false);
        writer.write(bean);

      String xml = "<?xml version='1.0'?><mixed><name>Lov</name><bad-name>Hate</bad-name>"
          + "<items><item>White</item><item>Life</item></items>"
          + "<bad-items><bad-item>Black</bad-item><bad-item>Death</bad-item></bad-items></mixed>";
       
View Full Code Here

            assertEquals("Second element name", "alpha" , elementDescriptors[1].getPropertyName());
        }
       
        // might as well give test output
        StringWriter out = new StringWriter();
        BeanWriter writer = new BeanWriter(out);
        writer.setWriteIDs(false);
        BeanWithBeanInfoBean bean = new BeanWithBeanInfoBean("alpha value","beta value","gamma value");
        writer.write(bean);
       
        if (alphaFirst) {
       
            xmlAssertIsomorphicContent(
                    parseFile("src/test/org/apache/commons/betwixt/introspection/test-bwbi-output-a.xml"),
View Full Code Here

TOP

Related Classes of org.apache.commons.betwixt.io.BeanWriter

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.