{
getAndSetter = new FieldGetAndSetter(field);
}
else
{
throw new WicketRuntimeException(
"The expression '" +
exp +
"' is neither an index nor is it a method or field for the list " +
clz);
}
}
}
}
else if (Map.class.isAssignableFrom(clz))
{
getAndSetter = new MapGetSet(exp);
}
else if (clz.isArray())
{
try
{
int index = Integer.parseInt(exp);
getAndSetter = new ArrayGetSet(clz.getComponentType(), index);
}
catch (NumberFormatException ex)
{
if (exp.equals("length") || exp.equals("size"))
{
getAndSetter = new ArrayLengthGetSet();
}
else
{
throw new WicketRuntimeException("Can't parse the expression '" + exp +
"' as an index for an array lookup");
}
}
}
else
{
field = findField(clz, exp);
if (field == null)
{
method = findMethod(clz, exp);
if (method == null)
{
int index = exp.indexOf('.');
if (index != -1)
{
String propertyName = exp.substring(0, index);
String propertyIndex = exp.substring(index + 1);
try
{
int parsedIndex = Integer.parseInt(propertyIndex);
// if so then it could be a getPropertyIndex(int)
// and setPropertyIndex(int, object)
String name = Character.toUpperCase(propertyName.charAt(0)) +
propertyName.substring(1);
method = clz.getMethod(GET + name, new Class[] { int.class });
getAndSetter = new ArrayPropertyGetSet(method, parsedIndex);
}
catch (Exception e)
{
throw new WicketRuntimeException(
"No get method defined for class: " + clz +
" expression: " + propertyName);
}
}
else
{
// We do not look for a public FIELD because
// that is not good programming with beans patterns
throw new WicketRuntimeException(
"No get method defined for class: " + clz + " expression: " +
exp);
}
}
else