in wicket-core/src/main/java/org/apache/wicket/core/util/lang/PropertyResolver.java [272:355]
private static ObjectWithGetAndSet getObjectWithGetAndSet(final String expression, final Object object, final int tryToCreateNull, Class<?> clz)
{
String expressionBracketsSeperated = Strings.replaceAll(expression, "[", ".[").toString();
int index = getNextDotIndex(expressionBracketsSeperated, 0);
while (index == 0 && expressionBracketsSeperated.startsWith("."))
{
// eat dots at the beginning of the expression since they will confuse
// later steps
expressionBracketsSeperated = expressionBracketsSeperated.substring(1);
index = getNextDotIndex(expressionBracketsSeperated, 0);
}
int lastIndex = 0;
Object value = object;
String exp = expressionBracketsSeperated;
while (index != -1)
{
exp = expressionBracketsSeperated.substring(lastIndex, index);
if (exp.length() == 0)
{
exp = expressionBracketsSeperated.substring(index + 1);
break;
}
IGetAndSet getAndSet;
try
{
getAndSet = getGetAndSet(exp, clz);
}
catch (WicketRuntimeException ex)
{
// expression by itself can't be found. try combined with the following
// expression (e.g. for a indexed property);
int temp = getNextDotIndex(expressionBracketsSeperated, index + 1);
if (temp == -1)
{
exp = expressionBracketsSeperated.substring(lastIndex);
break;
} else {
index = temp;
continue;
}
}
Object nextValue = null;
if (value != null)
{
nextValue = getAndSet.getValue(value);
}
if (nextValue == null)
{
if (tryToCreateNull == CREATE_NEW_VALUE)
{
nextValue = getAndSet.newValue(value);
if (nextValue == null)
{
return null;
}
}
else if (tryToCreateNull == RESOLVE_CLASS)
{
clz = getAndSet.getTargetClass();
}
else
{
return null;
}
}
value = nextValue;
if (value != null)
{
// value can be null if we are in the RESOLVE_CLASS
clz = value.getClass();
}
lastIndex = index + 1;
index = getNextDotIndex(expressionBracketsSeperated, lastIndex);
if (index == -1)
{
exp = expressionBracketsSeperated.substring(lastIndex);
break;
}
}
IGetAndSet getAndSet = getGetAndSet(exp, clz);
return new ObjectWithGetAndSet(getAndSet, value);
}