raimund@2651: package de.intevation.flys.artifacts;
raimund@2651:
raimund@2651: import java.util.List;
raimund@2651:
raimund@2651: import org.apache.log4j.Logger;
raimund@2651:
raimund@2651: import org.w3c.dom.Element;
raimund@2651: import org.w3c.dom.Document;
raimund@2651: import org.w3c.dom.Node;
raimund@2651:
raimund@2651: import de.intevation.artifacts.CallContext;
raimund@2651: import de.intevation.artifacts.common.utils.XMLUtils;
raimund@2651: import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
raimund@2651: import de.intevation.artifacts.common.ArtifactNamespaceContext;
raimund@2651:
raimund@2651: import de.intevation.artifactdatabase.ProtocolUtils;
raimund@2651: import de.intevation.artifactdatabase.data.StateData;
raimund@2651: import de.intevation.artifactdatabase.state.State;
raimund@2651: import de.intevation.artifactdatabase.state.StateEngine;
raimund@2651: import de.intevation.artifactdatabase.state.Output;
raimund@2651: import de.intevation.artifactdatabase.transition.TransitionEngine;
raimund@2651:
raimund@2651: import de.intevation.flys.artifacts.model.FacetTypes;
raimund@2651: import de.intevation.flys.artifacts.context.FLYSContext;
raimund@2651: import de.intevation.flys.artifacts.states.DefaultState;
raimund@2651:
raimund@2651: import de.intevation.flys.utils.FLYSUtils;
raimund@2651:
raimund@2651: /**
raimund@2651: * The default fixation analysis artifact.
raimund@2651: *
raimund@2651: * @author Raimund Renkert
raimund@2651: */
raimund@2651: public class FixationArtifact
raimund@2651: extends FLYSArtifact
raimund@2651: implements FacetTypes {
raimund@2651:
raimund@2651: /** The logger for this class. */
raimund@2651: private static Logger logger = Logger.getLogger(FixationArtifact.class);
raimund@2651:
raimund@2651: /** The name of the artifact. */
raimund@2651: public static final String ARTIFACT_NAME = "fixanalysis";
raimund@2651:
raimund@2651: /**
raimund@2651: * The default constructor.
raimund@2651: */
raimund@2651: public FixationArtifact() {
raimund@2651: }
raimund@2651:
raimund@2651: /**
raimund@2651: * Returns the name of the concrete artifact.
raimund@2651: *
raimund@2651: * @return the name of the concrete artifact.
raimund@2651: */
raimund@2651: public String getName() {
raimund@2651: return ARTIFACT_NAME;
raimund@2651: }
raimund@2651:
raimund@2651: public Document describe(Document data, CallContext context) {
raimund@2651: logger.debug("Describe: the current state is: " + getCurrentStateId());
raimund@2651:
raimund@2651: if (logger.isDebugEnabled()) {
raimund@2651: dumpArtifact();
raimund@2651: }
raimund@2651:
raimund@2651: FLYSContext flysContext = FLYSUtils.getFlysContext(context);
raimund@2651:
raimund@2651: StateEngine stateEngine = (StateEngine) flysContext.get(
raimund@2651: FLYSContext.STATE_ENGINE_KEY);
raimund@2651:
raimund@2651: TransitionEngine transitionEngine = (TransitionEngine) flysContext.get(
raimund@2651: FLYSContext.TRANSITION_ENGINE_KEY);
raimund@2651:
raimund@2651: List reachable = transitionEngine.getReachableStates(
raimund@2651: this, getCurrentState(context), stateEngine);
raimund@2651:
raimund@2651: Document description = XMLUtils.newDocument();
raimund@2651: XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
raimund@2651: description,
raimund@2651: ArtifactNamespaceContext.NAMESPACE_URI,
raimund@2651: ArtifactNamespaceContext.NAMESPACE_PREFIX);
raimund@2651:
raimund@2651: Element root = ProtocolUtils.createRootNode(creator);
raimund@2651: description.appendChild(root);
raimund@2651:
raimund@2651: State current = getCurrentState(context);
raimund@2651:
raimund@2651: ProtocolUtils.appendDescribeHeader(creator, root, identifier(), hash());
raimund@2651: ProtocolUtils.appendState(creator, root, current);
raimund@2651: ProtocolUtils.appendReachableStates(creator, root, reachable);
raimund@2651:
raimund@2651: Element ui = ProtocolUtils.createArtNode(
raimund@2651: creator, "ui", null, null);
raimund@2651:
raimund@2651: Element staticUI = ProtocolUtils.createArtNode(
raimund@2651: creator, "static", null, null);
raimund@2651:
raimund@2651: Element outs = ProtocolUtils.createArtNode(
raimund@2651: creator, "outputmodes", null, null);
raimund@2651: appendOutputModes(description, outs, context, identifier());
raimund@2651:
raimund@2651: appendStaticUI(description, staticUI, context, identifier());
raimund@2651:
raimund@2651:
raimund@2651: Element name = ProtocolUtils.createArtNode(
raimund@2651: creator, "name",
raimund@2651: new String[] { "value" },
raimund@2651: new String[] { getName() });
raimund@2651:
raimund@2651: Element dynamic = current.describe(
raimund@2651: this,
raimund@2651: description,
raimund@2651: root,
raimund@2651: context,
raimund@2651: identifier());
raimund@2651:
raimund@2651: if (dynamic != null) {
raimund@2651: ui.appendChild(dynamic);
raimund@2651: }
raimund@2651:
raimund@2651: ui.appendChild(staticUI);
raimund@2651:
raimund@2651: root.appendChild(name);
raimund@2651: root.appendChild(ui);
raimund@2651: root.appendChild(outs);
raimund@2651:
raimund@2651: return description;
raimund@2651: }
raimund@2651:
raimund@2651:
raimund@2651: /**
raimund@2651: * Append output mode nodes to a document.
raimund@2651: */
raimund@2651: protected void appendOutputModes(
raimund@2651: Document doc,
raimund@2651: Element outs,
raimund@2651: CallContext context,
raimund@2651: String uuid)
raimund@2651: {
raimund@2651: List