Expression[] predicates, int currentPredicate) {
Expression predicate = predicates[currentPredicate];
String key = keyFromPredicate(context, predicate);
NodePointer child = valuePointer(parent);
if (child instanceof PropertyOwnerPointer) {
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();
int count = child.getLength();
for (int i = 0; i < count; i++) {
child.setIndex(i);
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) {
int quality = computeQuality(pointer);
if (quality == PERFECT_MATCH) {
return pointer;
}
if (quality > bestQuality) {
bestMatch = (NodePointer) pointer.clone();
bestQuality = quality;
}
}
}
if (bestMatch != null) {