Example #1
0
  public Node removeChild(Node oldChild) throws DOMException {
    if (oldChild == null) {
      throw new IllegalArgumentException(Messages.getString("imageio.62"));
    }

    IIOMetadataNode oldIIOChild = (IIOMetadataNode) oldChild;

    // Fix next and previous
    IIOMetadataNode previous = oldIIOChild.previousSibling;
    IIOMetadataNode next = oldIIOChild.nextSibling;

    if (previous != null) {
      previous.nextSibling = next;
    }
    if (next != null) {
      next.previousSibling = previous;
    }

    // Fix this node
    if (lastChild == oldIIOChild) {
      lastChild = previous;
    }
    if (firstChild == oldIIOChild) {
      firstChild = next;
    }
    nChildren--;

    // Fix old child
    oldIIOChild.parent = null;
    oldIIOChild.previousSibling = null;
    oldIIOChild.nextSibling = null;

    return oldIIOChild;
  }
Example #2
0
  public Node replaceChild(Node newChild, Node oldChild) throws DOMException {
    if (newChild == null) {
      throw new IllegalArgumentException(Messages.getString("imageio.61"));
    }

    IIOMetadataNode newIIOChild = (IIOMetadataNode) newChild;
    IIOMetadataNode oldIIOChild = (IIOMetadataNode) oldChild;

    IIOMetadataNode next = oldIIOChild.nextSibling;
    IIOMetadataNode previous = oldIIOChild.previousSibling;

    // Fix new node
    newIIOChild.parent = this;
    newIIOChild.nextSibling = next;
    newIIOChild.previousSibling = previous;

    // Fix this node
    if (lastChild == oldIIOChild) {
      lastChild = newIIOChild;
    }
    if (firstChild == oldIIOChild) {
      firstChild = newIIOChild;
    }

    // Fix siblings
    if (next != null) {
      next.previousSibling = newIIOChild;
    }
    if (previous != null) {
      previous.nextSibling = newIIOChild;
    }

    // Fix old child
    oldIIOChild.parent = null;
    oldIIOChild.nextSibling = next;
    oldIIOChild.previousSibling = previous;

    return oldIIOChild;
  }
Example #3
0
  public Node insertBefore(Node newChild, Node refChild) throws DOMException {
    if (newChild == null) {
      throw new IllegalArgumentException(Messages.getString("imageio.61"));
    }

    IIOMetadataNode newIIOChild = (IIOMetadataNode) newChild;
    IIOMetadataNode refIIOChild = (IIOMetadataNode) refChild;

    newIIOChild.parent = this;

    if (refIIOChild == null) {
      newIIOChild.nextSibling = null;
      newIIOChild.previousSibling = lastChild;

      // Fix this node
      lastChild = newIIOChild;
      if (firstChild == null) {
        firstChild = newIIOChild;
      }
    } else {
      newIIOChild.nextSibling = refIIOChild;
      newIIOChild.previousSibling = refIIOChild.previousSibling;

      // Fix this node
      if (firstChild == refIIOChild) {
        firstChild = newIIOChild;
      }

      // Fix next node
      if (refIIOChild != null) {
        refIIOChild.previousSibling = newIIOChild;
      }
    }

    // Fix prev node
    if (newIIOChild.previousSibling != null) {
      newIIOChild.previousSibling.nextSibling = newIIOChild;
    }

    nChildren++;

    return newIIOChild;
  }