package org.bedework.util.deployment;

import org.w3c.dom.Element;
import org.w3c.dom.Node;

import java.io.File;
import java.util.List;

/** Represent a jboss-web.xml file.
 *
 * @author douglm
 */
public class JbossAllXml extends XmlFile {
  private final PropertiesChain props;
  private final String version;

  public JbossAllXml(final Utils utils,
                     final File metaInf,
                     final String version,
                     final PropertiesChain props) throws Throwable {
    super(utils, metaInf, "jboss-all.xml", false);
    this.version = version;
    this.props = props;
  }

  public void update() throws Throwable {
    utils.debug("Update " + theXml.getAbsolutePath());

    final List<String> earDependencies = 
            props.listProperty("app.ear.dependencies");

    if (earDependencies != null) {
      for (final String ed: earDependencies) {
        addDependency(ed);
      }
    }
  }

  public void addDependency(final String dep) throws Throwable {
    final Element el = findElement(root, "jboss-deployment-dependencies");
    if (el == null) {
      utils.error("Cannot locate jboss-deployment-dependencies");
      return;
    }
    
    final Node depNode = doc.createElement("dependency");
    final Node textNode = doc.createTextNode(dep + "-" + version + ".ear");

    depNode.appendChild(textNode);
    el.appendChild(depNode);

    updated = true;
  }
}

@@ -63,33 +63,8 @@
 ent;
-%0Aimport org.w3c.dom.Node;
 %0A%0Aim
@@ -1171,20 +1171,23 @@
   final 
-Node
+Element
  depNode
@@ -1230,115 +1230,68 @@
     
-final Node textNode = doc.createTextNode(dep + %22-%22 + version + %22.ear%22);%0A%0A    depNode.appendChild(textNode);
+depNode.setAttribute(%22name%22, dep + %22-%22 + version + %22.ear%22);%0A
 %0A   

Fix jboss-all generation. Name should be attribute