org.jgroups.conf.XmlNode Maven / Gradle / Ivy
Go to download
This artifact provides a single jar that contains all classes required to use remote Jakarta Enterprise Beans and Jakarta Messaging, including
all dependencies. It is intended for use by those not using maven, maven users should just import the Jakarta Enterprise Beans and
Jakarta Messaging BOM's instead (shaded JAR's cause lots of problems with maven, as it is very easy to inadvertently end up
with different versions on classes on the class path).
The newest version!
package org.jgroups.conf;
import java.util.*;
/**
* A simple replacement for a W3C DOM node.
* @author Bela Ban
* @since 5.1.4
*/
public class XmlNode {
protected final String name;
protected Map attributes;
protected List children;
public XmlNode(String name) {
this.name=Objects.requireNonNull(name);
}
public String getName() {return name;}
public Map getAttributes() {return attributes;}
public List getChildren() {return children;}
public XmlNode setAttributes(Map attrs) {
this.attributes=attrs;
return this;
}
public XmlNode addAttribute(String attr_name, String val) {
if(attributes == null)
attributes=new HashMap<>();
attributes.put(attr_name, val);
return this;
}
public XmlNode addChild(XmlNode n) {
if(children == null)
children=new ArrayList<>();
children.add(n);
return this;
}
@Override
public String toString() {
return print(0);
}
protected String print(int indent) {
StringBuilder sb=new StringBuilder(String.format("%s%s", " ".repeat(indent), name));
if(attributes != null)
sb.append(" ").append(attributes);
sb.append("\n");
if(children != null) {
for(XmlNode child: children)
sb.append(child.print(indent+2));
}
return sb.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy