/** * Unimplemented. See org.w3c.dom.Node * * @param newChild New child node to insert * @param refChild Insert in front of this child * @return null * @throws DOMException */ public Node insertBefore(Node newChild, Node refChild) throws DOMException { if (null == refChild) { appendChild(newChild); return newChild; } if (newChild == refChild) { // hmm... return newChild; } Node node = m_firstChild; Node prev = null; boolean foundit = false; while (null != node) { // If the newChild is already in the tree, it is first removed. if (newChild == node) { if (null != prev) ((ElemTemplateElement) prev).m_nextSibling = (ElemTemplateElement) node.getNextSibling(); else m_firstChild = (ElemTemplateElement) node.getNextSibling(); node = node.getNextSibling(); continue; // prev remains the same. } if (refChild == node) { if (null != prev) { ((ElemTemplateElement) prev).m_nextSibling = (ElemTemplateElement) newChild; } else { m_firstChild = (ElemTemplateElement) newChild; } ((ElemTemplateElement) newChild).m_nextSibling = (ElemTemplateElement) refChild; ((ElemTemplateElement) newChild).setParentElem(this); prev = newChild; node = node.getNextSibling(); foundit = true; continue; } prev = node; node = node.getNextSibling(); } if (!foundit) throw new DOMException( DOMException.NOT_FOUND_ERR, "refChild was not found in insertBefore method!"); else return newChild; }
/** * Add a child to the child list. NOTE: This presumes the child did not previously have a parent. * Making that assumption makes this a less expensive operation -- but requires that if you *do* * want to reparent a node, you use removeChild() first to remove it from its previous context. * Failing to do so will damage the tree. * * @param elem Child to be added to child list * @return Child just added to the child list */ public ElemTemplateElement appendChild(ElemTemplateElement elem) { if (null == elem) { error(XSLTErrorResources.ER_NULL_CHILD, null); // "Trying to add a null child!"); } if (null == m_firstChild) { m_firstChild = elem; } else { ElemTemplateElement last = getLastChildElem(); last.m_nextSibling = elem; } elem.setParentElem(this); return elem; }
/** * Set the parent as an ElemTemplateElement. * * @param p This node's parent as an ElemTemplateElement */ public void setParentElem(ElemTemplateElement p) { super.setParentElem(p); p.m_hasVariableDecl = true; }
/** * Set the parent of this node. * * @param n Must be a ElemTemplateElement. */ public void exprSetParent(ExpressionNode n) { // This obviously requires that only a ElemTemplateElement can // parent a node of this type. setParentElem((ElemTemplateElement) n); }