commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject Re: BeanUtils Properties
Date Sun, 17 Aug 2003 02:18:18 GMT
On Tue, 5 Aug 2003, Brian McCallister wrote:

> Date: Tue, 5 Aug 2003 16:45:06 -0400
> From: Brian McCallister <mccallister@forthillcompany.com>
> Reply-To: Jakarta Commons Users List <commons-user@jakarta.apache.org>
> To: Jakarta Commons Users List <commons-user@jakarta.apache.org>
> Subject: BeanUtils Properties
>
> Can anyone provide a quick answer on the methods BeanUtils uses to find
> properties? I am not particularly fluent in the JavaBeans specification
> (java.beans.* stuff).
>

The main introspection class is java.beans.Introspector.

> So, some specific questions...
>
> Can BeanUtils use a bean.get(String name) type accessor for a Bean?
>

If the bean in question is a DynaBean (that is, it implements the
org.apache.commons.beanutils.DynaBean interface), then the answer is yes.

> If so, how do I tell it to look for it? (copyProperties() / populate()
> behavior being of particular interest)
>

Inside BeanUtils (and PropertyUtils) there are instanceof checks for
DynaBean, so you don't have to do anything special.

> Does BeanUtils respect nested properties on both sides of a
> copyProperties() / populate() (ie, copy object graphs)
>

The copyProperties() method is shallow, but if the property type is an
object that is the root of a tree of objects, then the destination
property will end up pointing at the same tree.  The nested structures are
not cloned.

The populate() method accepts expressions ("foo.bar") in the keys of the
map, and calls the corresponding property setter on the destination bean,
which might navigate down into the tree hierarchy before setting.

>
> Much appreciated!
>
> -Brian

Craig

Mime
View raw message