felix@2024: package de.intevation.flys.artifacts.model;
felix@2024: 
felix@2024: import java.util.ArrayList;
felix@2024: import java.util.List;
felix@2024: 
felix@2024: import de.intevation.artifacts.Artifact;
felix@2024: import de.intevation.artifacts.CallContext;
felix@2024: 
felix@2125: import de.intevation.artifactdatabase.state.Facet;
felix@2024: import de.intevation.artifactdatabase.state.DefaultFacet;
felix@2024: 
felix@2024: 
felix@2024: /**
felix@2024:  * Facet that writes artifact-uui and facet index on the blackboard,
felix@2024:  * delivers data if asked so.
felix@2024:  */
felix@2024: public class BlackboardDataFacet extends DefaultFacet {
felix@2024: 
felix@2024:     public BlackboardDataFacet() {}
felix@2024: 
felix@2024:     /** Do not instantiate a BlackboardDataFacet, subclass it instead. */
felix@2024:     public BlackboardDataFacet(int idx, String name, String description) {
felix@2024:         super(idx, name, description);
felix@2024:     }
felix@2024: 
felix@2739: 
felix@2122:     /** Do not instantiate a BlackboardDataFacet, subclass it instead. */
felix@2122:     public BlackboardDataFacet(String name, String description) {
felix@2122:         super(0, name, description);
felix@2122:     }
felix@2024: 
felix@2739: 
felix@2104:     /** Define key to which to respond when asked for 'blackboard'
felix@2104:      * (DataProvider)- data. */
felix@2104:     public String areaDataKey(Artifact art) {
felix@2104:         return art.identifier() + ":" + getName() + ":" + getIndex();
felix@2104:     }
felix@2104: 
felix@2104: 
felix@2104:     /** Hey, We can ArtifactUUID+:+FacetName+:+FacetIndex (i.e. getData)! */
felix@2405:     @Override
felix@2405:     public List getStaticDataProviderKeys(Artifact art) {
felix@2024:         List list = new ArrayList();
felix@2104:         list.add(areaDataKey(art));
felix@2024:         return list;
felix@2024:     }
felix@2024: 
felix@2024: 
felix@2024:     /**
felix@2024:      * Can provide whatever getData returns.
felix@2024:      * @param key      will respond on uuid+index
felix@2024:      * @param param    ignored
felix@2024:      * @param context  ignored
felix@2024:      * @return whatever getData delivers.
felix@2024:      */
felix@2405:     @Override
felix@2024:     public Object provideBlackboardData(Artifact artifact,
felix@2024:         Object key,
felix@2024:         Object param,
felix@2024:         CallContext context
felix@2024:     ) {
felix@2104:         if (key.equals(areaDataKey(artifact))) {
felix@2024:             return getData(artifact, context);
felix@2024:         }
felix@2024:         else {
felix@2024:             return null;
felix@2024:         }
felix@2024:     }
felix@2125: 
felix@2125:     /** Copy deeply. */
felix@2125:     @Override
felix@2125:     public Facet deepCopy() {
felix@2125:         BlackboardDataFacet copy = new BlackboardDataFacet();
felix@2125:         copy.set(this);
felix@2125:         return copy;
felix@2125:     }
felix@2024: }
felix@2024: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :