felix@2133: package de.intevation.flys.artifacts.model;
felix@2133: 
christian@3602: import de.intevation.artifactdatabase.state.Facet;
christian@3602: import de.intevation.artifacts.Artifact;
christian@3602: import de.intevation.artifacts.CallContext;
christian@3602: import de.intevation.artifacts.DataProvider;
christian@3602: import de.intevation.flys.artifacts.HYKArtifact;
christian@3602: import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
christian@3602: import de.intevation.flys.model.FastCrossSectionLine;
christian@3602: 
felix@2133: import java.util.List;
felix@2133: 
felix@2133: import org.apache.log4j.Logger;
felix@2133: 
felix@2133: 
felix@2133: /**
felix@2133:  * Trival Facet for HYKs
felix@2133:  */
felix@2133: public class HYKFacet
felix@2133: extends      DataFacet
felix@2133: implements   FacetTypes {
felix@2133: 
felix@2150:     /** House logger. */
felix@2133:     private static Logger logger = Logger.getLogger(HYKFacet.class);
felix@2133: 
felix@2133:     /** Trivial constructor, set (maybe localized) description. */
felix@2133:     public HYKFacet(int idx, String description) {
felix@2133:         super(idx, HYK, description, ComputeType.FEED, null, null);
felix@2133:     }
felix@2133: 
felix@2133: 
felix@2133:     /**
felix@2150:      * Set km from cross section- master to HYKArtifact, then fire up
felix@2150:      * computation.
felix@2150:      *
felix@2133:      * @param art artifact to get data from.
felix@2133:      * @param context ignored
felix@2133:      */
christian@3602:      @Override
christian@3602:     public Object getData(Artifact art, CallContext context) {
felix@2133:         logger.debug("HYKFacet.getData");
felix@2133: 
felix@2133:         String dataKey = CrossSectionFacet.BLACKBOARD_CS_MASTER_DATA;
felix@2133: 
felix@2133:         List<DataProvider> providers = context.getDataProvider(dataKey);
felix@2133:         if (providers.size() < 1) {
felix@2133:             logger.warn("Could not find Cross-Section data provider to get master cs km.");
felix@2133:             return null;
felix@2133:         }
sascha@3076: 
felix@2133:         FastCrossSectionLine crossSection = (FastCrossSectionLine) providers.get(0)
felix@2133:             .provideData(dataKey, null, context);
felix@2133: 
christian@3602:         if(crossSection == null) {
christian@3602:             logger.debug("getData: crossSection is null");
christian@3602:             return null;
christian@3602:         }
christian@3602: 
felix@2133:         double km = crossSection.getKm();
felix@2133:         logger.debug("HYKFacet.getData: Master Cross Section is at km: " + km);
felix@2133: 
felix@2133:         // Set this km at hyk artifact to be evaluated.
felix@2133:         HYKArtifact hyk = (HYKArtifact) art;
felix@2133:         hyk.setKm(km);
felix@2133: 
felix@2133:         return hyk.compute(context, hash, stateId, type, false);
felix@2133:     }
felix@2133: 
felix@2133: 
felix@2133:     /** Do a deep copy. */
sascha@3076:     @Override
felix@2133:     public Facet deepCopy() {
felix@2133:         HYKFacet copy = new HYKFacet(this.index, this.description);
felix@2133:         copy.set(this);
felix@2133:         return copy;
felix@2133:     }
felix@2133: }
felix@2133: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :