/** Inserts the given sibling before this item. */
public void insertSiblingBefore(OMNode sibling) throws OMException {
ParentNode parentNode = parentNode();
// ((OMNodeEx)sibling).setParent(this.parentNode);
if (parentNode == null) {
throw new OMException("Parent can not be null");
} else if (this == sibling) {
throw new OMException("Inserting self as the sibling is not allowed");
}
if (sibling instanceof NodeImpl) {
// ChildNode domSibling = (ChildNode)sibling;
// domSibling.nextSibling = this;
// if(this.previousSibling != null) {
// this.previousSibling.nextSibling = domSibling;
// }
// domSibling.previousSibling = this.previousSibling;
// this.previousSibling = domSibling;
NodeImpl siblingImpl = (NodeImpl) sibling;
siblingImpl.internalSetNextSibling(this);
NodeImpl previousSibling = internalGetPreviousSibling();
if (previousSibling == null) {
parentNode.setFirstChild((OMNode)siblingImpl);
siblingImpl.internalSetPreviousSibling(null);
} else {
siblingImpl.setParent(parentNode, false);
previousSibling.setNextOMSibling((OMNode)siblingImpl);
siblingImpl.setPreviousOMSibling((OMNode)previousSibling);
}
internalSetPreviousSibling(siblingImpl);
} else {
throw new OMException("The given child is not of type "
+ NodeImpl.class);
}
}