sascha@674: package de.intevation.flys.artifacts.model; sascha@674: sascha@674: import org.w3c.dom.Document; sascha@674: import org.w3c.dom.Element; sascha@674: sascha@674: import java.util.List; sascha@674: import java.util.ArrayList; sascha@674: sascha@674: public class Calculation sascha@674: { sascha@674: public static class Problem { sascha@674: sascha@674: protected Double km; sascha@674: protected String msg; sascha@674: sascha@674: public Problem() { sascha@674: } sascha@674: sascha@674: public Problem(String msg) { sascha@674: this.msg = msg; sascha@674: } sascha@674: sascha@674: public Problem(double km, String msg) { sascha@674: this.km = km; sascha@674: this.msg = msg; sascha@674: } sascha@674: sascha@674: public Element toXML(Document document) { sascha@674: Element problem = document.createElement("problem"); sascha@674: if (km != null) { sascha@674: problem.setAttribute("km", String.valueOf(km)); sascha@674: } sascha@674: problem.setTextContent(msg); sascha@674: return problem; sascha@674: } sascha@674: } // class Problem sascha@674: sascha@674: protected List problems; sascha@674: sascha@674: public Calculation() { sascha@674: } sascha@674: sascha@674: protected List checkProblems() { sascha@674: if (problems == null) { sascha@674: problems = new ArrayList(); sascha@674: } sascha@674: return problems; sascha@674: } sascha@674: sascha@674: public void addProblem(String msg) { sascha@674: checkProblems().add(new Problem(msg)); sascha@674: } sascha@674: sascha@674: public void addProblem(double km, String msg) { sascha@674: checkProblems().add(new Problem(km, msg)); sascha@674: } sascha@674: sascha@674: public boolean hasProblems() { sascha@674: return problems != null && !problems.isEmpty(); sascha@674: } sascha@674: sascha@674: public List getProblems() { sascha@674: return problems; sascha@674: } sascha@674: sascha@674: public void toXML(Document document) { sascha@674: sascha@674: Element root = document.createElement("problems"); sascha@674: sascha@674: if (hasProblems()) { sascha@674: for (Problem problem: problems) { sascha@674: root.appendChild(problem.toXML(document)); sascha@674: } sascha@674: } sascha@674: sascha@674: document.appendChild(root); sascha@674: } sascha@674: } sascha@674: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :