commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <>
Subject [digester] multiple parent child relationships using xmlrules
Date Wed, 29 Jun 2005 10:13:03 GMT
Hi Richard,

On Tue, 2005-06-28 at 18:45 +0200, Richard Wood wrote:
> Hello
> I'm defining my rules using XML and using the DigesterRuleParser.
> How can I set multiple parent child relationships and vice versa if I create 
> more than one child object inside one pattern
> example
> class BBB {
> void setAAA(AAA a) {...}
> }
> <pattern value="x">
>     <object-create-rule classname="AAA" />
>     <object-create-rule classname="BBB"/>
>     <set-top-rule methodname="setAAA"/>
>     <set-next-rule methodname="addBBB"/>
>     <object-create-rule classname="BBB"/>
>     <set-top-rule methodname="setAAA"/>
>     <set-next-rule methodname="addBBB"/>
> </pattern>

In future, please put the commons component you are interested in at the
start of the email subject line. It's in your own interest as I didn't
see your email until now...

I don't understand what you are trying to achieve.

It looks like you are trying to do this:
 * when element <x> is encountered
     Create one AAA and two BBB objects and link them all together

Is this really the case? This is very unusual and it isn't any surprise
that Digester doesn't handle it out of the box.

Assuming you really do want this, the best solution is probably to write
your own custom rule class. Don't be reluctant to create a custom Rule;
it's quite ok to do so.

public class CreateOddSetOfObjectsRule extends Rule {
  public void begin(String ns, String element, Attributes attrs) {
    AAA obj1 = new AAA();
    BBB obj2 = new BBB();
    BBB obj3 = new BBB();
    // etc

    // Here possibly push one or more of these objects onto the 
    // digester stack so other rules can manipulate them. If
    // you do this, provide an end method that pops them back
    // off again.

Note however that digester rules typically operate on the top object on
the stack. So you may find that pushing more than one of the objects you
create onto the stack isn't useful.



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

View raw message