felix@4452: package de.intevation.flys.artifacts; felix@4452: felix@4452: import java.util.ArrayList; felix@4452: import java.util.List; felix@4452: felix@4452: import org.apache.log4j.Logger; felix@4452: import org.w3c.dom.Document; felix@4452: felix@4452: import de.intevation.artifactdatabase.state.DefaultOutput; felix@4452: import de.intevation.artifactdatabase.state.Facet; felix@4452: import de.intevation.artifactdatabase.state.FacetActivity; felix@4452: import de.intevation.artifactdatabase.state.State; felix@4452: import de.intevation.artifacts.Artifact; felix@4452: import de.intevation.artifacts.ArtifactFactory; felix@4452: import de.intevation.artifacts.CallMeta; felix@4452: import de.intevation.artifacts.common.utils.XMLUtils; felix@4452: import de.intevation.flys.model.FlowVelocityMeasurement; felix@4464: import de.intevation.flys.model.FlowVelocityMeasurementValue; felix@4452: import de.intevation.flys.artifacts.model.minfo.FlowVelocityMeasurementFacet; felix@4452: import de.intevation.flys.artifacts.model.minfo.FlowVelocityMeasurementFactory; felix@4452: import de.intevation.flys.artifacts.states.StaticState; felix@4452: felix@4452: import de.intevation.flys.artifacts.model.FacetTypes; felix@4452: felix@4452: felix@4452: /** Artefact to access flow velocity measurements. */ felix@4452: public class FlowVelocityMeasurementArtifact felix@4452: extends StaticFLYSArtifact felix@4452: implements FacetTypes felix@4452: { felix@4452: /** The logger for this class. */ felix@4452: private static Logger logger = felix@4452: Logger.getLogger(FlowVelocityMeasurementArtifact.class); felix@4452: felix@4452: /** Artifact key name. */ felix@4452: private static final String NAME = "flowvelocitymeasurement"; felix@4452: felix@4452: /** Spawn only inactive facets. */ felix@4452: static { felix@4452: // TODO: Move to configuration. felix@4452: FacetActivity.Registry.getInstance() felix@4452: .register(NAME, FacetActivity.INACTIVE); felix@4452: } felix@4452: felix@4452: /** Need to give the state an id. */ felix@4452: public static final String STATIC_STATE_NAME = felix@4452: "state.flowvelocitymeasurement.static"; felix@4452: felix@4452: /** One and only state to be in. */ felix@4452: protected transient State state = null; felix@4452: felix@4464: protected String DATA_NAME = "ID"; felix@4452: felix@4452: /** felix@4452: * Trivial Constructor. felix@4452: */ felix@4452: public FlowVelocityMeasurementArtifact() { felix@4452: logger.debug("FlowVelocityMeasurementArtifact.FlowVelocityMeasurementArtifact"); felix@4452: } felix@4452: felix@4452: felix@4452: /** Get artifact key name. */ felix@4452: @Override felix@4452: public String getName() { felix@4452: return NAME; felix@4452: } felix@4452: felix@4452: felix@4452: /** Create a new state with bogus output. */ felix@4452: protected State spawnState() { felix@4452: state = new StaticState(STATIC_STATE_NAME); felix@4452: List fs = facets.get(STATIC_STATE_NAME); felix@4452: DefaultOutput output = new DefaultOutput( felix@4452: "general", felix@4452: "general", felix@4452: "image/png", felix@4452: fs, felix@4452: "chart"); felix@4452: felix@4452: state.getOutputs().add(output); felix@4452: felix@4452: return state; felix@4452: } felix@4452: felix@4452: felix@4452: /** felix@4452: * Gets called from factory, to set things up. felix@4452: */ felix@4452: @Override felix@4452: public void setup( felix@4452: String identifier, felix@4452: ArtifactFactory factory, felix@4452: Object context, felix@4452: CallMeta callMeta, felix@4452: Document data) felix@4452: { felix@4452: logger.debug("FlowVelocityMeasurementArtifact.setup"); felix@4452: felix@4452: state = new StaticState(STATIC_STATE_NAME); felix@4452: felix@4452: if (logger.isDebugEnabled()) { felix@4452: logger.debug(XMLUtils.toString(data)); felix@4452: } felix@4452: felix@4452: List fs = new ArrayList(); felix@4452: String code = getDatacageIDValue(data); felix@4452: felix@4452: if (code != null) { felix@4452: // parse code, interact with factory, add real facets. felix@4452: // store relevant parts of code as data. felix@4464: Facet facet = new FlowVelocityMeasurementFacet( felix@4464: FLOW_VELOCITY_MEASUREMENT, felix@4464: "flowvelocity-name"); felix@4464: felix@4464: fs.add(facet); felix@4464: facets.put(state.getID(), fs); felix@4464: addStringData(DATA_NAME, code); felix@4452: } felix@4452: felix@4452: spawnState(); felix@4452: super.setup(identifier, factory, context, callMeta, data); felix@4452: } felix@4452: felix@4452: felix@4452: /** felix@4452: * Get a list containing the one and only State. felix@4452: * @param context ignored. felix@4452: * @return list with one and only state. felix@4452: */ felix@4452: @Override felix@4452: protected List getStates(Object context) { felix@4452: ArrayList states = new ArrayList(); felix@4452: states.add(getState()); felix@4452: return states; felix@4452: } felix@4452: felix@4452: felix@4452: /** felix@4452: * Get the "current" state (there is but one). felix@4452: * @param cc ignored. felix@4452: * @return the "current" (only possible) state. felix@4452: */ felix@4452: @Override felix@4452: public State getCurrentState(Object cc) { felix@4452: return getState(); felix@4452: } felix@4452: felix@4452: felix@4452: /** felix@4452: * Get the only possible state. felix@4452: * @return the state. felix@4452: */ felix@4452: protected State getState() { felix@4452: return getState(null, null); felix@4452: } felix@4452: felix@4452: felix@4452: /** felix@4452: * Get the state. felix@4452: * @param context ignored. felix@4452: * @param stateID ignored. felix@4452: * @return the state. felix@4452: */ felix@4452: @Override felix@4452: protected State getState(Object context, String stateID) { felix@4452: return (state != null) felix@4452: ? state felix@4452: : spawnState(); felix@4452: } felix@4452: felix@4452: felix@4452: /** felix@4452: * Called via setup. Overridden to avoid cloning all data. felix@4452: * felix@4452: * @param artifact The master-artifact. felix@4452: */ felix@4452: @Override felix@4452: protected void initialize( felix@4452: Artifact artifact, felix@4452: Object context, felix@4452: CallMeta meta) felix@4452: { felix@4452: logger.debug("initialize"); felix@4452: } felix@4464: felix@4464: felix@4464: /** Get the db-unbound flow velocity measurement value with given felix@4464: * id. */ felix@4464: public FlowVelocityMeasurementValue.FastFlowVelocityMeasurementValue felix@4464: getFlowVelocityMeasurementValue() felix@4464: { felix@4464: return FlowVelocityMeasurementFactory.getFlowVelocityMeasurement( felix@4464: Integer.parseInt(getDataAsString(DATA_NAME))); felix@4464: } felix@4452: } felix@4452: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :