*/
public Object getValue(String xpath, Expression expr) {
Object result = expr.computeValue(getEvalContext());
if (result == null) {
if (expr instanceof Path && !isLenient()) {
throw new JXPathNotFoundException("No value for xpath: "
+ xpath);
}
return null;
}
if (result instanceof EvalContext) {
EvalContext ctx = (EvalContext) result;
result = ctx.getSingleNodePointer();
if (!isLenient() && result == null) {
throw new JXPathNotFoundException("No value for xpath: "
+ xpath);
}
}
if (result instanceof NodePointer) {
result = ((NodePointer) result).getValuePointer();
if (!isLenient() && !((NodePointer) result).isActual()) {
// We need to differentiate between pointers representing
// a non-existing property and ones representing a property
// whose value is null. In the latter case, the pointer
// is going to have isActual == false, but its parent,
// which is a non-node pointer identifying the bean property,
// will return isActual() == true.
NodePointer parent =
((NodePointer) result).getImmediateParentPointer();
if (parent == null
|| !parent.isContainer()
|| !parent.isActual()) {
throw new JXPathNotFoundException("No value for xpath: "
+ xpath);
}
}
result = ((NodePointer) result).getValue();
}