You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Simon Kitching <si...@ecnetwork.co.nz> on 2003/05/19 01:19:09 UTC

Re: [digester]: Is there a way to populate bean tags by only onecall

On Fri, 2003-05-16 at 18:24, Norbert Krömeke wrote:
> Hi Simon,
> 
> Thanks for your answer, but haw can I put the "tag-name" and "tag-body" to
> my function "addParam" ?
> 
> Have I any possibility to extract the "tag-name" if I use "<call-param-rule>"?
> Sorry for this naive question, but I am still beginner in this stuff.

Hmm..missed that point.

I think unfortunately you are right; there is no way to pass the tag
name as a parameter when using CallMethodRule/CallParamRule.

It looks like a custom rule would be needed to do what you wish. Writing
a custom Rule isn't too complicated, but as you are using xml rules, you
will also need to write the xml "glue" stuff.


Note Craig's email which suggested an alternative approach: replace your
"setParam(String attrName, String attrValue)" method with a separate
method to set each attribute:
  setTrack1(String value) {...}
  setTrack2(Strign value) {...}
This would be more java-bean-like. I think you could then use the
BeanPropertySetterRule something like this:
  <bean-property-setter pattern="parameters/*"/>
which would match a <track1>foo</track1> tag inside a parameters tag,
and would then invoke
  setTrack1("foo");

======================

Robert, what do you think about the idea of enhancing CallParamRule so
that the tag name can be passed as a parameter to an invoked method?

Another question for you, Robert: I thought that a feature was addded
fairly recently to make it possible to use CallParamRule to pass an
arbitrary object to a method. However, I can't find that functionality.
This could be used in Norbert's case to at least pass the tag name into
a target method, as follows:
  <call-param-rule 
    pattern="parameters/foo" 
    object="foo" 
    paramcount="0"/>
to pass the literal string "foo" as the 0th parameter. If this
functionality doesn't exist, then what do you think about the idea of
adding this too??


Regards,

Simon




Re: [digester]: Is there a way to populate bean tags by onlyonecall

Posted by Norbert Krömeke <N....@actosoft.de>.
Hi Simon,

yes you are right, the solution from Craig is not this what I need. It's
the normal way to set the property, but than I have to write for each possible "sub-tag"
of <parameters> special "set" function.

While the factory class have to decide about final created object using DB configuration,
the way with only one function "addParam" from the base class is mutch universal.

OK, thank you very much,
also to Craig

Regards,

Norbert

----- Original Message -----
From: "Simon Kitching" <si...@ecnetwork.co.nz>
To: "Jakarta Commons Users List" <co...@jakarta.apache.org>
Sent: Monday, May 19, 2003 1:19 AM
Subject: Re: [digester]: Is there a way to populate bean tags by onlyonecall


> On Fri, 2003-05-16 at 18:24, Norbert Krömeke wrote:
> > Hi Simon,
> >
> > Thanks for your answer, but haw can I put the "tag-name" and "tag-body" to
> > my function "addParam" ?
> >
> > Have I any possibility to extract the "tag-name" if I use "<call-param-rule>"?
> > Sorry for this naive question, but I am still beginner in this stuff.
>
> Hmm..missed that point.
>
> I think unfortunately you are right; there is no way to pass the tag
> name as a parameter when using CallMethodRule/CallParamRule.
>
> It looks like a custom rule would be needed to do what you wish. Writing
> a custom Rule isn't too complicated, but as you are using xml rules, you
> will also need to write the xml "glue" stuff.
>
>
> Note Craig's email which suggested an alternative approach: replace your
> "setParam(String attrName, String attrValue)" method with a separate
> method to set each attribute:
>   setTrack1(String value) {...}
>   setTrack2(Strign value) {...}
> This would be more java-bean-like. I think you could then use the
> BeanPropertySetterRule something like this:
>   <bean-property-setter pattern="parameters/*"/>
> which would match a <track1>foo</track1> tag inside a parameters tag,
> and would then invoke
>   setTrack1("foo");
>
> ======================
>
> Robert, what do you think about the idea of enhancing CallParamRule so
> that the tag name can be passed as a parameter to an invoked method?
>
> Another question for you, Robert: I thought that a feature was addded
> fairly recently to make it possible to use CallParamRule to pass an
> arbitrary object to a method. However, I can't find that functionality.
> This could be used in Norbert's case to at least pass the tag name into
> a target method, as follows:
>   <call-param-rule
>     pattern="parameters/foo"
>     object="foo"
>     paramcount="0"/>
> to pass the literal string "foo" as the 0th parameter. If this
> functionality doesn't exist, then what do you think about the idea of
> adding this too??
>
>
> Regards,
>
> Simon
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>