commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <>
Subject Re: [digester] setter methods named by element attributes values
Date Fri, 10 Feb 2006 05:16:21 GMT
On Thu, 2006-02-09 at 18:44 +0100, Valerio Schiavoni wrote:
> Hello,
> this is the input  xml:
> <website>
>   <pageclass>
>     <page>
>       <metadata name="title">the title</metadata>
>       <metadata name="content">the content</metadata>
>       <metadata name='someUknownName'>...</metadata>
>     </page>
>   </pageclass>
> </website>
> in the
> digester.addObjectCreate("website/pageclass/page",Notizia.class);
> And here comes comes the problems:
> --how to call notizia.setTitle("the title"); ?
> --how to call notizia.setContent("the content"); ?
> --how to call notizia.setUnknownValue("..."); ?

Unfortunately there is currently no built-in rule in Digester to do
this. It's listed as a to-do item:

Implementing this in a way that supports wildcard expressions (ie where
nested invocation of the rule instance is possible) is tricky which is
why it hasn't been done yet. 

However a simpler implementation of this rule should do in your case,
and *is* quite easy to write. Just create a custom Rule class, and in
the begin method save the value of the "name" attribute on the rule
instance. In the "body" method, use reflection to find the appropriate
method on the object on the top of the stack and invoke it; the
SetNextRule or CallMethodRule classes should be good examples.

Don't be concerned about writing a custom Rule class; it's quite
acceptable and not particularly difficult.



To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message