Dear All,
I'm having some odd behaviour, which I hoped someone might recognise.
I am using the commons-digester 1.6 with xml rules to populate a config
object.
I have a class, 'Page', which contains a collection of 'Field's. Some of
these can also be CompoundField's, which are subclasses of Field. This is
made clearer below.
I have a Junit test which creates a Page, a compound and a field; the test
case seems to instantiate everything correctly without any exceptions.
This does not seem to be the case when I try to use the Digester.
I am trying to Digest an xml tree equivilent to the following:
...
<page>
<field name="foo"/>
<compoundField name="bar">
<cfield name="bar1"/>
</compoundField>
</page>
...
When I leave our my rules to create a compoundField, everything works
fine, however when they are included I get an exception with
StackOverflowError. None of the constructors or mutators used, seem to
cause me to go into any recursion - as proven by my junit test. The exact
error is of the form:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0( Native Method )
...
at org.apache.commons.digester.Digester.parse( Digester.java 1591
)
...
Caused by: java.lang.StackOverflowError
[ERROR] Digester - -End event threw exception
<java.lang.reflect.InvocationTargetException>
at org.apache.commons.digester.Digester.createSAXException( ... )
..
at org.apache.commons.digester.Digester.endElement( .... )
at ort.apache.commons.digester.Digester.parse( ... )
I have tested this with both commons-digester 1.6 and 1.7.
If I abstract my rules down to the lowest level, my these are as follows(
I have tested at this level of granularity - and failed ) :
<!-------------------------------------------------------->
....
<pattern value="page">
<object-create-rule classname="foo.model.Page" />
<!-- a field looks like: -->
<pattern value="field">
<object-create-rule classname="foo.model.Field"/>
<set-next-rule methodname="add"/>
<call-method-rule methodname="setName" paramcount="1"
paramtypes="java.lang.String"/>
<call-param-rule paramnumber="0" attrname="name"/>
</pattern>
<!-- create a compound -->
<pattern value="compoundField">
<!-- note that foo.model.CompoundField extends foo.model.Field -->
<object-create-rule classname="foo.model.CompoundField"/>
<set-next-rule methodname="addCompound"/>
<pattern value="cfield">
<object-create-rule classname="foo.model.Field"/>
<set-next-rule methodname="addMapping"/>
<call-method-rule methodname="setName" paramcount="1"
paramtypes="java.lang.String" />
<call-param-rule paramnumber="0" attrname="name"/>
</pattern>
</pattern>
</pattern>
<!------------------------------------------------------------------>
It might also be worth pointing out that if I comment out the
set-next-rule for addCompound, it also seems to work and I believe that my
tests indicicated that the CompoundField object was still being
instantiated.
Any feedback/similar experience would be appreciated.
Cheers,
Raf
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]