public Class getType(Object base, int index)
{
if (base == null)
{
throw new PropertyNotFoundException("Bean is null");
}
try
{
if (base.getClass().isArray())
{
if (base instanceof Object[]) {
Object[] array = (Object[]) base;
return array[index].getClass().getComponentType();
} else {
return base.getClass().getComponentType();
}
}
if (base instanceof List)
{
// REVISIT: does it make sense to do this or simply return
// Object.class? What if the new value is not of
// the old value's class?
Object value = ((List) base).get(index);
// REVISIT: when generics are implemented in JVM 1.5
return (value != null) ? value.getClass() : Object.class;
}
// Cannot determine type, return null per JSF spec
return null;
}
catch (IndexOutOfBoundsException e) {
throw new PropertyNotFoundException("Bean: "
+ base.getClass().getName() + ", index " + index, e);
}
catch (Exception e)
{
throw new EvaluationException("Exception getting type of index " + index + " of bean "