You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Brian McCallister <mc...@forthillcompany.com> on 2003/08/05 22:45:06 UTC

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

So, some specific questions...

Can BeanUtils use a bean.get(String name) type accessor for a Bean?

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

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


Much appreciated!

-Brian


Re: BeanUtils Properties

Posted by "Craig R. McClanahan" <cr...@apache.org>.
On Tue, 5 Aug 2003, Brian McCallister wrote:

> Date: Tue, 5 Aug 2003 16:45:06 -0400
> From: Brian McCallister <mc...@forthillcompany.com>
> Reply-To: Jakarta Commons Users List <co...@jakarta.apache.org>
> To: Jakarta Commons Users List <co...@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