sascha@2196: package de.intevation.flys.artifacts.model;
sascha@2196: 
sascha@2256: import java.util.List;
sascha@2407: import java.util.Collections;
sascha@2256: 
sascha@2196: import de.intevation.artifactdatabase.state.Facet;
sascha@2196: 
sascha@2196: import de.intevation.artifacts.Artifact;
sascha@2196: import de.intevation.artifacts.CallContext;
sascha@2196: 
sascha@2196: import de.intevation.flys.artifacts.FLYSArtifact;
sascha@2196: 
sascha@2196: import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
sascha@2196: 
sascha@2196: import org.apache.log4j.Logger;
sascha@2196: 
felix@2221: /** Facet for W-over-Ws. */
sascha@2196: public class ReferenceCurveFacet 
sascha@2196: extends      DataFacet
sascha@2196: {
sascha@2407:     private static Logger log = Logger.getLogger(ReferenceCurveFacet.class);
sascha@2256: 
sascha@2407:     public static final String CONTEXT_KEY = "reference.curve.axis.scale";
sascha@2196: 
sascha@2196:     public ReferenceCurveFacet() {
sascha@2196:     }
sascha@2196: 
sascha@2196:     public ReferenceCurveFacet(int index, String name, String description) {
sascha@2196:         super(index, name, description, ComputeType.ADVANCE, null, null);
sascha@2196:     }
sascha@2196: 
sascha@2196:     public ReferenceCurveFacet(
sascha@2196:         int         index,
sascha@2196:         String      name,
sascha@2196:         String      description,
sascha@2196:         ComputeType type,
sascha@2196:         String      stateID,
sascha@2196:         String      hash
sascha@2196:     ) {
sascha@2196:         super(index, name, description, type, hash, stateID);
sascha@2196:     }
sascha@2196: 
sascha@2196:     public Object getData(Artifact artifact, CallContext context) {
sascha@2196: 
sascha@2196:         if (log.isDebugEnabled()) {
sascha@2196:             log.debug("Get data for reference curve at index: " + index +
sascha@2196:                 " /stateId: " + stateId);
sascha@2196:         }
sascha@2196: 
felix@2283:         return getWWQQ(artifact, context);
sascha@2256:     }
sascha@2256: 
felix@2283:     protected WWQQ getWWQQ(Artifact artifact, CallContext context) {
sascha@2196:         FLYSArtifact winfo = (FLYSArtifact)artifact;
sascha@2196: 
sascha@2196:         CalculationResult res = (CalculationResult)
sascha@2196:             winfo.compute(context, hash, stateId, type, false);
sascha@2196: 
felix@2283:         return ((WWQQ [])res.getData())[index];
sascha@2196:     }
sascha@2196: 
sascha@2196:     @Override
sascha@2196:     public void set(Facet other) {
sascha@2196:         super.set(other);
felix@2405:         ReferenceCurveFacet o = (ReferenceCurveFacet)other;
felix@2405:         type                  = o.type;
felix@2405:         hash                  = o.hash;
felix@2405:         stateId               = o.stateId;
sascha@2196:     }
sascha@2196: 
sascha@2196:     /** Copy deeply. */
sascha@2196:     @Override
sascha@2196:     public Facet deepCopy() {
sascha@2196:         ReferenceCurveFacet copy = new ReferenceCurveFacet();
sascha@2196:         copy.set(this);
sascha@2196:         return copy;
sascha@2196:     }
sascha@2256: 
sascha@2256:     @Override
felix@2405:     public List getDataProviderKeys(Artifact art, CallContext context) {
sascha@2407: 
felix@2405:         // compute / get data
sascha@2407:         Object obj = context.getContextValue(CONTEXT_KEY);
felix@2405: 
felix@2405:         if (!(obj instanceof WWAxisTypes)) {
felix@2405:             obj = new WWAxisTypes(getWWQQ(art, context));
sascha@2407:             context.putContextValue(CONTEXT_KEY, obj);
felix@2405:         }
felix@2405:         else {
felix@2405:             ((WWAxisTypes)obj).classify(getWWQQ(art, context));
felix@2405:         }
sascha@2256: 
sascha@2407:         return Collections.emptyList();
sascha@2256:     }
sascha@2196: }
sascha@2196: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :