Package org.apache.commons.betwixt.io

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


        ListedClassNormalizer classNormalizer = new ListedClassNormalizer();
        classNormalizer.addSubstitution( IFace.class );
       
        StringWriter out = new StringWriter();
        out.write("<?xml version='1.0'?>");
        BeanWriter writer = new BeanWriter( out );
        writer.getXMLIntrospector().setClassNormalizer( classNormalizer );
        FaceImpl bean = new FaceImpl();
        bean.setName("Old Tom Cobbly");
        writer.write(bean);
       
        String xml="<?xml version='1.0'?><IFace><name>Old Tom Cobbly</name></IFace>";
        xmlAssertIsomorphicContent(
                            parseString(out.getBuffer().toString()),
                            parseString(xml),
View Full Code Here


                            true);
    }
   
    public void testBeanWriterWorksWithAnAddMethodAndACollection() throws Exception {

        BeanWriter bw = new BeanWriter();
        try {
            bw.write(new BeanWithAddMethod());
        } catch (IllegalArgumentException e) {
            fail("BeanWriter fails when a method is just called add(<type>) and there is also a collection");
        }
    }
View Full Code Here

        // Betwixt just writes out the bean as a fragment
        // we want well-formed xml, we need to add the prolog
        writer.write(XML_PROLOG);

        // Create a BeanWriter which writes to our prepared stream
        BeanWriter beanWriter = new BeanWriter(writer);

        // Configure betwixt
        // For more details see java docs or later in the main documentation
        beanWriter.getXMLIntrospector().setAttributesForPrimitives(true);
        beanWriter.setWriteIDs(false);
        beanWriter.enablePrettyPrint();

        // Write example bean as base element 'person'
        beanWriter.write("message", msg);
        beanWriter.flush();

        return writer.toString();
    }
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

        dynasaur.set("isRaptor", Boolean.TRUE);
        dynasaur.set("Period", "Jurassic");
       
        StringWriter out = new StringWriter();
        out.write("<?xml version='1.0'?>");
        BeanWriter writer = new BeanWriter(out);
        writer.getXMLIntrospector().setElementNameMapper(new DecapitalizeNameMapper());
        writer.write(dynasaur);
       
        String xml = "<?xml version='1.0'?><dynasaur><species>Allosaurus</species>"
            + "<isRaptor>true</isRaptor><period>Jurassic</period></dynasaur>";
       
        xmlAssertIsomorphicContent
View Full Code Here

    private BeanWriter newBeanWriter(Writer writer, NameMapper mapper) {
//        SimpleLog log = new SimpleLog("[TestElementsAlt:BeanWriter]");
//        log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
       
        BeanWriter result = new BeanWriter(writer);
        result.setWriteEmptyElements( true );
//        result.setLog(log);
       
//        log = new SimpleLog("[TestElementsAlt: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

   
    public void testOverrideWithDotBetwixt() throws Exception {
        DynaWithDotBetwixt bean = new DynaWithDotBetwixt("Tweedledum","Tweedledee");
        StringWriter out = new StringWriter();
        out.write("<?xml version='1.0'?>");
        BeanWriter writer = new BeanWriter(out);
        writer.getXMLIntrospector().setElementNameMapper(new DecapitalizeNameMapper());
        writer.write("bean", bean);
       
        String xml = "<?xml version='1.0'?><bean><ndp>Tweedledum</ndp></bean>";
        xmlAssertIsomorphicContent
                            "Test write dyna beans with dt betwixt",
                            parseString(xml),
View Full Code Here

       
        write( bean );
    }
       
    public void write(Object bean) throws Exception {
        BeanWriter writer = new BeanWriter();
        writer.getXMLIntrospector().setAttributesForPrimitives(false);
        writer.enablePrettyPrint();
        writer.write( bean );
    }
View Full Code Here

     * retrieved bean
     */
    private void write(Object bean, Writer out, boolean wrapCollectionsInElement)
    throws Exception
    {
        BeanWriter writer = new BeanWriter(out);
        writer.setWriteEmptyElements( true );
        writer.setXMLIntrospector(createXMLIntrospector());
        // specifies weather to use collection elements or not.
        writer.getXMLIntrospector().setWrapCollectionsInElement(wrapCollectionsInElement);
        // 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

    }

    public void testSimpleRead() throws Exception {
        StringWriter out = new StringWriter();
        out.write("<?xml version='1.0'?>");
        BeanWriter writer = new BeanWriter(out);
        IDBean bean = new IDBean("alpha","one");
        bean.addChild(new IDBean("beta","two"));
        bean.addChild(new IDBean("gamma","three"));
        writer.write(bean);
       
        String xml = "<IDBean><name>one</name><children><child><name>two</name><children/>"
                + "<id>beta</id></child><child><name>three</name><children/>"
                + "<id>gamma</id></child></children><id>alpha</id></IDBean>";
               
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.