You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Marcos Hass W <ma...@gmail.com> on 2006/09/19 19:13:40 UTC

Betwixt array property error

Hi all,

This problem is driving crazy, I''ve spent a lot of time trying to figure
out what's wrong ;-( and until now I don't have any clue. (Tried to search
in docs but didn't find this scenario)

Ok, I've built some tiny classes to explain what's happening.:

1.) I have a ParentBean class that has a nested IntermediaryBean.:

public class ParentBean {

    public ParentBean() {
    }

    private IntermediaryBean intermediary;

    public IntermediaryBean getIntermediary() {
        return this.intermediary;
    }

    public void setIntermediary(IntermediaryBean intermediary) {
        this.intermediary = intermediary;
    }

}

2.) IntermediaryBean has an array based property (children) of type
ChildrenBean.:

public class IntermediaryBean {

    public IntermediaryBean() {
    }

    private ChildrenBean[] children;

    public ChildrenBean getChildren(int index) {
        return this.children[index];
    }

    public ChildrenBean[] getChildren() {
        return this.children;
    }

    public void setChildren(int index, ChildrenBean children) {
        this.children[index] = children;
    }

    public void setChildren(ChildrenBean[] children) {
        this.children = children;
    }

}

3.)  ChildrenBean is a very simple class that has only 02 properties (name,
age).:

public class ChildrenBean {

    public ChildrenBean() {
    }

    private String name;

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    private int age;

    public int getAge() {
        return this.age;
    }
    public void setAge(int age) {
        this.age = age;
    }

}


4.) To produce the xml I've used the following method.:

    public static String loaderJobBeanToOlj(Object o) throws IOException,
            SAXException, IntrospectionException {

        String ret = null;

        StringWriter outputWriter = new StringWriter();

        outputWriter.write("<?xml version='1.0' encoding='UTF-8' ?>");

        BeanWriter beanWriter = new BeanWriter(outputWriter);

        beanWriter.getXMLIntrospector
().getConfiguration().setAttributesForPrimitives(false);
        beanWriter.getBindingConfiguration().setMapIDs(false); /** Composite
*/
        beanWriter.enablePrettyPrint();
        beanWriter.getXMLIntrospector().setRegistry(new NoCacheRegistry());

        beanWriter.write(o);

        ret = outputWriter.toString();

        outputWriter.close();

        return ret;
    }

5.) The xml produced is.:

<?xml version='1.0' encoding='UTF-8' ?>
<ParentBean>
    <intermediary>
      <children>
        <ChildrenBean>
          <age>12</age>
          <name>Filho</name>
        </ChildrenBean>
      </children>
    </intermediary>
</ParentBean>

6.) I try to feed the objects using the above xml with the following code.:

    public static Object oljToLoaderJobBean(String olj) throws
IntrospectionException,
            IOException, SAXException {

        Object ret = null;

        StringReader xmlReader = new StringReader(olj);

        BeanReader beanReader  = new BeanReader();

        beanReader.getXMLIntrospector
().getConfiguration().setAttributesForPrimitives(false);

        beanReader.getBindingConfiguration().setMapIDs(false);

        beanReader.registerBeanClass("ParentBean", ParentBean.class);

        ret = beanReader.parse(xmlReader);

        return ret;
    }

      And I get the following error.:

SEVERE: End event threw exception
java.util.EmptyStackException
        at org.apache.commons.collections.ArrayStack.peek(ArrayStack.java
:94)
        at org.apache.commons.betwixt.io.read.ReadContext.getBean(
ReadContext.java:349)
        at org.apache.commons.betwixt.expression.TypedUpdater.update(
TypedUpdater.java:46)
        at org.apache.commons.betwixt.io.read.BeanBindAction.update(
BeanBindAction.java:170)
        at org.apache.commons.betwixt.io.read.BeanBindAction.end(
BeanBindAction.java:157)
        at org.apache.commons.betwixt.io.BeanRuleSet$ActionMappingRule.end(
BeanRuleSet.java:315)
        at org.apache.commons.digester.Digester.endElement(Digester.java
:1130)
        at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown
Source)
        at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown
Source)
        at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown
Source)
        at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
Source)
        at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
        at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
        at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown
Source)
        at org.apache.commons.digester.Digester.parse(Digester.java:1685)
        at com.softing.octopus.transformer.Transformer.oljToLoaderJobBean(
Transformer.java:96)
        at
com.softing.octopus.transformer.TransformerTest.testLoaderJobBeanToOlj(
TransformerTest.java:185)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(
NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(
DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at junit.framework.TestCase.runTest(TestCase.java:154)
        at junit.framework.TestCase.runBare(TestCase.java:127)
        at junit.framework.TestResult$1.protect(TestResult.java:106)
        at junit.framework.TestResult.runProtected(TestResult.java:124)
        at junit.framework.TestResult.run(TestResult.java:109)
        at junit.framework.TestCase.run(TestCase.java:118)
        at junit.framework.TestSuite.runTest(TestSuite.java:208)
        at junit.framework.TestSuite.run(TestSuite.java:203)
        at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(
JUnitTestRunner.java:297)
        at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(
JUnitTestRunner.java:672)
        at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main
(JUnitTestRunner.java:567)
------------- ---------------- ---------------
Testcase: testLoaderJobBeanToOlj(
com.softing.octopus.transformer.TransformerTest):    Caused an ERROR
Error at line 10 char 16: null
java.util.EmptyStackException
        at org.apache.commons.digester.Digester.createSAXException(
Digester.java:2919)
        at org.apache.commons.digester.Digester.createSAXException(
Digester.java:2945)
        at org.apache.commons.digester.Digester.endElement(Digester.java
:1133)
        at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown
Source)
        at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown
Source)
        at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown
Source)
        at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
Source)
        at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
        at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
        at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown
Source)
        at org.apache.commons.digester.Digester.parse(Digester.java:1685)
        at com.softing.octopus.transformer.Transformer.oljToLoaderJobBean(
Transformer.java:96)
        at
com.softing.octopus.transformer.TransformerTest.testLoaderJobBeanToOlj(
TransformerTest.java:185)


        at junit.framework.TestResult.run(TestResult.java:109)
        at junit.framework.TestCase.run(TestCase.java:118)
        at junit.framework.TestSuite.runTest(TestSuite.java:208)
        at junit.framework.TestSuite.run(TestSuite.java:203)
        at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(
JUnitTestRunner.java:297)
        at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(
JUnitTestRunner.java:672)
        at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main
(JUnitTestRunner.java:567)
Test com.softing.octopus.transformer.TransformerTest FAILED

Could someone help me with this issue ?

Thank you very much
Marcos