// This class delivers the result of the path expression in unsorted order,
// without removal of duplicates. If sorting and deduplication are needed,
// this is achieved by wrapping the path expression in a DocumentSorter
SequenceIterator result = start.iterate(context);
XPathContext context2 = context.newMinorContext();
context2.setCurrentIterator(result);
context2.setOrigin(this);
context2.setOriginatingConstructType(Location.PATH_EXPRESSION);
result = new ContextMappingIterator(this, context2);
// Peek at the first item, and depending on its type, check that all the items
// are atomic values or that all are nodes.
final SourceLocator loc = this;
Item first = result.next();
if (first == null) {
return EmptyIterator.getInstance();
} else if (first instanceof AtomicValue) {
ItemMappingFunction atomicValueChecker = new ItemMappingFunction() {
public Item map(Item item) throws XPathException {
if (item instanceof AtomicValue) {
return item;
} else {
throw reportMixedItems(loc, context);
}
}
};
return new ItemMappingIterator(result.getAnother(), atomicValueChecker);
} else {
ItemMappingFunction nodeChecker = new ItemMappingFunction() {
public Item map(Item item) throws XPathException {
if (item instanceof NodeInfo) {
return item;
} else {
throw reportMixedItems(loc, context);
}
}
};
return new DocumentOrderIterator(
new ItemMappingIterator(result.getAnother(), nodeChecker),
GlobalOrderComparer.getInstance());
}
}