Sorry Frank, but I don't think you have to worry about casting at all. Say
you've collected all your values into a List (myList), as Thomas suggested -
then all you need to do is something like the following:

Class type = PropertyUtils.getPropertyType(obj, "myArray");

// Array Processing
if (type.isArray()) {

    Class componentType = type.getComponentType();

    // Create new instance of the array
    Object myArray = Array.newInstance(componentType, myList.size());

    // Get the converter
    Converter converter = ConvertUtils.lookup(componentType);

    // populate array values
    for (int i = 0; i < myList.size(); i++) {

        // Get & Convert the value
        Object value = converter.convert(componentType,  myList.get(i));

        // Set the value in the array
        Array.set(myArray, i, value);

    }

    // set the beans property
    BeanUtils.setProperty(obj, "myArray", myArray);

} else {

    // ? handle error ?

}

----- Original Message ----- 
From: "Frank W. Zammetti" <[EMAIL PROTECTED]>
Sent: Thursday, September 08, 2005 4:33 AM

<snip>
> Yep, knew about these already... unfortunately, the one thing that would
> make this a piece of cake is not available here, or in Java t all:
> dynamic casting.  If you could do that, it would be trivial to do
> something like:
>
> Class type = PropertyUtils.getPropertyType(obj, "myArray");
> Object v = Array.newInstance(type, values.size());
> BeanUtils.setProperty(obj, "myArray", values.toArray((type.getName())v));

>
> That still assumes that getName() returned the type in a useable form,
> which of course it doesn't anyway (which complicates my above if block,
> but I digress), so my pipe dream is even more so :)
</snip>



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

Reply via email to