in src/main/java/org/apache/commons/jxpath/ri/compiler/ExpressionPath.java [150:196]
protected Object expressionPath(final EvalContext evalContext, final boolean firstMatch) {
final Object value = expression.compute(evalContext);
EvalContext context;
if (value instanceof InitialContext) {
// This is an optimization. We can avoid iterating through a
// collection if the context bean is in fact one.
context = (InitialContext) value;
}
else if (value instanceof EvalContext) {
// UnionContext will collect all values from the "value" context
// and treat the whole thing as a big collection.
context =
new UnionContext(
evalContext,
new EvalContext[] {(EvalContext) value });
}
else {
context = evalContext.getRootContext().getConstantContext(value);
}
if (firstMatch
&& isSimpleExpressionPath()
&& !(context instanceof NodeSetContext)) {
final EvalContext ctx = context;
final NodePointer ptr = (NodePointer) ctx.getSingleNodePointer();
if (ptr != null
&& (ptr.getIndex() == NodePointer.WHOLE_COLLECTION
|| predicates == null
|| predicates.length == 0)) {
return SimplePathInterpreter.interpretSimpleExpressionPath(
evalContext,
ptr,
predicates,
getSteps());
}
}
if (predicates != null) {
for (int j = 0; j < predicates.length; j++) {
if (j != 0) {
context = new UnionContext(context, new EvalContext[]{context});
}
context = new PredicateContext(context, predicates[j]);
}
}
return firstMatch ? (Object) getSingleNodePointerForSteps(context)
: evalSteps(context);
}