felix@2001: package de.intevation.flys.artifacts.model;
felix@2001:
felix@2001: import java.util.List;
felix@2001:
felix@2001: import org.apache.log4j.Logger;
felix@2001:
felix@2001: import de.intevation.artifacts.Artifact;
felix@2001: import de.intevation.artifacts.CallContext;
felix@2001:
felix@2001: import de.intevation.artifactdatabase.state.DefaultFacet;
felix@2001: import de.intevation.artifactdatabase.state.Facet;
felix@2001:
felix@2001: import de.intevation.artifacts.DataProvider;
felix@2001:
felix@2001: import de.intevation.flys.artifacts.AreaArtifact;
felix@2001:
felix@2001:
felix@2001: /**
felix@2001: * Trival Facet for areas.
felix@2018: * Note that this Facet comes in two "types" (names):
felix@2018: *
felix@2018: * - CROSS_SECTION_AREA (cross_section.area) and
felix@2018: * - LONGITUDINAL_SECTION_AREA (longitudinal.area
felix@2018: *
felix@2018: * This is to support different diagram types without being painted in both
felix@2018: * at the same time. The name has to be given when constructing.
felix@2001: */
felix@2001: public class AreaFacet
felix@2001: extends DefaultFacet
felix@2001: implements FacetTypes {
felix@2001:
felix@2001: private static Logger logger = Logger.getLogger(AreaFacet.class);
felix@2001:
felix@2018: /**
felix@2018: * Constructor, set (maybe localized) description and name.
felix@2018: * @param idx Index given when querying artifact for data.
felix@2018: * @param name important to discern areas in different diagram types.
felix@2018: */
felix@2018: public AreaFacet(int idx, String name, String description) {
felix@2018: super(idx, name, description);
felix@2001: }
felix@2001:
felix@2001:
felix@2001: /**
felix@2001: * Gets Cross Section (profile).
felix@2001: * @param art artifact to get data from.
felix@2001: * @param context ignored
felix@2001: */
felix@2001: public Object getData(Artifact art, CallContext context) {
felix@2010: logger.debug("Get data for area.");
felix@2001:
felix@2001: // Get information from artifact about which
felix@2001: // info to grab from blackboard.
felix@2001: //
felix@2001: // All compatible facets should provide their data
felix@2001: // under the key (Artifact-UUID + Facet-Index).
felix@2001: AreaArtifact artifact = (AreaArtifact) art;
felix@2001: Object lowerData = null;
felix@2001: Object upperData = null;
felix@2001:
felix@2001: List providers = context.
felix@2001: getDataProvider(artifact.getLowerDPKey());
felix@2001: if (providers.size() < 1) {
felix@2018: logger.warn("No 'lower' provider given for area [" +
felix@2018: artifact.getLowerDPKey() + "]");
felix@2001: }
felix@2001: else {
felix@2001: lowerData = providers.get(0).provideData(
felix@2001: artifact.getLowerDPKey(), null, context);
felix@2001: }
felix@2001:
felix@2001: providers = context.getDataProvider(artifact.getUpperDPKey());
felix@2001: if (providers.size() < 1) {
felix@2018: logger.warn("No 'upper' provider given for area [" +
felix@2018: artifact.getUpperDPKey() + "]");
felix@2001: }
felix@2001: else {
felix@2001: upperData = providers.get(0).provideData(
felix@2001: artifact.getUpperDPKey(), null, context);
felix@2001: }
felix@2001:
felix@2001: if (upperData == null && lowerData == null) {
felix@2010: logger.warn("Not given 'upper' and 'lower' for area");
felix@2001: }
felix@2001:
felix@2033: return new Object[] {lowerData,
felix@2033: upperData,
felix@2033: Boolean.valueOf(artifact.getPaintBetween())};
felix@2001: }
felix@2001:
felix@2001:
felix@2001: /** Do a deep copy. */
felix@2001: @Override
felix@2001: public Facet deepCopy() {
felix@2018: AreaFacet copy = new AreaFacet(this.index, this.name, this.description);
felix@2001: copy.set(this);
felix@2001: return copy;
felix@2001: }
felix@2001: }
felix@2001: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :