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