1package org.testng.xml;
2
3import java.util.List;
4
5import org.testng.collections.Lists;
6import org.testng.reporters.XMLStringBuffer;
7import org.testng.xml.dom.Tag;
8
9import static org.testng.collections.CollectionUtils.hasElements;
10
11public class XmlGroups {
12
13  private List<XmlDefine> m_defines = Lists.newArrayList();
14  private XmlRun m_run;
15  private List<XmlDependencies> m_dependencies = Lists.newArrayList();
16
17  public List<XmlDefine> getDefines() {
18    return m_defines;
19  }
20
21  @Tag(name = "define")
22  public void addDefine(XmlDefine define) {
23    getDefines().add(define);
24  }
25
26  public void setDefines(List<XmlDefine> defines) {
27    m_defines = defines;
28  }
29
30  public XmlRun getRun() {
31    return m_run;
32  }
33
34  public void setRun(XmlRun run) {
35    m_run = run;
36  }
37
38  public List<XmlDependencies> getDependencies() {
39    return m_dependencies;
40  }
41
42//  public void setDependencies(List<XmlDependencies> dependencies) {
43//    m_dependencies = dependencies;
44//  }
45
46  @Tag(name = "dependencies")
47  public void setXmlDependencies(XmlDependencies dependencies) {
48    m_dependencies.add(dependencies);
49  }
50
51  public String toXml(String indent) {
52    XMLStringBuffer xsb = new XMLStringBuffer(indent);
53    String indent2 = indent + "  ";
54
55    boolean hasGroups = hasElements(m_defines) || m_run != null
56        || hasElements(m_dependencies);
57
58    if (hasGroups) {
59      xsb.push("groups");
60    }
61
62    for (XmlDefine d : m_defines) {
63      xsb.getStringBuffer().append(d.toXml(indent2));
64    }
65
66    xsb.getStringBuffer().append(m_run.toXml(indent2));
67
68    for (XmlDependencies d : m_dependencies) {
69      xsb.getStringBuffer().append(d.toXml(indent2));
70    }
71
72    if (hasGroups) {
73      xsb.pop("groups");
74    }
75
76    return xsb.toXML();
77  }
78}
79