93 lines
2.7 KiB
Java
93 lines
2.7 KiB
Java
package eu.eudat.entities.xmlmodels.modeldefinition;
|
|
|
|
import org.w3c.dom.Document;
|
|
import org.w3c.dom.Element;
|
|
|
|
import eu.eudat.models.components.commons.DefaultValue;
|
|
import eu.eudat.models.components.commons.Multiplicity;
|
|
import eu.eudat.utilities.XmlSerializable;
|
|
import eu.eudat.utilities.builders.XmlBuilder;
|
|
|
|
public class Field implements DatabaseModelDefinition,XmlSerializable<Field>{
|
|
|
|
private String id;
|
|
private String datatype;
|
|
private int ordinal;
|
|
private DefaultValue defaultValue;
|
|
private Multiplicity multiplicity;
|
|
public String getId() {
|
|
return id;
|
|
}
|
|
public void setId(String id) {
|
|
this.id = id;
|
|
}
|
|
public String getDatatype() {
|
|
return datatype;
|
|
}
|
|
public void setDatatype(String datatype) {
|
|
this.datatype = datatype;
|
|
}
|
|
public int getOrdinal() {
|
|
return ordinal;
|
|
}
|
|
public void setOrdinal(int ordinal) {
|
|
this.ordinal = ordinal;
|
|
}
|
|
|
|
public DefaultValue getDefaultValue() {
|
|
return defaultValue;
|
|
}
|
|
public void setDefaultValue(DefaultValue defaultValue) {
|
|
this.defaultValue = defaultValue;
|
|
}
|
|
|
|
public Multiplicity getMultiplicity() {
|
|
return multiplicity;
|
|
}
|
|
public void setMultiplicity(Multiplicity multiplicity) {
|
|
this.multiplicity = multiplicity;
|
|
}
|
|
|
|
@Override
|
|
public Element toXml(Document doc) {
|
|
Element element = doc.createElement("field");
|
|
element.setAttribute("id", this.id);
|
|
element.setAttribute("ordinal",""+this.ordinal);
|
|
element.setAttribute("datatype", this.datatype);
|
|
|
|
Element defaultValue = doc.createElement("defaultValue");
|
|
defaultValue.setAttribute("type", this.defaultValue.getType());
|
|
defaultValue.setAttribute("value",this.defaultValue.getValue());
|
|
|
|
Element multiplicity = doc.createElement("multiplicity");
|
|
multiplicity.setAttribute("min", ""+this.multiplicity.getMin());
|
|
multiplicity.setAttribute("max", ""+this.multiplicity.getMax());
|
|
|
|
element.appendChild(defaultValue);
|
|
element.appendChild(multiplicity);
|
|
return element;
|
|
}
|
|
@Override
|
|
public Field fromXml(Element item) {
|
|
this.id = item.getAttribute("id");
|
|
this.ordinal = Integer.parseInt(item.getAttribute("ordinal"));
|
|
this.datatype = item.getAttribute("datatype");
|
|
|
|
this.defaultValue = new DefaultValue();
|
|
Element defaultValue = (Element)XmlBuilder.getNodeFromListByTagName(item.getChildNodes(), "defaultValue");
|
|
|
|
this.defaultValue.setType(defaultValue.getAttribute("type"));
|
|
this.defaultValue.setValue(defaultValue.getAttribute("value"));
|
|
|
|
this.multiplicity = new Multiplicity();
|
|
Element multiplicity = (Element)XmlBuilder.getNodeFromListByTagName(item.getChildNodes(), "multiplicity");
|
|
|
|
this.multiplicity.setMin(Integer.parseInt(multiplicity.getAttribute("min")));
|
|
this.multiplicity.setMax(Integer.parseInt(multiplicity.getAttribute("max")));
|
|
|
|
return this;
|
|
}
|
|
|
|
|
|
}
|