On Mon, 20 Aug 2001, robert burrell donkin wrote:

> On Monday, August 20, 2001, at 06:37 PM, Craig R. McClanahan wrote:
> 
> > On Mon, 20 Aug 2001, robert burrell donkin wrote:
> 
> <snip>
> 
> >> the good thing is that digester is extensible and one easy way round this
> >> problem would be to create a rule that allowed a property with a 
> >> different
> >> name (from the attribute) to be set. if this is what you need, i can easy
> >> and quickly produce a new rule to do just this.
> >>
> >
> > Actually, you don't even need a new rule -- just a BeanInfo class for your
> > bean that does the appropriate mapping.  BeanUtils (which is used
> > underneath) follows standard Java introspection mechanisms - it does not
> > assume that the setter for method foo is always named setFoo().
> >
> 
> i assumed that jason (hopefully he'll will correct me if i'm wrong) was 
> trying to set - say - the 'rubbish' property from the 'trash' attribute. 
> (this is reasonably common for xml->object mapping since xml-attributes 
> and java method names have different naming rules.)
> 
> if there is a neat way to do this mapping using beanutils without write 
> new code then that'd be cool (any chance of a pointer?) but otherwise i'm 
> pretty keen to create a rule (or modify an existing rule, if that's better)
>   since i'm going to run into the same problem pretty soon.
> 

The JavaBeans spec talks about BeanInfo and friends:

  http://java.sun.com/products/javabeans/docs/spec.html

Basically, if you provide a BeanInfo class for your bean, it is up to
*you* to return the array of PropertyDescriptor objects describing the
properties of your underlying bean (by default, the introspector uses the
naming patterns to figure this out).  And, inside your PropertyDescriptor,
the Method objects used for getters and setters can be named anything you
like.

You still have to write new code (i.e. a BeanInfo class), but you don't
have to write a new Rules implementation in Digester for it.  Further, if
you use this bean in other environments that do standard Java
introspection (for example JSP pages), you can reuse the BeanInfo stuff
there as well.

> - robert
> 

Craig


Reply via email to