teichmann@5863: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5863: * Software engineering by Intevation GmbH teichmann@5863: * teichmann@5994: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5863: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5994: * documentation coming with Dive4Elements River for details. teichmann@5863: */ teichmann@5863: teichmann@5831: package org.dive4elements.river.artifacts.model.map; ingo@3300: ingo@3300: import java.util.HashMap; ingo@3300: import java.util.Map; ingo@3300: ingo@3300: import org.w3c.dom.Document; ingo@3300: import org.w3c.dom.Element; ingo@3300: tom@9726: import org.apache.logging.log4j.Logger; tom@9726: import org.apache.logging.log4j.LogManager; ingo@3300: teichmann@5831: import org.dive4elements.artifacts.CallMeta; teichmann@5831: import org.dive4elements.river.artifacts.model.Calculation; ingo@3300: ingo@3300: ingo@3300: public class WSPLGENCalculation extends Calculation { ingo@3300: tom@9726: private static final Logger log = LogManager.getLogger( tom@8856: WSPLGENCalculation.class); ingo@3300: ingo@3300: protected Map errors; ingo@3300: protected Map warnings; ingo@3300: ingo@3300: ingo@3300: public WSPLGENCalculation() { ingo@3300: errors = new HashMap(); ingo@3300: warnings = new HashMap(); ingo@3300: } ingo@3300: ingo@3300: ingo@3300: public void addError(Integer key, String msg) { ingo@3300: log.debug("New error: (" + key + ") " + msg); ingo@3300: errors.put(key, msg); ingo@3300: } ingo@3300: ingo@3300: ingo@3300: public void addWarning(Integer key, String msg) { ingo@3300: log.debug("New warning: (" + key + ") " + msg); ingo@3300: warnings.put(key, msg); ingo@3300: } ingo@3300: ingo@3300: ingo@3300: public int numErrors() { ingo@3300: return errors.size(); ingo@3300: } ingo@3300: ingo@3300: ingo@3300: public int numWarnings() { ingo@3300: return warnings.size(); ingo@3300: } ingo@3300: ingo@3300: ingo@3300: @Override ingo@3300: public void toXML(Document document, CallMeta meta) { ingo@3300: Element root = document.createElement("problems"); ingo@3300: ingo@3300: if (numErrors() > 0) { teichmann@4050: for (Map.Entry entry: errors.entrySet()) { ingo@3300: Element problem = document.createElement("problem"); ingo@3300: problem.setAttribute("error", String.valueOf(entry.getKey())); ingo@3300: problem.setTextContent(entry.getValue()); ingo@3300: ingo@3300: root.appendChild(problem); ingo@3300: } ingo@3300: } ingo@3300: ingo@3300: if (numWarnings() > 0) { teichmann@4050: for (Map.Entry entry: warnings.entrySet()) { ingo@3300: Element problem = document.createElement("problem"); ingo@3300: problem.setAttribute("error", String.valueOf(entry.getKey())); ingo@3300: problem.setTextContent(entry.getValue()); ingo@3300: ingo@3300: root.appendChild(problem); ingo@3300: } ingo@3300: } ingo@3300: ingo@3300: document.appendChild(root); ingo@3300: } ingo@3300: } ingo@3300: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :