示例#1
0
  public Attr setAttributeNode(Attr newAttr) throws DOMException {
    // Check if this attribute is already in use.
    Element owner = newAttr.getOwnerElement();
    if (owner != null) {
      if (owner == this) { // Replacing an attribute node by itself has no effect
        return null;
      } else {
        throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR, Messages.getString("imageio.8E"));
      }
    }

    String name = newAttr.getName();
    Attr oldAttr = getAttributeNode(name);
    if (oldAttr != null) {
      removeAttributeNode(oldAttr);
    }

    IIOMetadataAttr iioAttr;
    if (newAttr instanceof IIOMetadataAttr) {
      iioAttr = (IIOMetadataAttr) newAttr;
      iioAttr.setOwnerElement(this);
    } else {
      iioAttr = new IIOMetadataAttr(name, newAttr.getValue(), this);
    }

    attrs.list.add(iioAttr);

    return oldAttr;
  }