[PATCH] Added first version of diagram attribute parser

Wald Commits scm-commit at wald.intevation.org
Wed Sep 18 16:21:04 CEST 2013


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1379514059 -7200
# Branch generator-refactoring
# Node ID f3cdc620b666cb72064cc29cbe1485fbc423a97d
# Parent  d9fda41b4ec4bc5d52476a5414cb76b76932d902
Added first version of diagram attribute parser.

diff -r d9fda41b4ec4 -r f3cdc620b666 artifacts/src/main/java/org/dive4elements/river/exports/DiagramAttributes.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/DiagramAttributes.java	Wed Sep 18 16:20:59 2013 +0200
@@ -0,0 +1,123 @@
+/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+
+package org.dive4elements.river.exports;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import org.dive4elements.river.exports.process.Processor;
+
+import org.apache.log4j.Logger;
+
+public class DiagramAttributes
+{
+    private static Logger log = Logger.getLogger(DiagramAttributes.class);
+
+    public class AxisAttributes {
+        // TODO: More Attributes
+        private String name;
+
+        public AxisAttributes() {
+        }
+
+        public AxisAttributes(String name) {
+            this.name = name;
+        }
+
+        public String getName() {
+            return name;
+        }
+    } // class AxisAttributes
+
+    public class AxisProcessor {
+        private Processor processor;
+        private String axisName;
+
+        public AxisProcessor() {
+        }
+
+        public AxisProcessor(Processor processor, String axisName) {
+            this.processor = processor;
+            this.axisName  = axisName;
+        }
+
+        public Processor getProcessor() {
+            return processor;
+        }
+
+        public getAxisName() {
+            return axisName;
+        }
+    } // class AxisProcessor
+
+    private List<AxisAttributes> axesAttrs;
+    private List<AxisProcessor> axesProcessors;
+
+    public DiagramAttributes() {
+        axesAttrs      = new ArrayList<AxisAttributes>(5);
+        axesProcessors = new ArrayList<AxisProcessor>(5);
+    }
+
+    public DiagramAttributes(Element config) {
+        this();
+        parseAxis(config);
+        parseProcessors(config);
+    }
+
+    private void parseAxis(Element config) {
+        NodeList axisNodes = config.getElementsByTagName("axis");
+
+        for (int i = 0, N = axisNodes.getLength(); i < N; ++i) {
+            Element axisElement = (Element)axisNodes.item(i);
+            String name = axisElement.getAttribute("name").trim();
+            if (!name.isEmpty()) {
+                axesAttrs.add(new AxisAttributes(name));
+            }
+        }
+    }
+
+    public List<AxisProcessor> getAxesProcessors() {
+        return axesProcessors;
+    }
+
+    private void parseProcessors(Element config) {
+        NodeList processorNodes = config.getElementsByTagName("processor");
+
+        for (int i = 0, N = processorNodes.getLength(); i < N; ++i) {
+            Element processorElement = (Element)processorNodes.item(i);
+            String className = processorElement.getAttribute("class").trim();
+            String axisName = processorElement.getAttribute("axis").trim();
+            if (className.isEmpty() || axisName.isEmpty()) {
+                continue;
+            }
+
+            try {
+                Processor processor =
+                    (Processor)Class.forName(className).newInstance();
+                axesProcessors.add(new AxisProcessor(processor, axisName));
+            }
+            catch (ClassNotFoundException cnfe) {
+                log.error(cnfe, cnfe);
+            }
+            catch (InstantiationException ie) {
+                log.error(ie, ie);
+            }
+            catch (IllegalAccessException ia) {
+                log.error(ia, ia);
+            }
+            catch (ClassCastException cce) {
+                log.error(cce, cce);
+            }
+        }
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :


More information about the Dive4elements-commits mailing list