commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <>
Subject Re: [digester] help with multi-argument constructor
Date Mon, 26 May 2003 22:37:34 GMT
On Tue, 2003-05-27 at 07:12, Christopher Bare wrote:
> If I understand correctly, the CallParam pushes values
> onto the stack and the CallMethod rule pops them off
> and finally invokes the method in the
> end(java.lang.String namespace, java.lang.String name)
> method of the rule.

Sort of.

There are actually two stacks: the stack of *objects* and the stack of
"parameter sets". The object stack is the "main" one. The "parameter set
stack" is a bit of a hack really, but it works.

When the start of a tag is encountered, the set of matching rules is
determined. The "start" method of each matching rule is immediately
invoked, passing the set of attributes defined for that tag. The set of
matching rules is then cached away, and all nested tags are processed.
When the end of the tag is encountered, the "body" method of each rule
is invoked, then after that the "end" method of each rule is invoked *in
reverse order*.

For the ObjectCreateRule, the start method creates an instance of the
target class and pushes it onto the object stack. This is typically
followed by a SetNextRule which calls a method on the second-to-top
object on the object stack, passing the top object as a parameter.

The nested tags are then processed; any rules triggered as a result will
see the object previously created on the top of the object stack.

The end tag is then processed; the ObjectCreateRule's end method is
called which pops the created object off the stack.

>  I was thinking that the
> CallConstructor rule could work the same way, and that
> the newly created object could be pushed onto the
> stack in the end(...) method. Then the SetNext rule
> could come along and pop do its thing.

It is not the SetNextRule which pops the created object off the stack,
but the end method of the ObjectCreateRule. Otherwise, if someone
doesn't want to use SetNextRule, then the stack wouldn't get cleaned up.

Clearly, we can't create the object in a start method, because the
parameters aren't yet available. And we can't create the object in an
end method, because the end method also has the responsibility of
cleaning up the stack, therefore the created object has zero time
resident on the stack.

But as you & Robert pointed out, a solution could involve creating the
object in the body method. Not sure what the implications would be
(whether rules would interact reasonably in this situation), but worth

> definitely push the new object first. Would body(...)
> definitely be called -after- the params were pushed
> onto the stack?

The body method would definitely be called after all parameters in the
"parameter set" associated with your rule had been populated.

NB: the "parameter set stack" is actually a stack where each object on
the stack is an array of objects. One array --> one set of parameters to
be passed to some target method. The CallParamRule instances populate
the elements of the array on top of the parameter stack.

Good luck,


View raw message