commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <si...@ecnetwork.co.nz>
Subject Re: digester: can SetPropertyRule warn on not found properties?
Date Thu, 02 Sep 2004 22:24:00 GMT
Hi,

The reason that this feature isn't present in SetPropertiesRule is that
SetPropertiesRule just builds a map of (attrname,attrvalue) pairs then
calls BeanUtils.populate(...), and BeanUtils.populate doesn't support
reporting an error if a map entry has no matching setter method.

I think to add this you will need to modify the beanutils library. From
a brief look, BeanUtils.populate calls BeanUtils.setProperty for each
map entry, but BeanUtils.setProperty has this code:
           try {
                descriptor =
                    PropertyUtils.getPropertyDescriptor(target, name);
                if (descriptor == null) {
                    return; // Skip this property setter
                }
            } catch (NoSuchMethodException e) {
                return; // Skip this property setter
            }
So if no setter method is found, the property is just ignored.

NB: Robert, would you mind using bottom-posting instead of top-posting?
I wanted to comment on bits of both Gabriele's and your mail, but when
someone has already top-posted a reply it is hard to do that.

Cheers,

Simon


On Fri, 2004-09-03 at 06:34, robert burrell donkin wrote:
> the easiest way to achieve this would be to download the source and 
> then add a line or two that does that! you can then replace your 
> modified jar with the standard version when you're ready for 
> production.
> 
> - robert
> 
> On 2 Sep 2004, at 16:23, Gabriele Carcassi wrote:
> 
> > Hi,
> >
> > Is there a way to configure the SetPropertyRule to throw an exception, 
> > or to
> > alert me in some way, when a property set in the XML is not found in 
> > the
> > bean?
> >
> > This is typically useful when a user mispells the property for a bean 
> > whose
> > class is defined at runtime (thus I can't use schema). For example:
> > <building type="buildings.Sky" featerColor="yellow" />
> >
> > Do I have to create my rule or I am missing something?
> >
> > Thanks,
> > Gabriele
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 


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