commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <skitch...@apache.org>
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 DigesterReader.java:
> 
> 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:
  http://wiki.apache.org/jakarta-commons/Digester/TODO

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.

Regards,

Simon




---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message