doc.setIndexListener(listener);
doc.getMetadata().setIndexListener(listener);
	public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {        if (context.getProfiler().isEnabled()) {            context.getProfiler().start(this);                   context.getProfiler().message(this, Profiler.DEPENDENCIES, "DEPENDENCIES", Dependency.getDependenciesName(this.getDependencies()));            if (contextSequence != null)                context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);            if (contextItem != null)                context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT ITEM", contextItem.toSequence());        }        		if (contextItem != null)			contextSequence = contextItem.toSequence();				Sequence contentSeq = value.eval(contextSequence);		if (contentSeq.getLength() == 0)			throw new XPathException(getASTNode(), Messages.getMessage(Error.UPDATE_EMPTY_CONTENT));                Sequence inSeq = select.eval(contextSequence);                     if (!Type.subTypeOf(inSeq.getItemType(), Type.NODE))            throw new XPathException(getASTNode(), Messages.getMessage(Error.UPDATE_SELECT_TYPE));                if (inSeq.getLength() > 0) {             LOG.debug("Found: " + inSeq.getLength());                           contentSeq = deepCopy(contentSeq);                    try {                TransactionManager transact = context.getBroker().getBrokerPool().getTransactionManager();                Txn transaction = transact.beginTransaction();                StoredNode[] ql = selectAndLock(inSeq.toNodeSet());                NotificationService notifier = context.getBroker().getBrokerPool().getNotificationService();                IndexListener listener = new IndexListener(ql);                NodeImpl node;                NodeImpl parent;                DocumentImpl doc = null;                DocumentSet modifiedDocs = new DocumentSet();                NodeList contentList = seq2nodeList(contentSeq);                for (int i = 0; i < ql.length; i++) {                    node = ql[i];                    doc = (DocumentImpl) node.getOwnerDocument();                    doc.setIndexListener(listener);                    if (!doc.getPermissions().validate(context.getUser(), Permission.UPDATE))                        throw new XPathException(getASTNode(), "permission to remove document denied");                    modifiedDocs.add(doc);    				if (mode == INSERT_APPEND) {    					node.appendChildren(transaction, contentList, -1);    				} else {    	                parent = (StoredNode) node.getParentNode();    	                switch (mode) {    	                    case INSERT_BEFORE:    	                        parent.insertBefore(transaction, contentList, node);    	                        break;    	                    case INSERT_AFTER:    	                        ((NodeImpl) parent).insertAfter(transaction, contentList, node);    	                        break;    	                }    				}                    doc.clearIndexListener();                    doc.setLastModified(System.currentTimeMillis());                    context.getBroker().storeDocument(transaction, doc);                    notifier.notifyUpdate(doc, UpdateListener.UPDATE);                }                checkFragmentation(transaction, modifiedDocs);                    transact.commit(transaction);            } catch (PermissionDeniedException e) {    			throw new XPathException(getASTNode(), e.getMessage(), e);    		} catch (EXistException e) {                throw new XPathException(getASTNode(), e.getMessage(), e);    		} catch (LockException e) {                throw new XPathException(getASTNode(), e.getMessage(), e);    		} finally {                unlockDocuments();            }        }        if (context.getProfiler().isEnabled())             context.getProfiler().end(this, "", Sequence.EMPTY_SEQUENCE);                return Sequence.EMPTY_SEQUENCE;        	}