view flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ReferenceCurveFacet.java @ 5549:38acd82feeac

Added bed quality facets to flow velocity datacage. * Added facets in artifact config. * Added datacage config for bedquality facets. * Added ouput methods for bedquality facets to generator.
author Raimund Renkert <rrenkert@intevation.de>
date Thu, 04 Apr 2013 10:55:46 +0200
parents 5642a83420f2
children
line wrap: on
line source
package de.intevation.flys.artifacts.model;

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

import de.intevation.artifactdatabase.state.Facet;

import de.intevation.artifacts.Artifact;
import de.intevation.artifacts.CallContext;

import de.intevation.flys.artifacts.FLYSArtifact;
import de.intevation.flys.artifacts.WINFOArtifact;

import de.intevation.flys.artifacts.states.DefaultState.ComputeType;

import org.apache.log4j.Logger;


/** Facet for W-over-Ws. */
public class ReferenceCurveFacet
extends      DataFacet
{
    private static Logger log = Logger.getLogger(ReferenceCurveFacet.class);

    public static final String CONTEXT_KEY = "reference.curve.axis.scale";

    /** Blackboard data provider key for reference curves start km. */
    public static final String BB_REFERENCECURVE_STARTKM =
        "reference_curve.startkm";

    /** Blackboard data provider key for reference curves end kms. */
    public static final String BB_REFERENCECURVE_ENDKMS =
        "reference_curve.endkms";


    public ReferenceCurveFacet() {
    }


    public ReferenceCurveFacet(int index, String name, String description) {
        super(index, name, description, ComputeType.ADVANCE, null, null);
    }


    public ReferenceCurveFacet(
        int         index,
        String      name,
        String      description,
        ComputeType type,
        String      stateID,
        String      hash
    ) {
        super(index, name, description, type, hash, stateID);
    }


    public Object getData(Artifact artifact, CallContext context) {

        if (log.isDebugEnabled()) {
            log.debug("Get data for reference curve at index: " + index +
                " /stateId: " + stateId);
        }

        return getWWQQ(artifact, context);
    }


   /**
     * Can provide parameters of reference curve
     * @param key      will respond on BB_REFERENCECURVE START/ENDKMS
     * @param param    ignored
     * @param context  ignored
     * @return whatever parameters for reference curve
     */
    @Override
    public Object provideBlackboardData(Artifact artifact,
        Object key,
        Object param,
        CallContext context
    ) {
        WINFOArtifact winfo = (WINFOArtifact) artifact;
        if (key.equals(BB_REFERENCECURVE_STARTKM)) {
            return winfo.getReferenceStartKm();
        }
        else if (key.equals(BB_REFERENCECURVE_ENDKMS)) {
            return winfo.getReferenceEndKms();
        }
        else {
            return null;
        }
    }


    protected WWQQ getWWQQ(Artifact artifact, CallContext context) {
        FLYSArtifact winfo = (FLYSArtifact)artifact;

        CalculationResult res = (CalculationResult)
            winfo.compute(context, hash, stateId, type, false);

        return ((WWQQ [])res.getData())[index];
    }


    @Override
    public void set(Facet other) {
        super.set(other);
        ReferenceCurveFacet o = (ReferenceCurveFacet)other;
        type                  = o.type;
        hash                  = o.hash;
        stateId               = o.stateId;
    }


    /** Copy deeply. */
    @Override
    public Facet deepCopy() {
        ReferenceCurveFacet copy = new ReferenceCurveFacet();
        copy.set(this);
        return copy;
    }


    @Override
    public List getStaticDataProviderKeys(Artifact art) {
        List list = new ArrayList();
        list.add(BB_REFERENCECURVE_STARTKM);
        list.add(BB_REFERENCECURVE_ENDKMS);
        return list;
    }


    @Override
    public List getDataProviderKeys(Artifact art, CallContext context) {

        // compute / get data
        Object obj = context.getContextValue(CONTEXT_KEY);

        if (!(obj instanceof WWAxisTypes)) {
            obj = new WWAxisTypes(getWWQQ(art, context));
            context.putContextValue(CONTEXT_KEY, obj);
        }
        else {
            ((WWAxisTypes)obj).classify(getWWQQ(art, context));
        }

        return getStaticDataProviderKeys(art);//Collections.emptyList();
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org