/**
   * Assigns any existing properties to the node.<br>
   * It will call attributeDelegates before passing control to the factory that built the node.
   *
   * @param node the object returned by tne node factory
   * @param attributes the attributes for the node
   */
  protected void handleNodeAttributes(Object node, Map attributes) {
    // first, short circuit
    if (node == null) {
      return;
    }

    for (Closure attrDelegate : getProxyBuilder().getAttributeDelegates()) {
      FactoryBuilderSupport builder = this;
      if (attrDelegate.getOwner() instanceof FactoryBuilderSupport) {
        builder = (FactoryBuilderSupport) attrDelegate.getOwner();
      } else if (attrDelegate.getDelegate() instanceof FactoryBuilderSupport) {
        builder = (FactoryBuilderSupport) attrDelegate.getDelegate();
      }

      attrDelegate.call(new Object[] {builder, node, attributes});
    }

    if (getProxyBuilder()
        .getCurrentFactory()
        .onHandleNodeAttributes(getProxyBuilder().getChildBuilder(), node, attributes)) {
      getProxyBuilder().setNodeAttributes(node, attributes);
    }
  }