in src/main/java/org/apache/commons/jxpath/ri/axes/SimplePathInterpreter.java [222:280]
private static NodePointer doPredicateName(final EvalContext context, final NodePointer parent, final Step[] steps, final int currentStep,
final Expression[] predicates, final int currentPredicate) {
final Expression predicate = predicates[currentPredicate];
final String key = keyFromPredicate(context, predicate);
NodePointer child = valuePointer(parent);
if (child instanceof PropertyOwnerPointer) {
final PropertyPointer pointer = ((PropertyOwnerPointer) child).getPropertyPointer();
pointer.setPropertyName(key);
if (pointer.isActual()) {
return doPredicate(context, pointer, steps, currentStep, predicates, currentPredicate + 1);
}
} else if (child.isCollection()) {
// For each node in the collection, perform the following:
// if the node is a property owner, apply this predicate to it;
// if the node is a collection, apply this predicate to each elem.;
// if the node is not a prop owner or a collection,
// see if it has the attribute "name" with the right value,
// if so - proceed to the next predicate
NodePointer bestMatch = null;
int bestQuality = 0;
child = (NodePointer) child.clone();
final int count = child.getLength();
for (int i = 0; i < count; i++) {
child.setIndex(i);
final NodePointer valuePointer = valuePointer(child);
NodePointer pointer;
if (valuePointer instanceof PropertyOwnerPointer || valuePointer.isCollection()) {
pointer = doPredicateName(context, valuePointer, steps, currentStep, predicates, currentPredicate);
} else if (isNameAttributeEqual(valuePointer, key)) {
pointer = doPredicate(context, valuePointer, steps, currentStep, predicates, currentPredicate + 1);
} else {
pointer = null;
}
if (pointer != null) {
final int quality = computeQuality(pointer);
if (quality == PERFECT_MATCH) {
return pointer;
}
if (quality > bestQuality) {
bestMatch = (NodePointer) pointer.clone();
bestQuality = quality;
}
}
}
if (bestMatch != null) {
return bestMatch;
}
} else {
// If the node is a standard InfoSet node (e.g. DOM Node),
// employ doPredicates_standard, which will iterate through
// the node's children and apply all predicates
final NodePointer found = doPredicatesStandard(context, Collections.singletonList(child), steps, currentStep, predicates, currentPredicate);
if (found != null) {
return found;
}
}
// If nothing worked - return a null pointer
return createNullPointerForPredicates(context, child, steps, currentStep, predicates, currentPredicate);
}