commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Strachan" <james_strac...@yahoo.co.uk>
Subject Re: [BeanUtils] PropertyUtils and DynaBeans (getPropertyDescriptors)
Date Wed, 17 Apr 2002 22:03:45 GMT
----- Original Message -----
From: "Stephen Colebourne" <scolebourne@eurobell.co.uk>
> From: Craig R. McClanahan <craigmcc@apache.org
> > > There
> > > doesn't seem to be any way to use the one.two[0].three(four) type
syntax
> > > however. Maybe this could be added.
> > >
> >
> > It's already there, but not in the DynaBeans themselves ... :-)
>
> This is what I was getting at. If DynaBeans were to become used as the
main
> interface (instead of PropertyUtils), then DynaBeans would need to support
> this notation.

I think DynaBeans is a great abstraction for DynaBeans and regular beans.
DynaBeans can handle

* regular properties via get(String name)
* indexed properties via get(String name, int index);
* mapped properties via get(String name, String key);

Where DynaBeans are maybe not the best abstraction right now is for complex
expressions like one.two[3].four(5).

I guess we could always change the get(String) and set(String, Object value)
methods of DynaBean that if the name doesn't match a well defined property
to call the PropertyUtils method to evaluate the expression? I'm not sure
I'm convinced this is a good idea yet but its certainly possible.

Though maybe for complex expressions we should use either the existing
PropertyUtils API for this or some expression API explicitly. Stuff like
these complex expressions might deserve a different API, maybe that allows
expressions to be 'compiled' first then reused many times to avoid excessive
parsing of the exception.

e.g.

Expression expression = new Expression( "one.two[3].four(5)" );
for ( int i = 0; i < 20; i++ ) {
    expression.evaluate( array[i] );
}


> This could be done either by adding to the DynaBean interface:
> getNested(String)
> setNested(String, Object)
> or by changing the javadoc and implementation of get(String) and
set(String,
> Object)
>
> Any views on the better approach?

Its tempting. It would be nice to have a consistent, simple, clean API like
DynaBeans to handle all these cases.

Though I'd be happy to use DynaBeans for all 'simple' cases, bean
properties, indexed & mapped properties and DynaBeans, then use another API
for 'complex' expressions.


> > The property getter/setter methods in PropertyUtils and BeanUtils work
on
> > either standard JavaBeans or on DynaBeans, so you can use the exact same
> > property syntax on them.
>
> Thus implementation should be easy ;-)

Agreed.

James


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message