You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Benedikt Ritter <be...@systemoutprintln.de> on 2012/02/12 12:28:05 UTC

[SANDBOX][BeanUtils2] Discussion about cloneBean(), copyProperties() and cast() on DefaultBeanAccessor

Hi,

now that we have implemented describe() and populate() on 
DefaultBeanAccessor, cloneBean() and copyProperties(T target) seem very 
easy to implement. I would realize cloneBean() simply like:

public B cloneBean()
     throws aLotOfExceptions ;-)
{
     @SuppressWarnings( "unchecked" )
     B clone = (B) bean.getClass().newInstance();
     DefaultBeanAccessor<B> cloneAccessor = new DefaultBeanAccessor<B>( 
clone );
     cloneAccessor.populate( this.describe() );
     return clone;
}

copyProperties() can be implemented likewise. Is that really all we have 
to do, or am I missing something? I've looked at BeanUtils1 and they are 
handling Maps a little differently by coping all entries. So I guess we 
have to do the same (to keep the user experience).

Another thing I was winking about is cast(). I don't understand how that 
is supposed to work. Can it be, that there is an input parameter 
missing? To make it work it has to be:

public <V> V cast(Class<V> targetType);

Tell me what you think and I'll start implementing the missing methods.

Regards,
Benedikt

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


Re: [SANDBOX][BeanUtils2] Discussion about cloneBean(), copyProperties() and cast() on DefaultBeanAccessor

Posted by James Carman <jc...@carmanconsulting.com>.
If we jump to java 7, we can clean up our exceptions by using
ReflectiveOperationException.

Sent from tablet device.  Please excuse typos and brevity.
On Feb 12, 2012 6:28 AM, "Benedikt Ritter" <be...@systemoutprintln.de> wrote:

> Hi,
>
> now that we have implemented describe() and populate() on
> DefaultBeanAccessor, cloneBean() and copyProperties(T target) seem very
> easy to implement. I would realize cloneBean() simply like:
>
> public B cloneBean()
>    throws aLotOfExceptions ;-)
> {
>    @SuppressWarnings( "unchecked" )
>    B clone = (B) bean.getClass().newInstance();
>    DefaultBeanAccessor<B> cloneAccessor = new DefaultBeanAccessor<B>(
> clone );
>    cloneAccessor.populate( this.describe() );
>    return clone;
> }
>
> copyProperties() can be implemented likewise. Is that really all we have
> to do, or am I missing something? I've looked at BeanUtils1 and they are
> handling Maps a little differently by coping all entries. So I guess we
> have to do the same (to keep the user experience).
>
> Another thing I was winking about is cast(). I don't understand how that
> is supposed to work. Can it be, that there is an input parameter missing?
> To make it work it has to be:
>
> public <V> V cast(Class<V> targetType);
>
> Tell me what you think and I'll start implementing the missing methods.
>
> Regards,
> Benedikt
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: dev-unsubscribe@commons.**apache.org<de...@commons.apache.org>
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

Re: [SANDBOX][BeanUtils2] Discussion about cloneBean(), copyProperties() and cast() on DefaultBeanAccessor

Posted by Simone Tripodi <si...@apache.org>.
Hi Bene,

>
>
> yes I did (as I said ;-). So I guess, that we can implement it the way I
> said, but make sure Maps will be handled the way they were in BeanUtils1.
>

that would be acceptable since users are already used to that behavior

>
> Any thoughts about what James suggested? Just having to declare
> ReflectiveOperationException would be nice to clean up the interface. But I
> guess few people are already on Java 7. So better stay at Java 6?
>

I'm for keeping at least JDK6 compatibility

-Simo

http://people.apache.org/~simonetripodi/
http://simonetripodi.livejournal.com/
http://twitter.com/simonetripodi
http://www.99soft.org/

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


Re: [SANDBOX][BeanUtils2] Discussion about cloneBean(), copyProperties() and cast() on DefaultBeanAccessor

Posted by Benedikt Ritter <be...@systemoutprintln.de>.
Am 12.02.2012 18:28, schrieb Simone Tripodi:
> Hi Bene,
>

Hi!

>>
>> [...]
>>
>> copyProperties() can be implemented likewise. Is that really all we have to
>> do, or am I missing something? I've looked at BeanUtils1 and they are
>> handling Maps a little differently by coping all entries. So I guess we have
>> to do the same (to keep the user experience).
>>
>
> did you already check older BeanUtils?

yes I did (as I said ;-). So I guess, that we can implement it the way I 
said, but make sure Maps will be handled the way they were in BeanUtils1.

>
>> Another thing I was winking about is cast(). I don't understand how that is
>> supposed to work. Can it be, that there is an input parameter missing? To
>> make it work it has to be:
>>
>> public<V>  V cast(Class<V>  targetType);
>>
>
> no, it doesn't "has to be", even if a little weird it doesn't require
> the Class type. Have a look at[1] a give a try please with current
> codebase ;)

Ah, okay... :) I've the latest code base checked out. So that can stay 
the way it is.

Any thoughts about what James suggested? Just having to declare 
ReflectiveOperationException would be nice to clean up the interface. 
But I guess few people are already on Java 7. So better stay at Java 6?

Ciao!
Benedikt

>
> Alles gute,
> -Simo
>
> [1] http://stackoverflow.com/questions/338887/java-generics-generic-type-defined-as-return-type-only
>
> http://people.apache.org/~simonetripodi/
> http://simonetripodi.livejournal.com/
> http://twitter.com/simonetripodi
> http://www.99soft.org/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org


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


Re: [SANDBOX][BeanUtils2] Discussion about cloneBean(), copyProperties() and cast() on DefaultBeanAccessor

Posted by Simone Tripodi <si...@apache.org>.
Hi Bene,

>
> public B cloneBean()
>    throws aLotOfExceptions ;-)
> {
>    @SuppressWarnings( "unchecked" )
>    B clone = (B) bean.getClass().newInstance();
>    DefaultBeanAccessor<B> cloneAccessor = new DefaultBeanAccessor<B>( clone
> );
>    cloneAccessor.populate( this.describe() );
>    return clone;
> }
>
> copyProperties() can be implemented likewise. Is that really all we have to
> do, or am I missing something? I've looked at BeanUtils1 and they are
> handling Maps a little differently by coping all entries. So I guess we have
> to do the same (to keep the user experience).
>

did you already check older BeanUtils?

> Another thing I was winking about is cast(). I don't understand how that is
> supposed to work. Can it be, that there is an input parameter missing? To
> make it work it has to be:
>
> public <V> V cast(Class<V> targetType);
>

no, it doesn't "has to be", even if a little weird it doesn't require
the Class type. Have a look at[1] a give a try please with current
codebase ;)

Alles gute,
-Simo

[1] http://stackoverflow.com/questions/338887/java-generics-generic-type-defined-as-return-type-only

http://people.apache.org/~simonetripodi/
http://simonetripodi.livejournal.com/
http://twitter.com/simonetripodi
http://www.99soft.org/

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