view artifacts/src/main/java/org/dive4elements/river/exports/DiagramAttributes.java @ 7040:f3cdc620b666 generator-refactoring

Added first version of diagram attribute parser.
author Sascha L. Teichmann <teichmann@intevation.de>
date Wed, 18 Sep 2013 16:20:59 +0200
parents
children 599d3c48474c
line wrap: on
line source
/* 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 :

http://dive4elements.wald.intevation.org