protected int addItem(Node arg) {
   int i = findNamePoint(arg.getNamespaceURI(), arg.getLocalName());
   if (i >= 0) {
     nodes.set(i, arg);
   } else {
     // If we can't find by namespaceURI, localName, then we find by
     // nodeName so we know where to insert.
     i = findNamePoint(arg.getNodeName(), 0);
     if (i >= 0) {
       nodes.add(i, arg);
     } else {
       i = -1 - i; // Insert point (may be end of list)
       if (null == nodes) {
         nodes = new ArrayList(5);
       }
       nodes.add(i, arg);
     }
   }
   return i;
 }
  /**
   * Adds a node using its namespaceURI and localName.
   *
   * @see mf.org.w3c.dom.NamedNodeMap#setNamedItem
   * @return If the new Node replaces an existing node the replaced Node is returned, otherwise null
   *     is returned.
   * @param arg A node to store in a named node map. The node will later be accessible using the
   *     value of the namespaceURI and localName attribute of the node. If a node with those
   *     namespace URI and local name is already present in the map, it is replaced by the new one.
   */
  public Node setNamedItemNS(Node arg) throws DOMException {

    CoreDocumentImpl ownerDocument = ownerNode.ownerDocument();
    if (ownerDocument.errorChecking) {
      if (isReadOnly()) {
        String msg =
            DOMMessageFormatter.formatMessage(
                DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null);
        throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg);
      }

      if (arg.getOwnerDocument() != ownerDocument) {
        String msg =
            DOMMessageFormatter.formatMessage(
                DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null);
        throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
      }
    }

    int i = findNamePoint(arg.getNamespaceURI(), arg.getLocalName());
    NodeImpl previous = null;
    if (i >= 0) {
      previous = (NodeImpl) nodes.get(i);
      nodes.set(i, arg);
    } else {
      // If we can't find by namespaceURI, localName, then we find by
      // nodeName so we know where to insert.
      i = findNamePoint(arg.getNodeName(), 0);
      if (i >= 0) {
        previous = (NodeImpl) nodes.get(i);
        nodes.add(i, arg);
      } else {
        i = -1 - i; // Insert point (may be end of list)
        if (null == nodes) {
          nodes = new ArrayList(5);
        }
        nodes.add(i, arg);
      }
    }
    return previous;
  } // setNamedItemNS(Node):Node