ingo@105: package de.intevation.flys.artifacts;
ingo@105:
sascha@1055: import de.intevation.artifactdatabase.ProtocolUtils;
ingo@109:
sascha@1055: import de.intevation.artifactdatabase.data.StateData;
ingo@105:
ingo@693: import de.intevation.artifactdatabase.state.Facet;
ingo@144: import de.intevation.artifactdatabase.state.Output;
ingo@110: import de.intevation.artifactdatabase.state.State;
ingo@110: import de.intevation.artifactdatabase.state.StateEngine;
sascha@1055:
ingo@112: import de.intevation.artifactdatabase.transition.TransitionEngine;
ingo@110:
sascha@1055: import de.intevation.artifacts.CallContext;
sascha@1055:
sascha@1055: import de.intevation.artifacts.common.ArtifactNamespaceContext;
sascha@1055:
ingo@109: import de.intevation.artifacts.common.utils.XMLUtils;
ingo@109:
sascha@1055: import de.intevation.flys.artifacts.context.FLYSContext;
sascha@1055:
sascha@1055: import de.intevation.flys.artifacts.model.Calculation1;
sascha@1055: import de.intevation.flys.artifacts.model.Calculation2;
sascha@1055: import de.intevation.flys.artifacts.model.Calculation3;
sascha@1055: import de.intevation.flys.artifacts.model.Calculation4;
sascha@1055: import de.intevation.flys.artifacts.model.Calculation;
sascha@1055: import de.intevation.flys.artifacts.model.CalculationResult;
sascha@1055: import de.intevation.flys.artifacts.model.DischargeTables;
sascha@1055: import de.intevation.flys.artifacts.model.MainValuesFactory;
sascha@1055: import de.intevation.flys.artifacts.model.RiverFactory;
sascha@1055: import de.intevation.flys.artifacts.model.Segment;
sascha@1055: import de.intevation.flys.artifacts.model.WQKms;
sascha@1055: import de.intevation.flys.artifacts.model.WstValueTable;
sascha@1055: import de.intevation.flys.artifacts.model.WstValueTableFactory;
sascha@1055:
sascha@1055: import de.intevation.flys.artifacts.states.DefaultState;
sascha@1055: import de.intevation.flys.artifacts.states.LocationDistanceSelect;
sascha@1055:
ingo@385: import de.intevation.flys.model.Gauge;
ingo@362: import de.intevation.flys.model.River;
ingo@362:
sascha@1055: import de.intevation.flys.utils.DoubleUtil;
ingo@1095: import de.intevation.flys.utils.FLYSUtils;
sascha@655:
sascha@1055: import gnu.trove.TDoubleArrayList;
sascha@451:
sascha@1055: import java.util.ArrayList;
sascha@1055: import java.util.Arrays;
sascha@1055: import java.util.Collections;
sascha@1055: import java.util.List;
sascha@1055: import java.util.Map;
sascha@1055:
sascha@1055: import org.apache.log4j.Logger;
sascha@1055:
sascha@1055: import org.w3c.dom.Document;
sascha@1055: import org.w3c.dom.Element;
sascha@1055: import org.w3c.dom.Node;
ingo@105:
ingo@105: /**
ingo@105: * The default WINFO artifact.
ingo@105: *
ingo@105: * @author Ingo Weinzierl
ingo@105: */
ingo@119: public class WINFOArtifact extends FLYSArtifact {
ingo@105:
felix@1029: /** The logger for this class. */
ingo@105: private static Logger logger = Logger.getLogger(WINFOArtifact.class);
ingo@105:
ingo@105:
felix@1029: /** The name of the artifact. */
ingo@121: public static final String ARTIFACT_NAME = "winfo";
ingo@121:
sascha@1055:
ingo@124: /** XPath */
ingo@124: public static final String XPATH_STATIC_UI ="/art:result/art:ui/art:static";
ingo@124:
sascha@1055: /** The default number of steps between the start end end of a selected Q
sascha@1055: * range.*/
sascha@1055: public static final int DEFAULT_Q_STEPS = 30;
sascha@1055:
sascha@1055: /** The default step width between the start end end kilometer.*/
sascha@1055: public static final double DEFAULT_KM_STEPS = 0.1;
sascha@1055:
ingo@121:
ingo@105: /**
ingo@105: * The default constructor.
ingo@105: */
ingo@105: public WINFOArtifact() {
ingo@105: }
ingo@105:
ingo@105:
ingo@105: /**
ingo@105: * This method returns a description of this artifact.
ingo@105: *
ingo@105: * @param data Some data.
ingo@128: * @param context The CallContext.
ingo@105: *
ingo@105: * @return the description of this artifact.
ingo@105: */
ingo@105: public Document describe(Document data, CallContext context) {
ingo@119: logger.debug("Describe: the current state is: " + getCurrentStateId());
ingo@105:
ingo@624: if (logger.isDebugEnabled()) {
ingo@624: dumpArtifact();
ingo@624: }
ingo@624:
sascha@706: FLYSContext flysContext = getFlysContext(context);
ingo@110:
ingo@112: StateEngine stateEngine = (StateEngine) flysContext.get(
ingo@112: FLYSContext.STATE_ENGINE_KEY);
ingo@112:
ingo@112: TransitionEngine transitionEngine = (TransitionEngine) flysContext.get(
ingo@112: FLYSContext.TRANSITION_ENGINE_KEY);
ingo@112:
ingo@112: List reachable = transitionEngine.getReachableStates(
ingo@355: this, getCurrentState(context), stateEngine);
ingo@112:
ingo@112: Document description = XMLUtils.newDocument();
ingo@110: XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
ingo@110: description,
ingo@110: ArtifactNamespaceContext.NAMESPACE_URI,
ingo@110: ArtifactNamespaceContext.NAMESPACE_PREFIX);
ingo@110:
ingo@110: Element root = ProtocolUtils.createRootNode(creator);
ingo@115: description.appendChild(root);
ingo@115:
ingo@119: State current = getCurrentState(context);
ingo@119:
ingo@110: ProtocolUtils.appendDescribeHeader(creator, root, identifier(), hash());
ingo@119: ProtocolUtils.appendState(creator, root, current);
ingo@112: ProtocolUtils.appendReachableStates(creator, root, reachable);
ingo@110:
ingo@303: Element name = ProtocolUtils.createArtNode(
ingo@303: creator, "name",
ingo@303: new String[] { "value" },
ingo@303: new String[] { getName() });
ingo@303:
ingo@127: Element ui = ProtocolUtils.createArtNode(
ingo@127: creator, "ui", null, null);
ingo@110:
ingo@127: Element staticUI = ProtocolUtils.createArtNode(
ingo@127: creator, "static", null, null);
ingo@127:
ingo@144: Element outs = ProtocolUtils.createArtNode(
ingo@144: creator, "outputmodes", null, null);
ingo@144: appendOutputModes(description, outs, context, identifier());
ingo@144:
ingo@134: appendStaticUI(description, staticUI, context, identifier());
ingo@128:
ingo@127: Element dynamic = current.describe(
ingo@306: this,
ingo@124: description,
ingo@127: root,
ingo@127: context,
ingo@127: identifier());
ingo@127:
ingo@144: if (dynamic != null) {
ingo@144: ui.appendChild(dynamic);
ingo@144: }
ingo@144:
ingo@128: ui.appendChild(staticUI);
ingo@144:
ingo@303: root.appendChild(name);
ingo@127: root.appendChild(ui);
ingo@144: root.appendChild(outs);
ingo@124:
ingo@110: return description;
ingo@105: }
ingo@121:
ingo@121:
ingo@121: /**
ingo@121: * Returns the name of the concrete artifact.
ingo@121: *
ingo@121: * @return the name of the concrete artifact.
ingo@121: */
ingo@121: public String getName() {
ingo@121: return ARTIFACT_NAME;
ingo@121: }
ingo@124:
ingo@124:
ingo@144: protected void appendOutputModes(
ingo@144: Document doc,
ingo@144: Element outs,
ingo@144: CallContext context,
ingo@144: String uuid)
ingo@144: {
sascha@661: List stateIds = getPreviousStateIds();
ingo@144:
ingo@144: XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
ingo@144: doc,
ingo@144: ArtifactNamespaceContext.NAMESPACE_URI,
ingo@144: ArtifactNamespaceContext.NAMESPACE_PREFIX);
ingo@144:
ingo@144: FLYSContext flysContext = getFlysContext(context);
ingo@144: StateEngine engine = (StateEngine) flysContext.get(
ingo@144: FLYSContext.STATE_ENGINE_KEY);
ingo@144:
ingo@144: for (String stateId: stateIds) {
ingo@144: logger.debug("Append output modes for state: " + stateId);
ingo@693: DefaultState state = (DefaultState) engine.getState(stateId);
ingo@144:
ingo@144: List