//if (context.getProfiler().isEnabled())
//context.getProfiler().end(this, "fn:collection: loading documents", cached);
//return cached;
// }
//Build the document set
DocumentSet docs = null;
try {
if (args.size() == 0) {
//TODO : add default collection to the context
//If the value of the default collection is undefined an error is raised [err:FODC0002].
docs = context.getStaticallyKnownDocuments();
} else {
MutableDocumentSet ndocs = new DefaultDocumentSet();
for (final String next : args) {
final XmldbURI uri = new AnyURIValue(next).toXmldbURI();
final Collection coll = context.getBroker().getCollection(uri);
if (coll == null) {
if (context.isRaiseErrorOnFailedRetrieval()) {
throw new XPathException("FODC0002: can not access collection '" + uri + "'");
}
} else {
if (context.inProtectedMode())
{context.getProtectedDocs().getDocsByCollection(coll, includeSubCollections, ndocs);}
else
{coll.allDocs(context.getBroker(), ndocs,
includeSubCollections, context.getProtectedDocs());}
}
}
docs = ndocs;
}
} catch (final XPathException e) { //From AnyURIValue constructor
e.setLocation(line, column);
throw new XPathException("FODC0002: " + e.getMessage());
} catch(final PermissionDeniedException pde) {
throw new XPathException("FODC0002: can not access collection '" + pde.getMessage() + "'");
}
// iterate through all docs and create the node set
final NodeSet result = new NewArrayNodeSet(docs.getDocumentCount(), 1);
Lock dlock;
DocumentImpl doc;
for (final Iterator<DocumentImpl> i = docs.getDocumentIterator(); i.hasNext();) {
doc = i.next();
dlock = doc.getUpdateLock();
boolean lockAcquired = false;
try {
if (!context.inProtectedMode() && !dlock.hasLock()) {