public Element writeConstraints(Element element, ConstraintObject co) {
if (co.getConstraints().size() == 0)
return element;
Element newElement = element.addElement("constraints");
for (Constraint constr : co.getConstraints()) {
Element el = newElement.addElement(constr.getClass().getSimpleName());
el.addAttribute("weight", "" + constr.getWeight());
if (constr instanceof RasterConstraint) {
RasterConstraint rc = (RasterConstraint) constr;
Writing w = getWriting(BitSet.class);
el.setText(w.toString(rc.getRaster().getForbidden()));
el.addAttribute("length", "" + rc.getRaster().getForbidden().getLength());
} else if (constr instanceof EventOrderConstraint) {
EventOrderConstraint eoc = (EventOrderConstraint) constr;
el.addElement("event").addAttribute("ref", "" + eoc.getEvent().getId());
for (Event ev : eoc.getBefores()) {
el.addElement("beforeEvent").addAttribute("ref", "" + ev.getId());
}
for (Event ev : eoc.getFollows()) {
el.addElement("followsEvent").addAttribute("ref", "" + ev.getId());
}
} else if (constr instanceof PersonITCRasterConstraint) {
PersonITCRasterConstraint pc = (PersonITCRasterConstraint) constr;
el.addElement("person").addAttribute("ref", "" + pc.getPerson().getId());
} else if (constr instanceof MinGapsConstraint) {
MinGapsConstraint mgc = (MinGapsConstraint) constr;
el.addAttribute("countEarly", "" + mgc.isCountEarly());
for (Event ev : mgc.getEvents()) {
el.addElement("event").addAttribute("ref", "" + ev.getId());
}
} else if (constr instanceof DifferentDayConstraint) {
DifferentDayConstraint ddc = (DifferentDayConstraint) constr;
for (Event ev : ddc.getEvents()) {
el.addElement("event").addAttribute("ref", "" + ev.getId());
}
} else
throw new UnsupportedOperationException("Constraint export/import not yet implemented for class " + constr.getClass().getName());
}