# HG changeset patch # User Felix Wolfsteller # Date 1352389846 -3600 # Node ID bdf321802d3dc914e5d891f85c76e570973a0fad # Parent e2d8f344491e475982df54de851d1f034bfc5a29 Add FlowVelocityMeasurementArtifact and -facet. Yet dummies. diff -r e2d8f344491e -r bdf321802d3d flys-artifacts/src/main/java/de/intevation/flys/artifacts/FlowVelocityMeasurementArtifact.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FlowVelocityMeasurementArtifact.java Thu Nov 08 16:50:46 2012 +0100 @@ -0,0 +1,184 @@ +package de.intevation.flys.artifacts; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.log4j.Logger; +import org.w3c.dom.Document; + +import de.intevation.artifactdatabase.state.DefaultOutput; +import de.intevation.artifactdatabase.state.Facet; +import de.intevation.artifactdatabase.state.FacetActivity; +import de.intevation.artifactdatabase.state.State; +import de.intevation.artifacts.Artifact; +import de.intevation.artifacts.ArtifactFactory; +import de.intevation.artifacts.CallMeta; +import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.flys.model.FlowVelocityMeasurement; +import de.intevation.flys.artifacts.model.minfo.FlowVelocityMeasurementFacet; +import de.intevation.flys.artifacts.model.minfo.FlowVelocityMeasurementFactory; +import de.intevation.flys.artifacts.states.StaticState; + +import de.intevation.flys.artifacts.model.FacetTypes; + + +/** Artefact to access flow velocity measurements. */ +public class FlowVelocityMeasurementArtifact +extends StaticFLYSArtifact +implements FacetTypes +{ + /** The logger for this class. */ + private static Logger logger = + Logger.getLogger(FlowVelocityMeasurementArtifact.class); + + /** Artifact key name. */ + private static final String NAME = "flowvelocitymeasurement"; + + /** Spawn only inactive facets. */ + static { + // TODO: Move to configuration. + FacetActivity.Registry.getInstance() + .register(NAME, FacetActivity.INACTIVE); + } + + /** Need to give the state an id. */ + public static final String STATIC_STATE_NAME = + "state.flowvelocitymeasurement.static"; + + /** One and only state to be in. */ + protected transient State state = null; + + + /** + * Trivial Constructor. + */ + public FlowVelocityMeasurementArtifact() { + logger.debug("FlowVelocityMeasurementArtifact.FlowVelocityMeasurementArtifact"); + } + + + /** Get artifact key name. */ + @Override + public String getName() { + return NAME; + } + + + /** Create a new state with bogus output. */ + protected State spawnState() { + state = new StaticState(STATIC_STATE_NAME); + List fs = facets.get(STATIC_STATE_NAME); + DefaultOutput output = new DefaultOutput( + "general", + "general", + "image/png", + fs, + "chart"); + + state.getOutputs().add(output); + + return state; + } + + + /** + * Gets called from factory, to set things up. + */ + @Override + public void setup( + String identifier, + ArtifactFactory factory, + Object context, + CallMeta callMeta, + Document data) + { + logger.debug("FlowVelocityMeasurementArtifact.setup"); + + state = new StaticState(STATIC_STATE_NAME); + + if (logger.isDebugEnabled()) { + logger.debug(XMLUtils.toString(data)); + } + + List fs = new ArrayList(); + String code = getDatacageIDValue(data); + + if (code != null) { + // parse code, interact with factory, add real facets. + // store relevant parts of code as data. + } + + Facet facet = new FlowVelocityMeasurementFacet( + FLOW_VELOCITY_MEASUREMENT, + "flowvelocity-name"); + + fs.add(facet); + facets.put(state.getID(), fs); + + spawnState(); + super.setup(identifier, factory, context, callMeta, data); + } + + + /** + * Get a list containing the one and only State. + * @param context ignored. + * @return list with one and only state. + */ + @Override + protected List getStates(Object context) { + ArrayList states = new ArrayList(); + states.add(getState()); + return states; + } + + + /** + * Get the "current" state (there is but one). + * @param cc ignored. + * @return the "current" (only possible) state. + */ + @Override + public State getCurrentState(Object cc) { + return getState(); + } + + + /** + * Get the only possible state. + * @return the state. + */ + protected State getState() { + return getState(null, null); + } + + + /** + * Get the state. + * @param context ignored. + * @param stateID ignored. + * @return the state. + */ + @Override + protected State getState(Object context, String stateID) { + return (state != null) + ? state + : spawnState(); + } + + + /** + * Called via setup. Overridden to avoid cloning all data. + * + * @param artifact The master-artifact. + */ + @Override + protected void initialize( + Artifact artifact, + Object context, + CallMeta meta) + { + logger.debug("initialize"); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : diff -r e2d8f344491e -r bdf321802d3d flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/FlowVelocityMeasurementFacet.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/FlowVelocityMeasurementFacet.java Thu Nov 08 16:50:46 2012 +0100 @@ -0,0 +1,55 @@ +package de.intevation.flys.artifacts.model.minfo; + +import de.intevation.artifacts.Artifact; +import de.intevation.artifacts.CallContext; +import de.intevation.flys.artifacts.FlowVelocityMeasurementArtifact; +import de.intevation.flys.artifacts.model.BlackboardDataFacet; +import de.intevation.flys.artifacts.model.FacetTypes; + + +/** Facet to show measured flow velocity. */ +public class FlowVelocityMeasurementFacet +extends BlackboardDataFacet +implements FacetTypes { + + public FlowVelocityMeasurementFacet(String description) { + this(FLOW_VELOCITY_MEASUREMENT, description); + } + + + public FlowVelocityMeasurementFacet(String name, String description) { + this.name = name; + this.description = description; + this.index = 0; + } + + + /** + * Returns the data this facet requires. + * + * @param artifact the owner artifact. + * @param context the CallContext (ignored). + * + * @return the data. + */ + @Override + public Object getData(Artifact artifact, CallContext context) { + FlowVelocityMeasurementArtifact staticData = + (FlowVelocityMeasurementArtifact) artifact; + //TODO: impl like return staticData.getVelocity(); + return null; + } + + + /** + * Create a deep copy of this Facet. + * @return a deep copy. + */ + @Override + public FlowVelocityMeasurementFacet deepCopy() { + FlowVelocityMeasurementFacet copy = new FlowVelocityMeasurementFacet(description); + copy.set(this); + return copy; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :