[OT] Push a static value into digester's CallMethod rule?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[OT] Push a static value into digester's CallMethod rule?

Christopher Schultz-2
All,

I asked this over on the commons-user list yesterday but haven't gotten
a response. Since the digester was born here, maybe someone knows the
answer to this. I'd be happy to get a response over on commons-user or
here. I'll reply to my own thread if someone replies here, citing it.

:::

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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [OT] Push a static value into digester's CallMethod rule?

Konstantin Kolinko
ср, 17 февр. 2021 г. в 20:13, Christopher Schultz
<[hidden email]>:

>
> All,
>
> I asked this over on the commons-user list yesterday but haven't gotten
> a response. Since the digester was born here, maybe someone knows the
> answer to this. I'd be happy to get a response over on commons-user or
> here. I'll reply to my own thread if someone replies here, citing it.
>
> :::
>
> 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).

You have not said what version you are using.

Looking at Apache Commons Digester 3.2 source code and
searching for "peekParams()" calls (the API used to access the list of
parameters created by CallMethodRule):

1. I see that there exists a ObjectParamRule class that allows
injecting arbitrary values as parameters for the call. It is
documented as "@since 1.4".

2. There exists a Digester.addObjectParam() method. It is "@since 1.6".

HTH

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [OT] Push a static value into digester's CallMethod rule?

Christopher Schultz-2
Konstantin,

On 2/17/21 14:06, Konstantin Kolinko wrote:

> ср, 17 февр. 2021 г. в 20:13, Christopher Schultz
> <[hidden email]>:
>>
>> All,
>>
>> I asked this over on the commons-user list yesterday but haven't gotten
>> a response. Since the digester was born here, maybe someone knows the
>> answer to this. I'd be happy to get a response over on commons-user or
>> here. I'll reply to my own thread if someone replies here, citing it.
>>
>> :::
>>
>> 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).
>
> You have not said what version you are using.

You are absolutely right. My apologies. My version of commons-digester
is 3.2.

> Looking at Apache Commons Digester 3.2 source code and
> searching for "peekParams()" calls (the API used to access the list of
> parameters created by CallMethodRule):
>
> 1. I see that there exists a ObjectParamRule class that allows
> injecting arbitrary values as parameters for the call. It is
> documented as "@since 1.4".
>
> 2. There exists a Digester.addObjectParam() method. It is "@since 1.6".

Awesome. That's exactly what I was looking for.

Thanks!
-chris

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]