view src/java/de/intevation/mxd/reader/ClassBreakRendererReader.java @ 33:c51376f8e24c

Separated converter components into packages.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 12 Apr 2011 13:20:49 +0200
parents 40c0b4e5f91a
children 7a927921eb6c
line wrap: on
line source
package de.intevation.mxd.reader;

import java.io.IOException;

import org.apache.log4j.Logger;

import com.esri.arcgis.carto.IFeatureRenderer;
import com.esri.arcgis.carto.ClassBreaksRenderer;

import org.w3c.dom.Node;
import org.w3c.dom.Element;
import org.w3c.dom.Document;
import org.w3c.dom.Attr;

import de.intevation.mxd.utils.MapToXMLUtils;

/**
 * Reads the ClassBreaksRender Object Attributes.
 *
 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
 */
public class ClassBreakRendererReader
implements IRendererReader {

    /**
     * The logger.
     */
    private static final Logger logger =
        Logger.getLogger(ClassBreakRendererReader.class);

    /**
     * Private member.
     */
    private ClassBreaksRenderer renderer;
    private Element layer;
    private MapToXMLUtils util;


    public ClassBreakRendererReader(IFeatureRenderer renderer)
    throws Exception {
        logger.debug("contructor()");
        if(renderer instanceof ClassBreaksRenderer)
            this.renderer = (ClassBreaksRenderer)renderer;
        else
            throw new Exception("Not a ClassBreaksRenderer!");
    }

    /**
     * Setter for the parent XML element.
     *
     * @param parent The XML parent node.
     */
    public void setParent(Element parent) {
        this.layer = parent;
    }

    /**
     * Setter for XML document helper.
     *
     * @param util The helper class for storing map information.
     */
    public void setUtil(MapToXMLUtils util) {
        this.util = util;
    }

    /**
     * Reads the Renderer attributes.
     *
     * @return The XML node.
     */
    public Element read()
    throws IOException {
        logger.debug("read()");
        Element rendererElement;
        try {
            rendererElement = util.addRenderer(layer);
        }
        catch(Exception e) {
            e.printStackTrace();
            return null;
        }

        rendererElement.setAttribute("class_count",
                String.valueOf(renderer.getClassCount()));
        for(int i = 0; i < renderer.getClassCount(); i++){
            rendererElement.setAttribute("class_" + i,
                renderer.esri_getClass(i));
        }

        rendererElement.setAttribute("break_count",
            String.valueOf(renderer.getBreakCount()));
        for(int i = 0; i < renderer.getBreakCount(); i++){
            rendererElement.setAttribute("break_" + i,
                String.valueOf(renderer.getBreak(i)));
        }

        rendererElement.setAttribute("color_ramp", renderer.getColorRamp());
        return rendererElement;
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)