On Mon, 2004-12-06 at 07:30, Mihai C. wrote:
> Hi all, being new to digester, I have no clue how to get around my problem.
> Here's the story:
> I'm trying to parse a config xml that looks like this:
> <root>
> <a>
> .......
> <b>
> .....
> </b>
> <b>
> .....
> </b>
> </a>
> <a>
> .......
> <b>
> .....
> </b>
> <b>
> .....
> </b>
> </a>
> </root>
>
> I have two beans (ABean and BBean)
> and the factory :
> class Factory {
> processA(ABean ab){
> .......
> }
> processB(BBean bb){
> ........
> }
> digest(){
> Digester d = new Digester();
> d.push(this); //stack bottom
> d.addSetNext( "root/a/b", "processB" , "BBean"); // when
> root/a/b pattern mathes, execute processB on 'this' with BBean type param
> d.addSetNext( "root/a", "processA", "ABean"); // when root/a
> pattern mathes, execute processA on 'this' with ABean type param
> d.addObjectCreate( "root/a", ABean.class);
> d.addObjectCreate( "root/a/b", BBean.class);
>
> ............... //var addCallMethod()
> }
> }
>
> I get this error:
>
> [DEBUG] Digester - -[SetNextRule]{root/a/b} Call
> Factory.processB([EMAIL PROTECTED])
> [ERROR] Digester - -End event threw exception
> <java.lang.IllegalArgumentException: argument type
> mismatch>java.lang.IllegalArgumentException: argument type mismatch
>
> Obviously, processB() was called with the wrong arg type(ABean instead of
> BBean) and that because the BBean obj was just poped from the stack.
No, I think what is happening is that Digester is attempting to call a
method
processB(BBean)
on an object of type ABean. The ABean class presumably doesn't have such
a method.
The structure of your input xml implies that BBeans are children of
ABeans. But you appear to be trying to map this structure to a different
representation where ABean and BBean objects are children of a Factory
object. If you *really* want to do this, then I expect a way can be
found, but I doubt this is really what you want to achieve...
Remember that Digester has an object stack. You push an instance of
Factory on the stack initially. Then when an <a> tag is encountered,
your rules tell digester to create and push an ABean object onto the
stack, and call ProcessA on the (top-1) object (the Factory) passing the
top object (the ABean). All is ok so far. But then the <b> tag *within*
the <a> tag is encountered, so your rules tell Digester to create a
BBean object, push it on the stack, then call ProcessB on the (top-1)
object on the stack - which is an ABean. Now I think this probably *is*
what you want - the <b> tag is within the <a> tag, indicating that BBean
objects are children of ABean objects. So surely a method on the ABean
should be invoked to handle its children...
I hope this helps. If not, please provide a little more information on
why you don't want to map the input xml in the obvious manner..
Regards,
Simon
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]