You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Norbert Krömeke <N....@actosoft.de> on 2003/05/16 08:24:29 UTC

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

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.

Regards,

Norbert


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


> On Fri, 2003-05-16 at 17:22, Norbert Krömeke wrote:
> > Hi,
> >
> > I'm looking for the solution to resolve fallowing problem. The XML input
> > looks like this :
> >
> > ...
> > <parameters>
> >    <track1>1234567</track1>
> >    <track2>666666666</track2>
> >    ....
> >    <tag-name>tag-body</tag-name>
> > </parameters>
> >
> > I want to use only one function to collect all this 'sub-tags' from <parameters> by
> > call of addParam(tag-name, tag-body).
> >
> > How can I do it if I use digester-rules.dtd file.
>
> I've not done this myself, so the following is just a guess.
>
> I think you'll first have to use "ExtendedBaseRules" rather than the
> default "RulesBase" class as the pattern-matching engine, so that you
> can use patterns with trailing wildcards.
>
> I don't know if the XmlRules stuff allows you to do this from an xml
> config file, but it is easy to do in code:
>   digester.setRules(new ExtendedBaseRules());
>
> You should then be able to add a CallMethodRule triggered by the pattern
> "parameters/*".
>
> Regards,
>
> Simon
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>


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
>
>


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

Posted by Simon Kitching <si...@ecnetwork.co.nz>.
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