{return NodeSet.EMPTY_SET;}
// for this method to work, all items have to be nodes
if(itemType != Type.ANY_TYPE && Type.subTypeOf(itemType, Type.NODE)) {
//Was ExtArrayNodeset() which orders the nodes in document order
//The order seems to change between different invocations !!!
final NodeSet set = new AVLTreeNodeSet();
//We can't make it from an ExtArrayNodeSet (probably because it is sorted ?)
//NodeSet set = new ArraySet(100);
for (int i = 0; i < items.length; i++) {
//TODO : investigate why we could have null here
if (items[i] != null) {
NodeValue v = (NodeValue)items[i].item;
if(v.getImplementationType() != NodeValue.PERSISTENT_NODE) {
// found an in-memory document
final org.exist.memtree.DocumentImpl doc = ((NodeImpl)v).getDocument();
if (doc==null) {
continue;
}
// make this document persistent: doc.makePersistent()
// returns a map of all root node ids mapped to the corresponding
// persistent node. We scan the current sequence and replace all
// in-memory nodes with their new persistent node objects.
final DocumentImpl expandedDoc = doc.expandRefs(null);
final org.exist.dom.DocumentImpl newDoc = expandedDoc.makePersistent();
if (newDoc != null) {
NodeId rootId = newDoc.getBrokerPool().getNodeFactory().createInstance();
for (int j = i; j < count; j++) {
v = (NodeValue) items[j].item;
if(v.getImplementationType() != NodeValue.PERSISTENT_NODE) {
NodeImpl node = (NodeImpl) v;
if (node.getDocument() == doc) {
node = expandedDoc.getNode(node.getNodeNumber());
NodeId nodeId = node.getNodeId();
if (nodeId == null)
{throw new XPathException("Internal error: nodeId == null");}
if (node.getNodeType() == Node.DOCUMENT_NODE)
{nodeId = rootId;}
else
{nodeId = rootId.append(nodeId);}
NodeProxy p = new NodeProxy(newDoc, nodeId, node.getNodeType());
if (p != null) {
// replace the node by the NodeProxy
items[j].item = p;
}
}
}
}
}
set.add((NodeProxy) items[i].item);
} else {
set.add((NodeProxy)v);
}
}
}
return set;
} else