commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "*Colin Sharples" <>
Subject RE: Digester FactoryCreate rule
Date Wed, 07 Nov 2001 03:39:09 GMT
Well, predictably enough, when I tried to create a simple example to test
the problem, I couldn't recreate it. I guess there must have been something
wrong with the order I added the rules to the Digester (although I'm pretty
sure I tried several ways). I don't have the real code to hand, because I
changed to another way which worked just as well. Never mind.

Colin Sharples
IBM Global Services New Zealand

-----Original Message-----
From: robert burrell donkin []
Sent: Tuesday, 6 November 2001 12:15 p.m.
To: Jakarta Commons Developers List
Subject: Re: Digester FactoryCreate rule

On Friday, November 2, 2001, at 04:36 AM, *Colin Sharples wrote:

> Hi,

hi colin
(my comments are below)

> I've been using the digester for a while now, and thought that I'd pretty
> much got on top of things. However, I've hit on a problem using the
> FactoryCreate rule. I'm not sure if this is because I'm not using this
> properly, or because there's a bug somewhere.
> I've happily been using the digester to create objects like this:
> <foo id="blah">
>   <bar id="blahblah"/>
> </foo>
> digester.addObjectCreateRule("foo/bar", "");
> digester.addSetProperties("foo/bar");
> digester.addSetNext("foo/bar", "addBar", "");
> which creates an instance of Bar and adds it to the foo object below it on
> the stack using foo.addBar(). So far so good.
> Now, I have a situation where I have previously created and cached the Bar
> objects, so instead of creating new Bar instances, I want to do a lookup
> using the id specified by the <bar> tag. I thought that I could use the
> FactoryCreate to do this, by creating an ObjectCreationFactory which knows
> how to locate the Bar objects by id. I changed the digester set-up to:
> digester.addFactoryCreateRule("foo/bar", "");
> digester.addSetProperties("foo/bar");
> digester.addSetNext("foo/bar", "addBar", "");
> I assumed that this would work the same way, but that just shows you 
> should
> never assume anything. The parse would fail with a NoSuchMethodError, 
> which
> stumped me a bit at first. Then I realised that the Bar object was being
> popped off the stack before the SetNext was happening, so that the 
> digester
> was trying to call addBar() on the object *below* foo. Setting debug to 
> lots
> showed that the end() event was indeed being fired to the FactoryCreate 
> rule
> *before* it was fired to the SetNext rule.
> This seems like strange behaviour - but is it buggy or am I interpreting
> things wrong?

since i've been adding test cases, i've written a test case for the call 
(i'll submit it with the rest of the stuff i've been working on.)
this test shows that the basic call code is ok.

i quite often have to tweak the order of rules. digester can be a little 
strange at times - but i've always been able to make things work by 
altering the order of the rules. i'll take a look if you post an example.

- robert

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message