felix@2001: package de.intevation.flys.artifacts;
felix@2001: 
felix@2001: import java.util.ArrayList;
felix@2001: import java.util.List;
felix@2001: 
felix@2001: import org.apache.log4j.Logger;
felix@2001: 
felix@2001: import org.w3c.dom.Document;
felix@2001: 
felix@2001: import de.intevation.artifacts.Artifact;
felix@2001: import de.intevation.artifacts.ArtifactFactory;
felix@2001: import de.intevation.artifacts.CallMeta;
felix@2001: 
felix@2001: import de.intevation.flys.artifacts.model.AreaFacet;
felix@2001: 
felix@2001: 
felix@2001: import de.intevation.flys.artifacts.states.AreaCreationState;
felix@2001: import de.intevation.flys.artifacts.states.StaticState;
felix@2001: 
felix@2001: import de.intevation.artifactdatabase.state.Facet;
felix@2001: import de.intevation.artifactdatabase.state.State;
felix@2001: 
felix@2001: 
felix@2001: /**
felix@2001:  * Artifact describing the area between two WKms.
felix@2001:  */
felix@2001: public class AreaArtifact extends StaticFLYSArtifact {
felix@2001: 
felix@2001:     /** Name of Artifact. */
felix@2001:     public static final String AREA_ARTIFACT_NAME = "area_artifact";
felix@2001: 
felix@2018:     /** Dataitem: Facet name. Facets with this name will be created (important
felix@2018:      * to not have the area calculated in e.g. a CrossSection to be shown in
felix@2018:      * LongitudinalSection.  */
felix@2018:     protected static final String FACET_NAME = "area.facet";
felix@2018: 
felix@2001:     /** Name of state. */
felix@2001:     public static final String STATIC_STATE_NAME = "state.area_artifact";
felix@2001: 
felix@2001:     /** data item name to access upper curve. */
felix@2018:     protected static final String AREA_CURVE_OVER = "area.curve_over";
felix@2001: 
felix@2001:     /** data item name to access lower curve. */
felix@2018:     protected static final String AREA_CURVE_UNDER = "area.curve_under";
felix@2001: 
felix@2033:     /** data item name to access whether or not paint over and under. */
felix@2033:     protected static final String AREA_BETWEEN = "area.between";
felix@2033: 
felix@2010:     /** Name of state. */
felix@2018:     protected static final String AREA_NAME = "area.name";
felix@2010: 
felix@2001:     /** Own logger. */
felix@2001:     private static final Logger logger =
felix@2001:         Logger.getLogger(AreaArtifact.class);
felix@2001: 
felix@2001: 
felix@2001:     /** Return given name. */
felix@2001:     @Override
felix@2001:     public String getName() {
felix@2001:         return AREA_ARTIFACT_NAME;
felix@2001:     }
felix@2001: 
felix@2001: 
felix@2001:     /** Store ids, create an AreaFacet. */
felix@2001:     @Override
felix@2001:     public void setup(
felix@2001:         String          identifier,
felix@2001:         ArtifactFactory factory,
felix@2001:         Object          context,
felix@2001:         CallMeta        callMeta,
felix@2001:         Document        data)
felix@2001:     {
felix@2001:         logger.info("AreaArtifact.setup");
felix@2001: 
felix@2001:         super.setup(identifier, factory, context, callMeta, data);
felix@2001: 
felix@2010:         // TODO yet unused.
felix@2741:         String ids = getDatacageIDValue(data);
felix@2001: 
felix@2018:         // TODO this facet will be remodeled during next feed.
felix@2001:         List<Facet> fs = new ArrayList<Facet>();
felix@2018:         fs.add(new AreaFacet(0, "", "TODO: I am an AreaFacet"));
felix@2001: 
felix@2001:         AreaCreationState state = (AreaCreationState) getCurrentState(context);
felix@2001: 
felix@2001:         if (!fs.isEmpty()) {
felix@2001:             facets.put(getCurrentStateId(), fs);
felix@2001:         }
felix@2001:     }
felix@2001: 
felix@2001:     // TODO Data is not cached in this way.
felix@2001: 
felix@2001:     /** Do not copy data from daddyfact. */
felix@2001:     @Override
felix@2001:     protected void initialize(
felix@2001:         Artifact artifact,
felix@2001:         Object   context,
felix@2001:         CallMeta callMeta)
felix@2001:     {
felix@2001:         // do nothing
felix@2001:     }
felix@2001: 
felix@2033: 
felix@2018:     /**
felix@2018:      * Get name of facets to create.
felix@2018:      */
felix@2018:     public String getFacetName() {
felix@2018:         return getDataAsString(FACET_NAME);
felix@2018:     }
felix@2001: 
felix@2033: 
felix@2001:     /**
felix@2001:      * Get dataprovider key for the 'lower' curve (we got that information fed
felix@2001:      * from the client and store it as data).
felix@2001:      */
felix@2001:     public String getLowerDPKey() {
felix@2001:         return getDataAsString(AREA_CURVE_UNDER);
felix@2001:     }
felix@2001: 
felix@2001: 
felix@2001:     /**
felix@2033:      * True if the whole area between the two curves shall be filled.
felix@2033:      */
felix@2033:     public boolean getPaintBetween() {
felix@2033:         String val = getDataAsString(AREA_BETWEEN);
felix@2033: 
felix@2033:         return val != null && val.equals("true");
felix@2033:     }
felix@2033: 
felix@2033: 
felix@2033:     /**
felix@2001:      * Get dataprovider key for the 'upper' curve (we got that information fed
felix@2001:      * from the client and store it as data).
felix@2001:      */
felix@2001:     public String getUpperDPKey() {
felix@2001:         return getDataAsString(AREA_CURVE_OVER);
felix@2001:     }
felix@2001: 
felix@2001: 
felix@2010:     /** Return data item that is used to configure name of area. */
felix@2010:     public String getAreaName() {
felix@2010:         return getDataAsString(AREA_NAME);
felix@2010:     }
felix@2010: 
felix@2010: 
felix@2001:     /**
felix@2001:      * Create and return a new AreaCreationState with charting output.
felix@2001:      */
felix@2001:     @Override
felix@2001:     public State getCurrentState(Object cc) {
felix@2001:         final List<Facet> fs = facets.get(getCurrentStateId());
felix@2001: 
felix@2001:         AreaCreationState state = new AreaCreationState();
felix@2001: 
felix@2001:         StaticState.addDefaultChartOutput(state, "cross_section", fs);
felix@2001: 
felix@2001:         return state;
felix@2001:     }
felix@2001: 
felix@2001: 
felix@2001:     /**
felix@2001:      * Get a list containing the one and only State.
felix@2001:      * @param  context ignored.
felix@2001:      * @return list with one and only state.
felix@2001:      */
felix@2001:     @Override
felix@2001:     protected List<State> getStates(Object context) {
felix@2001:         ArrayList<State> states = new ArrayList<State>();
felix@2001:         states.add(getCurrentState(context));
felix@2001: 
felix@2001:         return states;
felix@2001:     }
felix@2001: 
felix@2033: 
felix@2001:     /** Trivia. */
felix@2001:     protected State getState(Object context, String stateID) {
felix@2001:         return getCurrentState(null);
felix@2001:     }
felix@2001: }
felix@2001: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :