You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Christopher Schultz <ch...@christopherschultz.net> on 2021/02/16 20:31:58 UTC
[digester] Pass a static value to a CallParam rule?
All,
I'd like to invoke a method on the current top-of-the-stack object and
pass a static string value to it, like this:
digester.push(new MyBean());
digester.addCallMethod("/Foo/Bar", "setAttribute", 2, new Class<?>[] {
String.class });
digester.addCallParam("/Foo/Bar", 0, "MyStaticString");
digester.addCallParam("/Foo/Bar", 1, "attrName");
digester.parse(...);
When encountering /Foo/Bar, I'd like this to be called:
myBean.setAttribute("MyStaticString", [value of attribute "attrName"])
Is that kind of thing possible?
I thought I might pull a fast one and push the value "MyStaicString"
onto the stack and call:
digester.addCallParam("/Foo/Bar", 0, true);
But I it seems I can't push a value onto the stack when a specific path
is seen: only statically at some specific point (like before parsing
begins).
Thanks,
-chris
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: [digester] Pass a static value to a CallParam rule?
Posted by Christopher Schultz <ch...@christopherschultz.net>.
All,
On 2/16/21 15:31, Christopher Schultz wrote:
> All,
>
> I'd like to invoke a method on the current top-of-the-stack object and
> pass a static string value to it, like this:
>
>
> digester.push(new MyBean());
> digester.addCallMethod("/Foo/Bar", "setAttribute", 2, new Class<?>[] {
> String.class });
> digester.addCallParam("/Foo/Bar", 0, "MyStaticString");
> digester.addCallParam("/Foo/Bar", 1, "attrName");
> digester.parse(...);
>
> When encountering /Foo/Bar, I'd like this to be called:
>
> myBean.setAttribute("MyStaticString", [value of attribute "attrName"])
>
> Is that kind of thing possible?
>
> I thought I might pull a fast one and push the value "MyStaicString"
> onto the stack and call:
>
> digester.addCallParam("/Foo/Bar", 0, true);
>
> But I it seems I can't push a value onto the stack when a specific path
> is seen: only statically at some specific point (like before parsing
> begins).
Konstanin Kolinko in the Tomcat-user list pointed me toward:
digester.addObjectParam("/Foo/Bar", 0, "MyStaticString");
digester.addCallParam("/Foo/Bar", 1, "attrName");
This will accomplish what I'm trying to do.
Thanks!
-chris
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org