felix@1116: package de.intevation.flys.artifacts.model;
felix@1116: 
felix@1967: import java.util.ArrayList;
felix@1967: import java.util.List;
felix@1967: 
felix@1116: import org.apache.log4j.Logger;
felix@1116: 
felix@1116: import de.intevation.artifacts.Artifact;
felix@1116: import de.intevation.artifacts.CallContext;
felix@1116: 
felix@1116: import de.intevation.artifactdatabase.state.Facet;
felix@1116: 
felix@1967: import de.intevation.flys.artifacts.CrossSectionArtifact;
felix@1116: 
felix@1116: import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
felix@1116: 
felix@1116: 
felix@1116: /**
felix@1967:  * Trival Facet for Cross Sections (profiles).
felix@1116:  */
felix@1116: public class CrossSectionFacet
felix@2301: extends      BlackboardDataFacet
felix@1116: implements   FacetTypes {
felix@1116: 
felix@1967:     public static String BLACKBOARD_CS_MASTER_DATA
felix@1967:         = "crosssection.masterprofile.data";
felix@1967: 
felix@3272:     public static String BLACKBOARD_CS_PREV_KM
felix@3272:         = "crosssection.masterprofile.km.prev";
felix@3272: 
felix@3272:     public static String BLACKBOARD_CS_NEXT_KM
felix@3272:         = "crosssection.masterprofile.km.next";
felix@3272: 
felix@3272: 
felix@1116:     private static Logger logger = Logger.getLogger(CrossSectionFacet.class);
felix@1116: 
felix@1138:     protected ComputeType type;
felix@1116: 
felix@1967: 
felix@1116:     /** Trivial constructor, set (maybe localized) description. */
felix@1803:     public CrossSectionFacet(int idx, String description) {
felix@1803:         super(idx, CROSS_SECTION, description);
felix@1138:         type = ComputeType.ADVANCE;
felix@1116:     }
felix@1116: 
felix@1116: 
felix@1967:     /** Tell world we know about crosssection masters data and its index. */
felix@2405:     public List getStaticDataProviderKeys(Artifact art) {
felix@1967:         CrossSectionArtifact artifact = (CrossSectionArtifact) art;
felix@1967:         List keys = new ArrayList();
felix@1967:         if (artifact.isMaster()) {
felix@1967:             keys.add(BLACKBOARD_CS_MASTER_DATA);
felix@3272:             keys.add(BLACKBOARD_CS_PREV_KM);
felix@3272:             keys.add(BLACKBOARD_CS_NEXT_KM);
felix@1967:         }
felix@2002:         keys.add(artifact.identifier() + getIndex());
felix@2405:         keys.addAll(super.getStaticDataProviderKeys(art));
felix@1967:         return keys;
felix@1967:     }
felix@1967: 
felix@1967: 
felix@1116:     /**
felix@1967:      * Can provide the master cross section lines or its index.
felix@1967:      * @param artifact crosssection-artifact
felix@1967:      * @param key      will respond on BLACKBOARD_CS_MASTER_DATA
felix@1967:      * @param param    ignored
felix@1967:      * @param context  ignored
felix@1967:      * @return data from artifact (cross section master track).
felix@1116:      */
felix@1967:     public Object provideBlackboardData(Artifact artifact,
felix@1967:         Object key,
felix@1967:         Object param,
felix@1967:         CallContext context
felix@1967:     ) {
felix@1967:         CrossSectionArtifact crossSection = (CrossSectionArtifact) artifact;
felix@1967: 
felix@1967:         if (key.equals(BLACKBOARD_CS_MASTER_DATA)) {
felix@1967:             return crossSection.searchCrossSectionLine();
felix@1967:         }
felix@2002:         else if (key.equals(artifact.identifier() + getIndex())) {
felix@2002:             return getData(artifact, context);
felix@2002:         }
felix@3272:         else if (key.equals(BLACKBOARD_CS_NEXT_KM)) {
felix@3272:             return crossSection.getNextKm();
felix@3272:         }
felix@3272:         else if (key.equals(BLACKBOARD_CS_PREV_KM)) {
felix@3272:             return crossSection.getPrevKm();
felix@3272:         }
felix@1967:         else {
felix@2301:             Object obj = super.provideBlackboardData(artifact, key, param,
felix@2301:                 context);
felix@2301:             if (obj == null) {
felix@2301:                 logger.warn("Cannot provide data for key: " + key);
felix@2301:             }
felix@2301:             return obj;
felix@1967:         }
felix@1967:     }
felix@1967: 
felix@1967: 
felix@1967:     /**
felix@1967:      * Gets Cross Section (profile).
felix@1967:      * @param art artifact to get data from.
felix@1967:      * @param context ignored
felix@1967:      */
felix@1967:     public Object getData(Artifact art, CallContext context) {
felix@1116:         logger.debug("Get data for cross section");
felix@1116: 
felix@1967:         CrossSectionArtifact artifact = (CrossSectionArtifact)art;
felix@1116: 
felix@1967:         return artifact.getCrossSectionData();
felix@1116:     }
felix@1116: 
felix@1138: 
felix@1138:     /** Do a deep copy. */
sascha@3076:     @Override
felix@1116:     public Facet deepCopy() {
felix@1803:         CrossSectionFacet copy = new CrossSectionFacet(this.index, this.description);
felix@1116:         copy.set(this);
felix@1116:         return copy;
felix@1116:     }
felix@1116: }
felix@1116: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :