96 lines
2.7 KiB
Java
96 lines
2.7 KiB
Java
package eu.eudat.entities.xmlmodels.modeldefinition;
|
|
|
|
import java.util.LinkedList;
|
|
import java.util.List;
|
|
|
|
import org.w3c.dom.Document;
|
|
import org.w3c.dom.Element;
|
|
import org.w3c.dom.Node;
|
|
import org.w3c.dom.NodeList;
|
|
|
|
import eu.eudat.models.components.commons.Multiplicity;
|
|
import eu.eudat.utilities.XmlSerializable;
|
|
import eu.eudat.utilities.builders.XmlBuilder;
|
|
|
|
public class FieldSet implements DatabaseModelDefinition,XmlSerializable<FieldSet>{
|
|
|
|
private String id;
|
|
|
|
private int ordinal;
|
|
private Multiplicity multiplicity;
|
|
|
|
private List<Field> fields;
|
|
|
|
public String getId() {
|
|
return id;
|
|
}
|
|
public void setId(String id) {
|
|
this.id = id;
|
|
}
|
|
public int getOrdinal() {
|
|
return ordinal;
|
|
}
|
|
public void setOrdinal(int ordinal) {
|
|
this.ordinal = ordinal;
|
|
}
|
|
public List<Field> getFields() {
|
|
return fields;
|
|
}
|
|
public void setFields(List<Field> fields) {
|
|
this.fields = fields;
|
|
}
|
|
|
|
public Multiplicity getMultiplicity() {
|
|
return multiplicity;
|
|
}
|
|
public void setMultiplicity(Multiplicity multiplicity) {
|
|
this.multiplicity = multiplicity;
|
|
}
|
|
@Override
|
|
public Element toXml(Document doc) {
|
|
|
|
Element rootElement = doc.createElement("fieldset");
|
|
rootElement.setAttribute("id", this.id);
|
|
rootElement.setAttribute("ordinal",""+this.ordinal);
|
|
|
|
Element fieldsElement = doc.createElement("fields");
|
|
for(Field field:this.fields){
|
|
fieldsElement.appendChild(field.toXml(doc));
|
|
}
|
|
rootElement.appendChild(fieldsElement);
|
|
Element multiplicity = doc.createElement("multiplicity");
|
|
multiplicity.setAttribute("min", ""+this.multiplicity.getMin());
|
|
multiplicity.setAttribute("max", ""+this.multiplicity.getMax());
|
|
rootElement.appendChild(multiplicity);
|
|
rootElement.appendChild(multiplicity);
|
|
return rootElement;
|
|
}
|
|
@Override
|
|
public FieldSet fromXml(Element element) {
|
|
this.id = element.getAttribute("id");
|
|
this.ordinal = Integer.parseInt(element.getAttribute("ordinal"));
|
|
|
|
this.fields = new LinkedList();
|
|
Element fields = (Element)XmlBuilder.getNodeFromListByTagName(element.getChildNodes(), "fields");
|
|
|
|
if(fields!=null){
|
|
NodeList fieldElements = fields.getChildNodes();
|
|
for (int temp = 0; temp < fieldElements.getLength(); temp++) {
|
|
Node fieldElement = fieldElements.item(temp);
|
|
if (fieldElement.getNodeType() == Node.ELEMENT_NODE) {
|
|
this.fields.add(new Field().fromXml((Element)fieldElement));
|
|
}
|
|
}
|
|
}
|
|
this.multiplicity = new Multiplicity();
|
|
Element multiplicity = (Element)XmlBuilder.getNodeFromListByTagName(element.getChildNodes(), "multiplicity");
|
|
|
|
this.multiplicity.setMin(Integer.parseInt(multiplicity.getAttribute("min")));
|
|
this.multiplicity.setMax(Integer.parseInt(multiplicity.getAttribute("max")));
|
|
|
|
return this;
|
|
}
|
|
|
|
|
|
}
|