view flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSDBArtifact.java @ 1850:0463e1f80bfd

Handle MainValue Facets in Duration Curve Diagrams. flys-artifacts/trunk@3194 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 09 Nov 2011 13:13:01 +0000
parents 5364b86a0880
children e372934f0c42
line wrap: on
line source
package de.intevation.flys.artifacts;

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

import org.w3c.dom.Document;

import org.apache.log4j.Logger;

import com.vividsolutions.jts.geom.Envelope;

import de.intevation.artifacts.Artifact;
import de.intevation.artifacts.ArtifactFactory;
import de.intevation.artifacts.CallMeta;

import de.intevation.artifactdatabase.data.DefaultStateData;
import de.intevation.artifactdatabase.state.Facet;
import de.intevation.artifactdatabase.state.State;

import de.intevation.artifacts.common.ArtifactNamespaceContext;
import de.intevation.artifacts.common.utils.XMLUtils;

import de.intevation.flys.artifacts.states.DefaultState;
import de.intevation.flys.artifacts.model.WMSDBLayerFacet;


public abstract class WMSDBArtifact extends StaticFLYSArtifact {

    private static final Logger logger = Logger.getLogger(WMSDBArtifact.class);

    public static final String XPATH_IDS = "/art:action/art:ids/@value";


    @Override
    public void setup(
        String          identifier,
        ArtifactFactory factory,
        Object          context,
        CallMeta        callMeta,
        Document        data)
    {
        logger.debug("WMSDBArtifact.setup");

        super.setup(identifier, factory, context, callMeta, data);

        String ids = XMLUtils.xpathString(
            data, XPATH_IDS, ArtifactNamespaceContext.INSTANCE);

        if (ids != null && ids.length() > 0) {
            addData("ids", new DefaultStateData("ids", null, null, ids));
        }
        else {
            throw new IllegalArgumentException("No attribute 'ids' found!");
        }

        List<Facet> fs = new ArrayList<Facet>();

        WMSDBState state = (WMSDBState) getCurrentState(context);
        state.computeInit(this, hash(), context, callMeta, fs);

        if (!fs.isEmpty()) {
            facets.put(getCurrentStateId(), fs);
        }
    }


    @Override
    protected void initialize(
        Artifact artifact,
        Object   context,
        CallMeta callMeta)
    {
        // do nothing
    }


    /**
     * Get a list containing the one and only State.
     * @param  context ignored.
     * @return list with one and only state.
     */
    @Override
    protected List<State> getStates(Object context) {
        ArrayList<State> states = new ArrayList<State>();
        states.add(getCurrentState(context));

        return states;
    }



    public static abstract class WMSDBState extends DefaultState {
        private static final Logger logger = Logger.getLogger(WMSDBState.class);

        protected WMSDBArtifact artifact;

        public WMSDBState(WMSDBArtifact artifact) {
            this.artifact = artifact;
        }

        @Override
        public Object computeInit(
            FLYSArtifact artifact,
            String       hash,
            Object       context,
            CallMeta     meta,
            List<Facet>  facets
        ) {
            logger.debug("WMSDBState.computeInit");

            String type = getFacetType();

            WMSDBLayerFacet facet = new WMSDBLayerFacet(
                0,
                type,
                getTitle(meta),
                ComputeType.INIT,
                getID(), hash,
                getUrl());

            String name = artifact.identifier() + "-" + type;

            facet.addLayer(name);
            facet.setExtent(getExtent());
            facet.setSrid(getSrid());
            facet.setData(getDataString());
            facet.setFilter(getFilter());
            facet.setGeometryType(getGeometryType());

            facets.add(facet);

            return null;
        }

        protected abstract String getFacetType();

        protected abstract String getTitle(CallMeta meta);

        protected abstract String getUrl();

        protected abstract String getSrid();

        protected abstract Envelope getExtent();

        protected abstract String getFilter();

        protected abstract String getDataString();

        protected abstract String getGeometryType();
    } // end of WMSDBState
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org