for (SequenceIterator nodesIter = args[1].iterate(); nodesIter.hasNext(); ) {
NodeValue nv = (NodeValue) nodesIter.nextItem();
if (nv.getImplementationType() == NodeValue.IN_MEMORY_NODE)
throw new XPathException(this, "Cannot create order-index on an in-memory node");
NodeProxy node = (NodeProxy) nv;
SortItem si = new SortItemImpl(node);
if (LOG.isDebugEnabled() && ++c % logChunk == 0) {
LOG.debug("Storing item " + c + " out of " + len + " to sort index.");
}
if (call != null) {
// call the callback function to get value
params[0] = node;
Sequence r = call.evalFunction(contextSequence, null, params);
if (!r.isEmpty()) {
AtomicValue v = r.itemAt(0).atomize();
if (v.getType() == Type.UNTYPED_ATOMIC)
v = v.convertTo(Type.STRING);
si.setValue(v);
}
} else {
// no callback, take value from second sequence
AtomicValue v = valuesIter.nextItem().atomize();
if (v.getType() == Type.UNTYPED_ATOMIC)
v = v.convertTo(Type.STRING);
si.setValue(v);
}
items.add(si);
}
// sort the set
FastQSort.sort(items, 0, items.size() - 1);