1 package org.testng.xml; 2 3 import static org.testng.collections.CollectionUtils.hasElements; 4 5 import org.testng.collections.Lists; 6 import org.testng.reporters.XMLStringBuffer; 7 import org.testng.xml.dom.OnElement; 8 9 import java.util.List; 10 11 public class XmlDefine { 12 13 private String m_name; 14 setName(String name)15 public void setName(String name) { 16 m_name = name; 17 } 18 getName()19 public String getName() { 20 return m_name; 21 } 22 toXml(String indent)23 public String toXml(String indent) { 24 XMLStringBuffer xsb = new XMLStringBuffer(indent); 25 boolean hasElements = hasElements(m_includes); 26 if (hasElements) { 27 xsb.push("define", "name", m_name); 28 } 29 for (String s : m_includes) { 30 xsb.addEmptyElement("include", "name", s); 31 } 32 if (hasElements) { 33 xsb.pop("define"); 34 } 35 36 return xsb.toXML(); 37 } 38 39 private List<String> m_includes = Lists.newArrayList(); 40 41 @OnElement(tag = "include", attributes = "name") onElement(String name)42 public void onElement(String name) { 43 m_includes.add(name); 44 } 45 getIncludes()46 public List<String> getIncludes() { 47 return m_includes; 48 } 49 } 50