Package org.apache.commons.betwixt.io

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


    }

    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 AlphaListHolder);
        AlphaListHolder holder = (AlphaListHolder)bean;
       
        AlphaList list = holder.getAlphaList();
View Full Code Here


        //log = new
        // SimpleLog("[testReadwithCollectionsInElementRoundTrip:BeanReader]");
        //log.setLevel(SimpleLog.LOG_LEVEL_TRACE);

        BeanReader reader = new BeanReader();
        reader.setXMLIntrospector(intro);
        //reader.setLog(log);
        reader.registerBeanClass(ElementBean.class);

        ElementBean bean = (ElementBean) reader
                .parse(getTestFileURL("src/test/org/apache/commons/betwixt/recursion/recursion.xml"));

        List elements = bean.getElements();
        assertEquals("Root elements size", 2, elements.size());
        Element elementOne = (Element) elements.get(0);
View Full Code Here

        //        intro.setLog(log);
        //        log = new
        // SimpleLog("[testReadWithoutCollectionsInElementRoundTrip:XMLIntrospectorHelper]");
        //        log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
        //        XMLIntrospectorHelper.setLog(log);
        BeanReader reader = new BeanReader();
        //        log = new
        // SimpleLog("[testReadWithoutCollectionsInElementRoundTrip:BeanReader]");
        //        log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
        //        reader.setLog(log);
        reader.setXMLIntrospector(intro);
        reader.registerBeanClass(ElementBean.class);
        ElementBean bean = (ElementBean) reader
                .parse(getTestFileURL("src/test/org/apache/commons/betwixt/recursion/recursion2.xml"));
        List elements = bean.getElements();
        assertEquals("Number of elements in root bean", 2, elements.size());
        Element elementOne = (Element) bean.elements.get(0);
        assertEquals("First element name", "element1", elementOne.getName());
View Full Code Here

        }
    }

    /** Tests for a stack overflow bug */
    public void testRegisterOverflow() throws Exception {
        BeanReader reader = new BeanReader();
        try {
            reader.registerBeanClass(NorthWind.class);
        } catch (StackOverflowError e) {
            e.printStackTrace();
            fail("Expected registration to succeed");
        }
    }
View Full Code Here

            fail("Expected registration to succeed");
        }
    }

    public void testRegisterOverflow2() throws Exception {
        BeanReader beanReader = new BeanReader();
        try {
            beanReader.registerBeanClass(PersonTest.class);
        } catch (StackOverflowError e) {
            e.printStackTrace();
            fail("Expected registration to succeed");
        }
    }
View Full Code Here

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

        BeanReader beanReader = new BeanReader();
        beanReader.getBindingConfiguration().setMapIDs(true);

        // Configure the reader
        beanReader.registerBeanClass(PersonTest.class);
        beanReader.registerBeanClass(AddressTest.class);
        beanReader.registerBeanClass(ReferenceTest.class);

        String out = outputWriter.toString();
        StringReader xmlReader = new StringReader(out);

        //Parse the xml
        PersonTest result = (PersonTest) beanReader.parse(xmlReader);
        assertSame("Cycle did not result in the same reference", result, result
                .getAddress().getReference().getPerson());

    }
View Full Code Here

  @SuppressWarnings("unchecked")
  public <T> T convertToObject(String xml, Class<T> className) {
    String errorMessage = "Could not convert " + xml + " to " + className;

    BeanReader reader = new BeanReader();
    try {
      reader.registerBeanClass("activity", className);
      StringReader rd = new StringReader(xml);
      return (T) reader.parse(rd);
    } catch (IntrospectionException e) {
      throw new RuntimeException(errorMessage, e);
    } catch (IOException e) {
      throw new RuntimeException(errorMessage, e);
    } catch (SAXException e) {
View Full Code Here

  public static final String ERROR_MESSAGE_FMT = "Could not convert %s to %s";

  @SuppressWarnings("unchecked")
  public <T> T convertToObject(String xml, Class<T> className) {
    xml=xml.substring(xml.indexOf("?>") + 2);
    BeanReader reader = new BeanReader();
    try {
      reader.registerBeanClass("activity", className);
      StringReader rd = new StringReader(xml);
      return (T) reader.parse(rd);
    } catch (IntrospectionException e) {
      throw new RuntimeException(String.format(ERROR_MESSAGE_FMT, xml, className), e);
    } catch (IOException e) {
      throw new RuntimeException(String.format(ERROR_MESSAGE_FMT, xml, className), e);
    } catch (SAXException e) {
View Full Code Here

     *
     * @return The reader
     */
    protected BeanReader getReader() throws IntrospectionException, SAXException, IOException
    {
        BeanReader reader = new BeanReader();

        reader.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(true);
        reader.getXMLIntrospector().getConfiguration().setWrapCollectionsInElement(false);
        reader.getXMLIntrospector().getConfiguration().setElementNameMapper(new HyphenatedNameMapper());
        reader.setValidating(isValidateXml());
        if (isUseInternalDtd())
        {
            reader.setEntityResolver(new LocalEntityResolver());
        }
        reader.registerMultiMapping(getBetwixtMapping());

        return reader;
    }
View Full Code Here

    {
        SchedulerConfig schedConf = new SchedulerConfig();
        FileInputStream in = new FileInputStream(new File(XML));

        // create a new BeanReader
        BeanReader reader = createBeanReader();

        SchedulerConfig schedConf2 = (SchedulerConfig) reader.parse(in);

        assertNotNull("scheduler should not be null.", schedConf2);
        assertEquals("there should be 2 job configurations", 2, schedConf2.getJobConfigs().size());
        assertEquals("there should be 2 triggers", 2, schedConf2.getTriggerConfigs().size());
        assertTrue("scheduler name should be scheduler1", schedConf2.getInstanceName().equals("scheduler1"));
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.