view gnv-artifacts/src/main/java/de/intevation/gnv/exports/DefaultDataCollector.java @ 1115:f953c9a559d8

Added license file and license headers. gnv-artifacts/trunk@1260 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 02 Nov 2010 17:46:55 +0000
parents b1f5f2a8840f
children
line wrap: on
line source
/*
 * Copyright (c) 2010 by Intevation GmbH
 *
 * This program is free software under the LGPL (>=v2.1)
 * Read the file LGPL.txt coming with the software for details
 * or visit http://www.gnu.org/licenses/ if it does not exist.
 */

package de.intevation.gnv.exports;

import de.intevation.gnv.geobackend.base.Result;
import de.intevation.gnv.geobackend.base.ResultDescriptor;

import de.intevation.gnv.state.exception.StateException;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

/**
 * This is the default implementation of {@link Export.DataCollector}. This
 * class serves a method to extract required data from <code>Result</code>
 * objects.
 *
 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
 */
public class DefaultDataCollector
implements Export.DataCollector
{
    /**
     * Logger used to log via log4j.
     */
    private   Logger log = Logger.getLogger(DefaultDataCollector.class);

    /**
     * ResultDescriptor used to extract specific attributes from
     * <code>Result</code> object.
     */
    protected ResultDescriptor rd;

    /**
     * Atrribute names in <code>Result</code> object which should be used for
     * data extraction.
     */
    protected String []        names;


    /**
     * Constructor
     *
     * @param names See {@link #names}
     */
    public DefaultDataCollector(String[] names) {
        this.names = names;
    }

    /**
     * This method initializes the <code>ResultDescriptor</code> rd for a faster
     * data extraction.
     *
     * @param res A <code>Result</code> object used to get its description.
     */
    public void init(Result res) {
        rd = res.getResultDescriptor();
    }

    /**
     * This method is used to extract the required data specified by {@link
     * #names}.
     *
     * @param result <code>Result</code> object.
     *
     * @return Extracted data.
     */
    public String[] getData(Result result)
    throws StateException {

        if (rd == null)
            init(result);

        List entries = new ArrayList();

        int[] indices = rd.getColumnIndices(names);
        for (int i = 0; i < names.length; ++i) {
            entries.add(result.getString(indices[i]));
        }

        return (String[]) entries.toArray((new String[entries.size()]));
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org