commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henri Yandell (JIRA)" <j...@apache.org>
Subject [jira] Updated: (BEANUTILS-198) [beanutils] Copy bean properties with different names
Date Wed, 08 Nov 2006 01:42:53 GMT
     [ http://issues.apache.org/jira/browse/BEANUTILS-198?page=all ]

Henri Yandell updated BEANUTILS-198:
------------------------------------

      Bugzilla Id:   (was: 33109)
    Fix Version/s: LATER THAN 1.8.0

> [beanutils] Copy bean properties with different names
> -----------------------------------------------------
>
>                 Key: BEANUTILS-198
>                 URL: http://issues.apache.org/jira/browse/BEANUTILS-198
>             Project: Commons BeanUtils
>          Issue Type: Improvement
>          Components: Bean / Property Utils
>    Affects Versions: Nightly Builds
>         Environment: Operating System: All
> Platform: PC
>            Reporter: Rafael U. C. Afonso
>            Priority: Minor
>             Fix For: LATER THAN 1.8.0
>
>         Attachments: BeanFrom.java, BeanTo.java, CopyPropertiesWithDifferentNames.java
>
>
> In avaliable BeanUtils.copyProperties() implementation it is necessary that
> properties names of origin and destiny bean must be equals. My propose is
> include a overloading method in BeanUtils that receives - beyond destiny and
> origin beans - a two dimensional String array with two columns. This array will
> have name of properties to be copied - destiny property in first column, origin
> property in second column.  
> Code Implementation:
>     private static final int TO = 0;
>     private static final int FROM = 1;
>     /**<p>Copy property values from the origin bean to the destination bean 
>      * for cases where properties names are different. A bidimentional array 
>      * provides properties names: destiny bean properties in first column and
>      * origin bean properties in secon column. To be added to 
>      * org.apache.commons.beanutils.BeanUtils class.  
>      * 
>      * @param dest
>      * @param orig
>      * @param toFrom
>      * @throws IllegalAccessException
>      * @throws InvocationTargetException
>      * @throws NoSuchMethodException
>      */
>     public static void copyProperties(Object dest, Object orig,
>             String[][] toFrom) throws IllegalAccessException,
>             InvocationTargetException, NoSuchMethodException {
>         BeanUtilsBean beanUtilsBean = BeanUtilsBean.getInstance();
>         for (int i = 0; i < toFrom.length; i++) {
>             String[] strings = toFrom[i];
>             Object value = beanUtilsBean.getProperty(orig, strings[FROM]);
>             beanUtilsBean.setProperty(dest, strings[TO], value);
>         }
>     }
> Usage:
>         BeanFrom from = new BeanFrom(10, "my value"); // properties: keyFrom
> (int), valueFrom (String)
>         BeanTo to = new BeanTo(); // properties: keyTo (int), valueTo (String) 
>         String[][] table = { { "keyTo", "keyFrom" }, { "valueTo", "valueFrom" } };
>        copyProperties(b, a, table);

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

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


Mime
View raw message