}
@SuppressWarnings("unchecked")
public <T> T getNodeValue(Object o, Node node) {
Object current = o;
Node currentNode = node;
while (currentNode != null) {
if (current == null) {
return null;
}
String currentName = currentNode.getLabel();
boolean mapEqIsProcessed = false;
logger.trace(getProcessingMessagePrefix() + "Processing " + currentName);
boolean ok = false;
if (!ok) {
Method m = GwtReflectionUtils.getMethod(current.getClass(), currentName);
if (m == null) {
m = GwtReflectionUtils.getMethod(current.getClass(), "get" + currentName);
}
if (m != null) {
try {
if (m.getParameterTypes().length == 0 || currentNode.getParams() != null) {
current = invoke(current, m, currentNode.getParams());
ok = true;
} else {
current = findInList(current, m, currentNode.getMapEq(), currentNode.getMap());
mapEqIsProcessed = true;
ok = true;
}
} catch (Exception e) {
logger.error(getAssertionErrorMessagePrefix() + "Execution error", e);
fail(getAssertionErrorMessagePrefix() + "Unable to get method result on "
+ o.getClass().getCanonicalName() + ", method " + m.getName()
+ ", params " + currentNode.getParams());
}
}
}
if (!ok) {
Field f = getField(current, current.getClass(), currentName);
if (f != null) {
try {
current = f.get(current);
ok = true;
} catch (Exception e) {
logger.error(getAssertionErrorMessagePrefix() + "Execution error", e);
fail(getAssertionErrorMessagePrefix() + "Unable to get field value on "
+ o.getClass().getCanonicalName() + ", field " + f.getName()
+ ", params " + node);
}
}
}
if (ok && currentNode.getMap() != null) {
if (currentNode.getMapEq() == null) {
current = proccessMap(current, currentNode.getMap());
} else {
if (!mapEqIsProcessed) {
if (current instanceof Iterable<?>) {
Iterable<Object> list = (Iterable<Object>) current;
current = findInIterable(list, currentNode.getMapEq(), currentNode.getMap(),
current, null);
} else {
fail(getAssertionErrorMessagePrefix() + "Not managed type for iteration "
+ current.getClass().getCanonicalName());
}
}
}
}
if (!ok) {
return null;
}
currentNode = currentNode.getNext();
}
return (T) current;
}