ingo@105: package de.intevation.flys.artifacts;
ingo@105:
ingo@693: import java.util.ArrayList;
ingo@693: import java.util.HashSet;
ingo@109: import java.util.List;
ingo@687: import java.util.Map;
ingo@693: import java.util.Set;
ingo@109:
ingo@105: import org.w3c.dom.Document;
ingo@110: import org.w3c.dom.Element;
ingo@124: import org.w3c.dom.Node;
ingo@105:
ingo@105: import org.apache.log4j.Logger;
ingo@105:
ingo@110: import de.intevation.artifacts.ArtifactNamespaceContext;
ingo@105: import de.intevation.artifacts.CallContext;
ingo@105:
ingo@110: import de.intevation.artifactdatabase.ProtocolUtils;
ingo@693: import de.intevation.artifactdatabase.state.DefaultOutput;
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;
ingo@112: import de.intevation.artifactdatabase.transition.TransitionEngine;
ingo@110:
ingo@109: import de.intevation.artifacts.common.utils.XMLUtils;
ingo@109:
ingo@385: import de.intevation.flys.model.Gauge;
ingo@362: import de.intevation.flys.model.River;
ingo@362:
ingo@134: import de.intevation.flys.artifacts.states.DefaultState;
ingo@109: import de.intevation.flys.artifacts.context.FLYSContext;
sascha@655:
ingo@687: import de.intevation.flys.artifacts.model.DischargeTables;
ingo@385: import de.intevation.flys.artifacts.model.MainValuesFactory;
ingo@385: import de.intevation.flys.artifacts.model.WQDay;
ingo@362: import de.intevation.flys.artifacts.model.WQKms;
ingo@362: import de.intevation.flys.artifacts.model.WstValueTable;
sascha@443: import de.intevation.flys.artifacts.model.WstValueTableFactory;
ingo@686: import de.intevation.flys.artifacts.model.Calculation1;
ingo@686: import de.intevation.flys.artifacts.model.Calculation2;
ingo@686: import de.intevation.flys.artifacts.model.Calculation3;
sascha@655: import de.intevation.flys.artifacts.model.Calculation4;
sascha@655: import de.intevation.flys.artifacts.model.Segment;
sascha@451:
sascha@451: import gnu.trove.TDoubleArrayList;
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:
ingo@105: /** The logger for this class */
ingo@105: private static Logger logger = Logger.getLogger(WINFOArtifact.class);
ingo@105:
ingo@105:
ingo@121: /** The name of the artifact.*/
ingo@121: public static final String ARTIFACT_NAME = "winfo";
ingo@121:
ingo@124: /** XPath */
ingo@124: public static final String XPATH_STATIC_UI ="/art:result/art:ui/art:static";
ingo@124:
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:
ingo@112: FLYSContext flysContext = null;
ingo@112: if (context instanceof FLYSContext) {
ingo@112: flysContext = (FLYSContext) context;
ingo@112: }
ingo@112: else {
ingo@112: flysContext = (FLYSContext) context.globalContext();
ingo@112: }
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