Examples of BeanReader


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

        StringWriter buffer = new StringWriter();
        write( bean, buffer );
       

        // create a BeanReader
        BeanReader reader = new BeanReader();
        reader.registerBeanClass( Channel.class );

        // Register local copies of the DTDs we understand
        for (int i = 0; i < registrations.length; i += 2) {
            URL url = RSSDigester.class.getResource(registrations[i + 1]);
            if (url != null) {
                reader.register(registrations[i], url.toString());
            }
        }
       
        // now lets try parse the output sing the BeanReader
        String text = buffer.toString();       
        bean = reader.parse( new StringReader( text ) );
       
        // managed to parse it again!
       
        // now lets write it to another buffer
        buffer = new StringWriter();
View Full Code Here

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

        RSSBeanReader sample = new RSSBeanReader("RSS");
        sample.run( args );
    }
   
    public void run(String[] args) throws Exception {
        BeanReader reader = new BeanReader();
       
        reader.registerBeanClass( Channel.class );
       
        // Register local copies of the DTDs we understand
        for (int i = 0; i < registrations.length; i += 2) {
            URL url = RSSDigester.class.getResource(registrations[i + 1]);
            if (url != null) {
                reader.register(registrations[i], url.toString());
            }
        }
       
        Object bean = null;
        if ( args.length > 0 ) {
            bean = reader.parse( args[0] );
        }
        else {
            InputStream in = new FileInputStream( getTestFile("src/test/org/apache/commons/betwixt/rss-example.xml") );
            bean = reader.parse( in );
            in.close();
        }
       
        write( bean );
    }
View Full Code Here

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

                return chain.create(mapping, context);
            }
        }
        chain.insertBeanCreator(1, new EnumCreator());
       
        BeanReader reader = new BeanReader();
        reader.getXMLIntrospector().setAttributesForPrimitives(true);
        reader.getXMLIntrospector().setWrapCollectionsInElement(false);
        reader.registerBeanClass("houses", HouseBeans.class);
        reader.getReadConfiguration().setBeanCreationChain(chain);
       
        StringReader in = new StringReader(xml);
        HouseBeans newHouses = (HouseBeans) reader.parse(in);
        assertNotNull("Parsing should return a bean", newHouses);
       
        ArrayList houseList = newHouses.houses;
        assertEquals("Should be two houses read", 2, houseList.size());
        HouseBean newOne = (HouseBean) houseList.get(0);
View Full Code Here

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

                return chain.create(mapping, context);
            }
        }
        chain.insertBeanCreator(1, new EnumCreator());
       
        BeanReader reader = new BeanReader();
        reader.getXMLIntrospector().setAttributesForPrimitives(true);
        reader.getXMLIntrospector().setWrapCollectionsInElement(false);
        reader.registerBeanClass("houses", HouseBeans.class);
        reader.getReadConfiguration().setBeanCreationChain(chain);
       
        StringReader in = new StringReader(xml);
        HouseBeans newHouses = (HouseBeans) reader.parse(in);
        assertNotNull("Parsing should return a bean", newHouses);
       
        ArrayList houseList = newHouses.houses;
        assertEquals("Should be two houses read", 2, houseList.size());
        HouseBean newOne = (HouseBean) houseList.get(0);
View Full Code Here

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

        "<book author='Ben Laurie' title='Apache' publisher='O&apos;Reilly'/>" +
        "<book author='Kent Beck' title='Test Driven Development' publisher='Addision Wesley'/>" +
        "</books>" +
        "</LibraryBean>";
       
        BeanReader reader = new BeanReader();
        reader.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(true);
        reader.getBindingConfiguration().setMapIDs(false);
        reader.registerBeanClass(LibraryBean.class);
        LibraryBean bean = (LibraryBean) reader.parse(new StringReader(xml));
       
        BookBean[] books = bean.getBooks();
        assertEquals("Three books read", 3, books.length);
        assertEquals("Book one", new BookBean("Martin Fowler", "Refactoring", "Addision Wesley"), books[0]);
        assertEquals("Book two", new BookBean("Ben Laurie", "Apache", "O'Reilly"), books[1]);
View Full Code Here

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

        "<BookBean author='Ben Laurie' title='Apache' publisher='O&apos;Reilly'/>" +
        "<BookBean author='Kent Beck' title='Test Driven Development' publisher='Addision Wesley'/>" +
        "</books>" +
        "</LibraryBeanWithArraySetter>";
       
        BeanReader reader = new BeanReader();
        reader.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(true);
        reader.getBindingConfiguration().setMapIDs(false);
        reader.registerBeanClass(LibraryBeanWithArraySetter.class);
        LibraryBeanWithArraySetter bean = (LibraryBeanWithArraySetter) reader.parse(new StringReader(xml));
       
        BookBean[] books = bean.getBooks();
        assertEquals("Three books read", 3, books.length);
        assertEquals("Book one", new BookBean("Martin Fowler", "Refactoring", "Addision Wesley"), books[0]);
        assertEquals("Book two", new BookBean("Ben Laurie", "Apache", "O'Reilly"), books[1]);
View Full Code Here

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

                return chain.create(mapping, context);
            }
        }
        chain.insertBeanCreator(1, new EnumCreator());
       
        BeanReader reader = new BeanReader();
        reader.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(true);
        reader.getXMLIntrospector().getConfiguration().setWrapCollectionsInElement(false);
        reader.registerBeanClass("houses", HouseBeans.class);
        reader.getReadConfiguration().setBeanCreationChain(chain);
       
        StringReader in = new StringReader(xml);
        HouseBeans newHouses = (HouseBeans) reader.parse(in);
        assertNotNull("Parsing should return a bean", newHouses);
       
        ArrayList houseList = newHouses.houses;
        assertEquals("Should be two houses read", 2, houseList.size());
        HouseBean newOne = (HouseBean) houseList.get(0);
View Full Code Here

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

                return chain.create(mapping, context);
            }
        }
        chain.insertBeanCreator(1, new EnumCreator());
       
        BeanReader reader = new BeanReader();
        reader.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(true);
        reader.getXMLIntrospector().getConfiguration().setWrapCollectionsInElement(false);
        reader.registerBeanClass("houses", HouseBeans.class);
        reader.getReadConfiguration().setBeanCreationChain(chain);
       
        StringReader in = new StringReader(xml);
        HouseBeans newHouses = (HouseBeans) reader.parse(in);
        assertNotNull("Parsing should return a bean", newHouses);
       
        ArrayList houseList = newHouses.houses;
        assertEquals("Should be two houses read", 2, houseList.size());
        HouseBean newOne = (HouseBean) houseList.get(0);
View Full Code Here

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

        RSSBeanReader sample = new RSSBeanReader("RSS");
        sample.run( args );
    }
   
    public void run(String[] args) throws Exception {
        BeanReader reader = new BeanReader();
       
        reader.registerBeanClass( Channel.class );
       
        // Register local copies of the DTDs we understand
        for (int i = 0; i < registrations.length; i += 2) {
            URL url = RSSDigester.class.getResource(registrations[i + 1]);
            if (url != null) {
                reader.register(registrations[i], url.toString());
            }
        }
       
        Object bean = null;
        if ( args.length > 0 ) {
            bean = reader.parse( args[0] );
        }
        else {
            InputStream in = new FileInputStream( getTestFile("src/test/org/apache/commons/betwixt/rss-example.xml") );
            bean = reader.parse( in );
            in.close();
        }
       
        write( bean );
    }
View Full Code Here

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

        "<line>And he stoppeth one of three.</line>" +
        "<line>\"By thy long grey beard and the glittering eye,</line>" +
        "<line>Now wherefore stopp'st thou me?\"</line>" +
        "</lines>" +
        "</PoemBean>";
        BeanReader reader = new BeanReader();
        reader.registerBeanClass(PoemBean.class);
        PoemBean bean = (PoemBean) reader.parse(new StringReader(xml));
        assertNotNull("Expected bean to be output");
        Object[] lines = bean.getLines().toArray();
        assertEquals("Expected four lines", 4, lines.length);
        assertEquals("First line of Rime Of The Ancient Mariner", "It is an ancient Mariner,", lines[0]);
        assertEquals("Second line of Rime Of The Ancient Mariner", "And he stoppeth one of three.", lines[1]);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.