final StoredNode ql[] = selectAndLock(transaction, inSeq);
final IndexListener listener = new IndexListener(ql);
final NotificationService notifier = context.getBroker().getBrokerPool().getNotificationService();
Item temp;
TextImpl text;
AttrImpl attribute;
ElementImpl parent;
for (int i = 0; i < ql.length; i++) {
final StoredNode node = ql[i];
final DocumentImpl doc = (DocumentImpl)node.getOwnerDocument();
if (!doc.getPermissions().validate(context.getUser(), Permission.WRITE)) {
throw new PermissionDeniedException("User '" + context.getSubject().getName() + "' does not have permission to write to the document '" + doc.getDocumentURI() + "'!");
}
doc.getMetadata().setIndexListener(listener);
//update the document
parent = (ElementImpl) node.getParentStoredNode();
if (parent == null)
{throw new XPathException(this, "The root element of a document can not be replaced with 'update replace'. " +
"Please consider removing the document or use 'update value' to just replace the children of the root.");}
switch (node.getNodeType()) {
case Node.ELEMENT_NODE:
temp = contentSeq.itemAt(0);
if (!Type.subTypeOf(temp.getType(), Type.NODE))
{throw new XPathException(this,
Messages.getMessage(Error.UPDATE_REPLACE_ELEM_TYPE,
Type.getTypeName(temp.getType())));}
parent.replaceChild(transaction, ((NodeValue)temp).getNode(), node);
break;
case Node.TEXT_NODE:
text = new TextImpl(contentSeq.getStringValue());
text.setOwnerDocument(doc);
parent.updateChild(transaction, node, text);
break;
case Node.ATTRIBUTE_NODE:
final AttrImpl attr = (AttrImpl) node;
attribute = new AttrImpl(attr.getQName(), contentSeq.getStringValue(), context.getBroker().getBrokerPool().getSymbols());
attribute.setOwnerDocument(doc);
parent.updateChild(transaction, node, attribute);
break;
default:
throw new EXistException("unsupported node-type");