Node node = null; if (children == 0) node = appendChild(firstChildID(), this, child, true); else { long last = lastChildID(); node = appendChild( last + 1, (NodeImpl) ownerDocument.getNode(last), child, true);
long childGid; NodeImpl lastNode; if (children == 0) { childGid = firstChildID(); lastNode = this; } else { childGid = lastChildID() + 1; lastNode = getLastNode((NodeImpl)ownerDocument.getNode(childGid - 1));
	public Node appendChild(Node child) throws DOMException {		DocumentImpl prevDoc = new DocumentImpl(ownerDocument);		Node node = null;		if (children == 0)			node = appendChild(firstChildID(), this, child, true);		else {			long last = lastChildID();			node =				appendChild(					last + 1,					(NodeImpl) ownerDocument.getNode(last),					child,					true);		}		ownerDocument.broker.update(this);		ownerDocument.broker.reindex(prevDoc, ownerDocument, null);		try {			ownerDocument.broker.saveCollection(ownerDocument.getCollection());		} catch (PermissionDeniedException e) {			throw new DOMException(DOMException.INVALID_ACCESS_ERR, e.getMessage());		}		return child;	}