}
return oldNode;
}
public void removeAppendAttributes(Txn transaction, NodeList removeList, NodeList appendList) {
DBBroker broker = null;
try {
broker = ownerDocument.getBrokerPool().get(null);
if (removeList != null) {
try {
for (int i=0; i<removeList.getLength(); i++) {
final Node oldChild = removeList.item(i);
if (!(oldChild instanceof StoredNode))
{throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, "Wrong node type");}
final StoredNode old = (StoredNode) oldChild;
if (!old.nodeId.isChildOf(nodeId))
{throw new DOMException(DOMException.NOT_FOUND_ERR, "node " +
old.nodeId.getParentId() +
" is not a child of element " + nodeId);}
final NodePath oldPath = old.getPath();
// remove old custom indexes
broker.getIndexController().reindex(transaction, old,
StreamListener.REMOVE_SOME_NODES);
broker.removeNode(transaction, old, oldPath, null);
children--;
attributes--;
}
} finally {
broker.endRemove(transaction);
}
}
final NodePath path = getPath();
broker.getIndexController().setDocument(ownerDocument, StreamListener.STORE);
final StreamListener listener = broker.getIndexController().getStreamListener();
if (children == 0) {
appendChildren(transaction, nodeId.newChild(), null,
new NodeImplRef(this), path, appendList, listener);
} else {
if (attributes == 0) {
final StoredNode firstChild = (StoredNode) getFirstChild();
final NodeId newNodeId = firstChild.nodeId.insertBefore();
appendChildren(transaction, newNodeId, firstChild.getNodeId(),
new NodeImplRef(this), path, appendList, listener);
} else {
final AttribVisitor visitor = new AttribVisitor();
accept(visitor);
final NodeId firstChildId = visitor.firstChild == null ? null : visitor.firstChild.nodeId;
final NodeId newNodeId = visitor.lastAttrib.nodeId.insertNode(firstChildId);
appendChildren(transaction, newNodeId, firstChildId, new NodeImplRef(visitor.lastAttrib),
path, appendList, listener);
}
setDirty(true);
}
attributes += appendList.getLength();
broker.updateNode(transaction, this, true);
broker.flush();
} catch (final EXistException e) {
LOG.warn("Exception while inserting node: " + e.getMessage(), e);
} finally {
if (broker != null)
broker.release();
}
}