
org.yaoqiang.bpmn.model.elements.XMLComplexElement Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yaoqiang-bpmn-editor Show documentation
Show all versions of yaoqiang-bpmn-editor Show documentation
an Open Source BPMN 2.0 Modeler
package org.yaoqiang.bpmn.model.elements;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* XMLComplexElement
*
* @author Shi Yaoqiang([email protected])
*/
public abstract class XMLComplexElement extends XMLElement {
protected LinkedHashMap elements = new LinkedHashMap();
public XMLComplexElement(XMLElement parent) {
super(parent);
fillStructure();
}
public XMLComplexElement(XMLElement parent, String name) {
super(parent, name);
fillStructure();
}
protected abstract void fillStructure();
public void set(String name, String value) {
XMLElement el = get(name);
if (el != null) {
el.setValue(value);
} else {
throw new RuntimeException("No such element!");
}
}
public void add(XMLElement el) {
elements.put(el.toName(), el);
}
public XMLElement remove(String name) {
return elements.remove(name);
}
public boolean isEmpty() {
boolean isEmpty = true;
for (XMLElement el : elements.values()) {
isEmpty = isEmpty && el.isEmpty();
}
isEmpty = isEmpty && value.trim().length() == 0;
return isEmpty;
}
public List toElements() {
return new ArrayList(elements.values());
}
public List getXMLElements() {
List els = new ArrayList();
for (XMLElement el : elements.values()) {
if (!(el instanceof XMLAttribute)) {
els.add(el);
}
}
return els;
}
public XMLElement get(String name) {
return elements.get(name);
}
public boolean containsName(String name) {
return elements.containsKey(name);
}
public Object clone() {
XMLComplexElement d = (XMLComplexElement) super.clone();
d.elements = new LinkedHashMap();
for (Map.Entry entry : elements.entrySet()) {
String key = new String(entry.getKey());
XMLElement value = (XMLElement) entry.getValue().clone();
value.setParent(d);
d.elements.put(key, value);
}
return d;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy