result.add(new NodeProxy((DocumentImpl) i.next(), -1, Node.DOCUMENT_NODE));
doc = (DocumentImpl) i.next(); result.add(new NodeProxy(doc, -1, Node.DOCUMENT_NODE)); if(lockOnLoad) { context.getLockedDocuments().add(doc); }
	public Sequence eval(		Sequence contextSequence,		Item contextItem)		throws XPathException {	    DocumentSet docs = null;	    Sequence result = null;	    if (getArgumentCount() == 0) {	        if(cached != null) {	            result = cached;	            docs = cached.getDocumentSet();	        } else {		        docs = new DocumentSet();		        context.getBroker().getAllDocuments(docs);	        }	    } else {		    List args = getParameterValues(contextSequence, contextItem);			boolean cacheIsValid = false;			if(cachedArgs != null)			    cacheIsValid = compareArguments(cachedArgs, args);			if(cacheIsValid) {			    result = cached;			    docs = cached.getDocumentSet();			} else {				docs = new DocumentSet();				for(int i = 0; i < args.size(); i++) {					String next = (String)args.get(i);					if(next.length() == 0)						throw new XPathException("Invalid argument to fn:doc function: empty string is not allowed here.");					if(next.charAt(0) != '/')						next = context.getBaseURI() + '/' + next;					try {						DocumentImpl doc = (DocumentImpl) context.getBroker().getDocument(next);						if(doc != null) {						    if(!doc.getPermissions().validate(context.getUser(), Permission.READ))							    throw new XPathException("Insufficient privileges to read resource " + next);							docs.add(doc);						}					} catch (PermissionDeniedException e) {						throw new XPathException("Permission denied: unable to load document " + next);					}				}				cachedArgs = args;			}	    }	    try {	        docs.lock(false);	        // wait for pending updates			if(result == null) {			    result = new ExtArrayNodeSet(docs.getLength(), 1);				for (Iterator i = docs.iterator(); i.hasNext();) {					result.add(new NodeProxy((DocumentImpl) i.next(), -1, Node.DOCUMENT_NODE));				}			}	    } catch (LockException e) {            throw new XPathException(getASTNode(), "Could not acquire lock on document set.");        } finally {	        docs.unlock(false);	    }		cached = result;		return result;	}