On Mon, 2005-03-07 at 12:35 +1100, Mike Young wrote:
> Hi I am looking for some direction on how to convert a raw data array into
> a Java bean / Value Object.
> 
> I have a Java bean
> 
> public class PickValueVO extends ValueObject implements java.io.Serializable{
>     private String col1 = null;
>     private String col2 = null;
>     private String col3 = null;
> 
>    //getters & Setters
> }
> 
> I have a raw data array as an object[]
>     Object[] data = (Object[]) row.next();
> 
>         which might look like [row1_col2_data]
> 
> and I have a String Array which contains the corresponding property names
> of the java bean that the raw data represents.
> 
> String[] attrSubString
> 
>         which might look like [col2]
> 
> 
>  I would like to copy the contents of the raw array ([row1_col2_data])into
> the Java bean and end up with the data in property COL2 using reflection.
> 
> I think that the commons beanutils class will help me do this but am not
> sure how to go about it, any help would be greatly appreciated

I believe that you could put all your (propName, value) pairs into a Map
object then call
  BeanUtils.populate(destObject, srcMap);
or you could do
  for(int i=0; i<attrSubString.length; ++i) {
    BeanUtils.setProperty(destObject, attrSubString[i], data[i]);
  }

BTW, when posting to commons-user, please put the name of the component
you are discussing in the subject line (as this reply does).

Regards,

Simon


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to