if (contextItem != null)
{context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT ITEM", contextItem.toSequence());}
}
// get statically known documents from the context
DocumentSet ds = context.getStaticallyKnownDocuments();
if (ds == null || ds.getDocumentCount() == 0) {return Sequence.EMPTY_SEQUENCE;}
// // if the expression occurs in a nested context, we might have cached the
// // document set
// // TODO: disabled cache for now as it may cause concurrency issues
// // better use compile-time inspection and maybe a pragma to mark those
// // sections in the query that can be safely cached
// if (cachedDocs != null && cachedDocs.equalDocs(ds)) return cached;
// check if the loaded documents should remain locked
NewArrayNodeSet result = new NewArrayNodeSet(2);
try {
// wait for pending updates
if (!context.inProtectedMode())
{ds.lock(context.getBroker(), false, true);}
DocumentImpl doc;
for (final Iterator<DocumentImpl> i = ds.getDocumentIterator(); i.hasNext();) {
doc = i.next();
if (context.inProtectedMode() && !context.getProtectedDocs().containsKey(doc.getDocId()))
{continue;}
if(doc.getResourceType() == DocumentImpl.XML_FILE) { // skip binary resources
result.add(new NodeProxy(doc));
}
}
cached = result;
cachedDocs = ds;
} catch (final LockException e) {
throw new XPathException(this, "Failed to acquire lock on the context document set");
} finally {
// release all locks
if (!context.inProtectedMode())
{ds.unlock(false);}
}
// result.updateNoSort();
if (context.getProfiler().isEnabled())
{context.getProfiler().end(this, "", result);}