On Thu, 16 May 2002, Brent Hale wrote:

> Date: Thu, 16 May 2002 09:23:21 -0600
> From: Brent Hale <[EMAIL PROTECTED]>
> Reply-To: Jakarta Commons Developers List <[EMAIL PROTECTED]>,
>      [EMAIL PROTECTED]
> To: [EMAIL PROTECTED]
> Subject: I need access to bodyText in Digester or a addSetRoot which can
>     get bodyText
>
> Hi,
>
> In my particular situation I need to call a method on an object which is not
> the top on on the stack and still get the body of the XML element being
> processed.  It appears to me that the only way to ever gain access to the
> body of the XML element being processed is through addCallMethod() passing
> zero in as the paramCount.  But that only calls methods on an object on the
> top of the stack.
>
> I see a couple possible solutions and I hope someone else may have even
> better ones.
>
> 1) Add a public String getBodyText() method to the digester.  I can then
> push the digester itself on the bottom of the stack and thereby get access
> to the XML body that way.
>
> 2) Create a new series of addCallMethod()'s which take an "int n" parameter.
> If n were equal to 0 then it would behave like it does now.  If n == 1 then
> it would execute the method on the next-to-top object on the stack and so on
> down the line.  Then you could still pass in a paramCount of zero or
> whatever.
>
> 3) A variation on #2 above.  Only change is to call the new series of
> addCallMethod()'s something different like addCallMethodN() or something so
> as to not make so many variations of addCallMethod.
>
> 4) Another more drastic alternative would be to have all callbacks accept as
> a first parameter the Digester and then still do #1 above.  That would break
> a lot of code but make somethings a lot easier like collaborating with other
> objects on the stack.  Hey...I'm only dreaming here.
>
> But after all this...there may be another way of doing what I need that I am
> just missing.  So any help would be appreciated.
>

#2 is probably the best of these approaches -- it generalizes the concept
of "walk up the stack before calling" the best.  #1 and #4 seem especially
kludgey, because Rule instances have access to the body text of the
current element (via the body() method getting called) already.

In the short term, I'd suggest just writing your own version of
CallMethodRule (either by subclassing or cut-n-paste) and add a
constructor that takes the extra argument.  You can use your custom
implementation by calling Digester.addRule(), even if it is not part of
the standard Digester suite of Rule implementations yet.

> Thanks,
> Brent
>

Craig


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

Reply via email to