Package org.apache.commons.betwixt.io

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


        StringReader in = new StringReader(xmlOut);
       
//        SimpleLog log = new SimpleLog("[TextElementsIO:BeanReader]");
//        log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
       
        BeanReader reader = new BeanReader();
//        reader.setLog(log);

//        log = new SimpleLog("[TextElementsIO:BeanReader]");
//        log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
//        BeanCreateRule.setLog(log);
       
        reader.setXMLIntrospector(newXMLIntrospector(mapper));
        reader.registerBeanClass(Elements.class);
        Elements result = (Elements) reader.parse(in);

        assertNotNull("Element 'a' is null (" + testName + ")", result.getElement("a"));
        assertNotNull("Element 'b' is null (" + testName + ")", result.getElement("b"));
        assertNotNull("Element 'c' is null (" + testName + ")", result.getElement("c"));
    }
View Full Code Here


                "        <element name='wibble' property='alpha'/>" +
                "        <element name='wobble' property='beta'/>" +
                "    </element>" +
                "</info>");

          BeanReader reader = new BeanReader();
          reader.getBindingConfiguration().setMapIDs(false);
          reader.registerBeanClass(new InputSource(dotBetwixt), SimpleTestBean.class);
          SimpleTestBean bean = (SimpleTestBean) reader.parse(in);
          assertNotNull("Bean not mapped", bean);
          assertEquals("Property alpha mapping", "one", bean.getAlpha());
          assertEquals("Property beta mapping", "two", bean.getBeta());
    }
View Full Code Here

            "       </composer>" +
            "   </composers>" +
            "</TuneBean>";
       StringReader in = new StringReader(xml);
      
       BeanReader reader = new BeanReader();
       reader.getXMLIntrospector().getConfiguration().setSimpleTypeMapper(new StringsAsElementsSimpleTypeMapper());
       reader.getXMLIntrospector().getConfiguration().setWrapCollectionsInElement(true);
       reader.getBindingConfiguration().setMapIDs(false);
      
       reader.registerBeanClass(TuneBean.class);
      
       TuneBean bean = (TuneBean) reader.parse(in);
      
       assertNotNull("Parsing failed", bean);
       assertEquals("Name value", "On The Run", bean.getName());
       assertEquals("Artist value", "Pink Floyd", bean.getArtist());
       assertEquals("Recorded value", 1972, bean.getRecorded());
View Full Code Here

        beanWriter.setEndOfLine("\n");
        beanWriter.enablePrettyPrint();
        beanWriter.getBindingConfiguration().setMapIDs(true);
        beanWriter.write(father);

        BeanReader beanReader = new BeanReader();

        // Configure the reader
        beanReader.registerBeanClass(Father.class);
        StringReader xmlReader = new StringReader(outputWriter.toString());

        //Parse the xml
        Father result = (Father) beanReader.parse(xmlReader);

        assertNotNull("Unexpected null list of children!", result.getKids());
        assertEquals(
            "got wrong number of children",
            father.getKids().size(),
View Full Code Here

   
   
    public void testRead() throws Exception
    {
        StringReader in = new StringReader(XML);
        BeanReader reader = new BeanReader();
        reader.getBindingConfiguration().setMapIDs(false);
        reader.getXMLIntrospector().register(new InputSource(new StringReader(MAPPING)));
        reader.registerBeanClass(Animals.class);
        Animals animals = (Animals) reader.parse(in);
       
        assertNotNull(animals);
        assertEquals(3, animals.size());
       
        Iterator it = animals.getAnimals();
View Full Code Here

        super(testName);
    }
   
    public void testPersonList() throws Exception {

        BeanReader reader = new BeanReader();
        reader.registerBeanClass( PersonListBean.class );
       
        InputStream in = 
            new FileInputStream( getTestFile("src/test/org/apache/commons/betwixt/derived/person-list.xml") );
        try {
       
            checkBean((PersonListBean) reader.parse( in ));
           
        }
        finally {
            in.close();
        }  
View Full Code Here

//        BeanRuleSet.setLog(log);
       
//        log = new SimpleLog("[CombinedRoundTrip]");
//        log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
       
        BeanReader reader = createBeanReader();
       
        PhysicalSchema schema = (PhysicalSchema) reader.parse(
            getTestFileURL("src/test/org/apache/commons/betwixt/schema/schema.xml"));
        StringWriter buffer = new StringWriter();
        write(schema, buffer, true);
       
//        log.debug(buffer.getBuffer().toString());
       
        StringReader in = new StringReader(buffer.getBuffer().toString());
        reader = createBeanReader();
        XMLIntrospector intro = createXMLIntrospector();
        DefaultXMLBeanInfoRegistry registry = new DefaultXMLBeanInfoRegistry();
        intro.setRegistry(registry);
        // we have written the xml file back with element collections,
        // so we have to say to the reader we want to use that now
        // (the default when creating in this test is not to use them)
        intro.getConfiguration().setWrapCollectionsInElement(true);
        // first flush the cash, else setting other options, doesn't
        // end up in rereading / mapping the object model.
        registry.flush();
        // set the xmlIntrospector back to the reader
        reader.setXMLIntrospector(intro);
        reader.deregisterBeanClass(PhysicalSchema.class);
        reader.getRules().clear();
        reader.registerBeanClass(PhysicalSchema.class);
        PhysicalSchema schemaSecond = (PhysicalSchema) reader.parse(in);
        buffer.close();
        write(schema,buffer, true);
        assertEquals(schema, schemaSecond);
    }
View Full Code Here

     * Beans..
     */
    public void testRoundTripWithoutCollectionElement()
    throws Exception
    {
        BeanReader reader = createBeanReader();
        PhysicalSchema schema = (PhysicalSchema) reader.parse(
            getTestFileURL("src/test/org/apache/commons/betwixt/schema/schema.xml"));
        StringWriter buffer = new StringWriter();
        write(schema, buffer, false);
        StringReader in = new StringReader(buffer.getBuffer().toString());
        PhysicalSchema schemaSecond = (PhysicalSchema) reader.parse(in);
        assertEquals(schemaSecond, schema);
    }
View Full Code Here

     * Creates a beanReader
     */
    protected BeanReader createBeanReader()
    throws Exception
     {
        BeanReader reader = new BeanReader();
        reader.setXMLIntrospector(createXMLIntrospector());
        // register the class which maps to the root element
        // of the xml file (this depends on the NameMapper used.
        reader.registerBeanClass(PhysicalSchema.class);
        return reader;
    }
View Full Code Here

                true);
  }

  public void testRead() throws Exception {
    StringReader in = new StringReader(XML);
    BeanReader reader = new BeanReader();
    StringReader mapping = new StringReader(MAPPING);
    reader.registerMultiMapping(new InputSource(mapping));
        reader.registerBeanClass(AlphaList.class);
    configure(reader.getBindingConfiguration());
    Object bean = reader.parse(in);
    assertTrue(bean instanceof AlphaList);
    AlphaList list = (AlphaList) bean;
    assertEquals(2, list.size());
       
        assertTrue(list.get(0) instanceof AlphaOneImpl);
View Full Code Here

TOP

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

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.