ingo@2693: package de.intevation.flys.artifacts;
ingo@2693:
ingo@2693: import de.intevation.artifactdatabase.ProtocolUtils;
ingo@2693:
ingo@2693: import de.intevation.artifactdatabase.state.Output;
ingo@2693: import de.intevation.artifactdatabase.state.State;
ingo@2693: import de.intevation.artifactdatabase.state.StateEngine;
ingo@2693:
ingo@2693: import de.intevation.artifactdatabase.transition.TransitionEngine;
ingo@2693:
ingo@2693: import de.intevation.artifacts.CallContext;
ingo@2693: import de.intevation.artifacts.Message;
ingo@2693:
ingo@2693: import de.intevation.artifacts.common.ArtifactNamespaceContext;
ingo@2693:
ingo@2693: import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
ingo@2693:
ingo@2693: import de.intevation.artifacts.common.utils.XMLUtils;
ingo@2693:
ingo@2693: import de.intevation.flys.artifacts.context.FLYSContext;
ingo@2693:
ingo@2693: import de.intevation.flys.artifacts.model.CalculationMessage;
ingo@2693: import de.intevation.flys.artifacts.model.FacetTypes;
ingo@2693:
ingo@2693: import de.intevation.flys.artifacts.states.DefaultState;
ingo@2713: import de.intevation.flys.artifacts.states.SoundingsSelect;
ingo@2693:
ingo@2693: import de.intevation.flys.utils.FLYSUtils;
ingo@2693:
ingo@2713: import gnu.trove.TIntArrayList;
ingo@2713:
ingo@2693: import java.util.LinkedList;
ingo@2693: import java.util.List;
ingo@2693:
ingo@2693: import org.apache.log4j.Logger;
ingo@2693:
ingo@2693: import org.w3c.dom.Document;
ingo@2693: import org.w3c.dom.Element;
ingo@2693: import org.w3c.dom.Node;
ingo@2693:
ingo@2693: /**
ingo@2693: * The default MINFO artifact.
ingo@2693: *
ingo@2693: * @author Ingo Weinzierl
ingo@2693: */
ingo@2693: public class MINFOArtifact
ingo@2693: extends FLYSArtifact
ingo@2693: implements FacetTypes {
ingo@2693:
ingo@2693: /** The logger for this class. */
ingo@2693: private static Logger logger = Logger.getLogger(MINFOArtifact.class);
ingo@2693:
ingo@2693: /** The name of the artifact. */
ingo@2693: public static final String ARTIFACT_NAME = "minfo";
ingo@2693:
ingo@2693: /** XPath */
ingo@2693: public static final String XPATH_STATIC_UI ="/art:result/art:ui/art:static";
ingo@2693:
ingo@2693:
ingo@2693: /**
ingo@2693: * The default constructor.
ingo@2693: */
ingo@2693: public MINFOArtifact() {
ingo@2693: }
ingo@2693:
ingo@2693:
ingo@2693: /**
ingo@2693: * This method returns a description of this artifact.
ingo@2693: *
ingo@2693: * @param data Some data.
ingo@2693: * @param context The CallContext.
ingo@2693: *
ingo@2693: * @return the description of this artifact.
ingo@2693: */
ingo@2693: public Document describe(Document data, CallContext context) {
ingo@2693: logger.debug("Describe: the current state is: " + getCurrentStateId());
ingo@2693:
ingo@2693: FLYSContext flysContext = FLYSUtils.getFlysContext(context);
ingo@2693: StateEngine stateEngine = (StateEngine) flysContext.get(
ingo@2693: FLYSContext.STATE_ENGINE_KEY);
ingo@2693:
ingo@2693: TransitionEngine transitionEngine = (TransitionEngine) flysContext.get(
ingo@2693: FLYSContext.TRANSITION_ENGINE_KEY);
ingo@2693:
ingo@2693: List reachable = transitionEngine.getReachableStates(
ingo@2693: this, getCurrentState(context), stateEngine);
ingo@2693:
ingo@2693: Document description = XMLUtils.newDocument();
ingo@2693: XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
ingo@2693: description,
ingo@2693: ArtifactNamespaceContext.NAMESPACE_URI,
ingo@2693: ArtifactNamespaceContext.NAMESPACE_PREFIX);
ingo@2693:
ingo@2693: Element root = ProtocolUtils.createRootNode(creator);
ingo@2693: description.appendChild(root);
ingo@2693:
ingo@2693: State current = getCurrentState(context);
ingo@2693:
ingo@2693: ProtocolUtils.appendDescribeHeader(creator, root, identifier(), hash());
ingo@2693: ProtocolUtils.appendState(creator, root, current);
ingo@2693: ProtocolUtils.appendReachableStates(creator, root, reachable);
ingo@2693:
ingo@2693: appendBackgroundActivity(creator, root, context);
ingo@2693:
ingo@2693: Element name = ProtocolUtils.createArtNode(
ingo@2693: creator, "name",
ingo@2693: new String[] { "value" },
ingo@2693: new String[] { getName() });
ingo@2693:
ingo@2693: Element ui = ProtocolUtils.createArtNode(
ingo@2693: creator, "ui", null, null);
ingo@2693:
ingo@2693: Element staticUI = ProtocolUtils.createArtNode(
ingo@2693: creator, "static", null, null);
ingo@2693:
ingo@2693: Element outs = ProtocolUtils.createArtNode(
ingo@2693: creator, "outputmodes", null, null);
ingo@2693: appendOutputModes(description, outs, context, identifier());
ingo@2693:
ingo@2693: appendStaticUI(description, staticUI, context, identifier());
ingo@2693:
ingo@2693: Element dynamic = current.describe(
ingo@2693: this,
ingo@2693: description,
ingo@2693: root,
ingo@2693: context,
ingo@2693: identifier());
ingo@2693:
ingo@2693: if (dynamic != null) {
ingo@2693: ui.appendChild(dynamic);
ingo@2693: }
ingo@2693:
ingo@2693: ui.appendChild(staticUI);
ingo@2693:
ingo@2693: root.appendChild(name);
ingo@2693: root.appendChild(ui);
ingo@2693: root.appendChild(outs);
ingo@2693:
ingo@2693: return description;
ingo@2693: }
ingo@2693:
ingo@2693:
ingo@2693: /**
ingo@2693: * Returns the name of the concrete artifact.
ingo@2693: *
ingo@2693: * @return the name of the concrete artifact.
ingo@2693: */
ingo@2693: public String getName() {
ingo@2693: return ARTIFACT_NAME;
ingo@2693: }
ingo@2693:
ingo@2693:
ingo@2693: protected static void appendBackgroundActivity(
ingo@2693: ElementCreator cr,
ingo@2693: Element root,
ingo@2693: CallContext context
ingo@2693: ) {
ingo@2693: Element inBackground = cr.create("background-processing");
ingo@2693: root.appendChild(inBackground);
ingo@2693:
ingo@2693: cr.addAttr(
ingo@2693: inBackground,
ingo@2693: "value",
ingo@2693: String.valueOf(context.isInBackground()),
ingo@2693: true);
ingo@2693:
ingo@2693: LinkedList messages = context.getBackgroundMessages();
ingo@2693:
ingo@2693: if (messages == null) {
ingo@2693: return;
ingo@2693: }
ingo@2693:
ingo@2693: CalculationMessage message = (CalculationMessage) messages.getLast();
ingo@2693: cr.addAttr(
ingo@2693: inBackground,
ingo@2693: "steps",
ingo@2693: String.valueOf(message.getSteps()),
ingo@2693: true);
ingo@2693:
ingo@2693: cr.addAttr(
ingo@2693: inBackground,
ingo@2693: "currentStep",
ingo@2693: String.valueOf(message.getCurrentStep()),
ingo@2693: true);
ingo@2693:
ingo@2693: inBackground.setTextContent(message.getMessage());
ingo@2693: }
ingo@2693:
ingo@2693:
ingo@2693: /**
ingo@2693: * Append output mode nodes to a document.
ingo@2693: */
ingo@2693: protected void appendOutputModes(
ingo@2693: Document doc,
ingo@2693: Element outs,
ingo@2693: CallContext context,
ingo@2693: String uuid)
ingo@2693: {
ingo@2693: List