commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "*Colin Sharples" <>
Subject Digester FactoryCreate rule
Date Fri, 02 Nov 2001 04:36:56 GMT

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"/>

digester.addObjectCreateRule("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.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?


Colin Sharples
IBM Global Services New Zealand.

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

View raw message