public OMNode detach() throws OMException { if (this.parentNode == null) { throw new OMException("Parent level elements cannot be detached"); } else { if (!done) { build(); } if (previousSibling == null) { // This is the first child if (nextSibling != null) { this.parentNode.setFirstChild(nextSibling); } else { this.parentNode.firstChild = null; this.parentNode.lastChild = null; } } else { this.previousSibling.setNextOMSibling(nextSibling); if (nextSibling == null) { this.previousSibling.parentNode.done = true; } } if (this.nextSibling != null) { this.nextSibling.setPreviousOMSibling(this.previousSibling); } if (this.parentNode != null && this.parentNode.lastChild == this) { this.parentNode.lastChild = previousSibling; } this.parentNode = null; } return this; }
/** Inserts the given sibling before this item. */ public void insertSiblingBefore(OMNode sibling) throws OMException { // ((OMNodeEx)sibling).setParent(this.parentNode); if (this == sibling) { throw new OMException("Inserting self as the sibling is not allowed"); } if (sibling instanceof ChildNode) { // ChildNode domSibling = (ChildNode)sibling; // domSibling.nextSibling = this; // if(this.previousSibling != null) { // this.previousSibling.nextSibling = domSibling; // } // domSibling.previousSibling = this.previousSibling; // this.previousSibling = domSibling; ChildNode siblingImpl = (ChildNode) sibling; siblingImpl.nextSibling = this; if (previousSibling == null) { this.parentNode.setFirstChild(siblingImpl); siblingImpl.previousSibling = null; } else { siblingImpl.setParent(this.parentNode); previousSibling.setNextOMSibling(siblingImpl); siblingImpl.setPreviousOMSibling(previousSibling); } previousSibling = siblingImpl; } else { throw new OMException("The given child is not of type " + ChildNode.class); } }