Hello Simon

Thanks for replying

The creation of new rules is not an issue but I was speculating on using existing rules like
object-create-rule, set-next-rule and others.

Putting all rule logic into one isn't really very efficient and I would be duplicating code...

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.

That is exactly the problem. Inside one pattern I cannot add more than one object to the stack as popping only happens when the pattern ends. And not the rule...

And is it really so unusual to set two or more parent-child connections instead of only one?

Regards
   Richard

----- Original Message ----- From: "Simon Kitching" <[EMAIL PROTECTED]>
To: "Richard Wood" <[EMAIL PROTECTED]>
Cc: <[email protected]>
Sent: Wednesday, June 29, 2005 12:13 PM
Subject: [digester] multiple parent child relationships using xmlrules


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();
   obj1.addBBB(obj2);
   obj1.addBBB(obj2);
   // 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.

Regards,

Simon


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to