ingo@119: package de.intevation.flys.artifacts;
ingo@119:
ingo@119: import java.util.List;
ingo@119:
ingo@119: import org.apache.log4j.Logger;
ingo@119:
ingo@119: import org.w3c.dom.Document;
ingo@119:
ingo@119: import de.intevation.artifacts.ArtifactFactory;
ingo@119: import de.intevation.artifacts.CallContext;
ingo@119:
ingo@119: import de.intevation.artifacts.common.ArtifactNamespaceContext;
ingo@119: import de.intevation.artifacts.common.utils.XMLUtils;
ingo@119:
ingo@119: import de.intevation.artifactdatabase.DefaultArtifact;
ingo@119: import de.intevation.artifactdatabase.data.StateData;
ingo@119: import de.intevation.artifactdatabase.state.State;
ingo@119: import de.intevation.artifactdatabase.state.StateEngine;
ingo@119:
ingo@119: import de.intevation.flys.artifacts.context.FLYSContext;
ingo@119:
ingo@119:
ingo@119: /**
ingo@119: * The defaul FLYS artifact.
ingo@119: *
ingo@119: * @author Ingo Weinzierl
ingo@119: */
ingo@119: public abstract class FLYSArtifact extends DefaultArtifact {
ingo@119:
ingo@119: /** The logger that is used in this artifact.*/
ingo@119: private static Logger logger = Logger.getLogger(FLYSArtifact.class);
ingo@119:
ingo@119:
ingo@119: /** The XPath to the name of the artifact in its configuration. */
ingo@119: public static final String XPATH_ARTIFACT_NAME = "@name";
ingo@119:
ingo@119:
ingo@119: /** The identifier of the current state. */
ingo@119: protected String currentStateId;
ingo@119:
ingo@119: /** The name of the artifact.*/
ingo@119: protected String name;
ingo@119:
ingo@119:
ingo@119: /**
ingo@119: * Initialize the artifact and insert new data if data
contains
ingo@119: * information necessary for this artifact.
ingo@119: *
ingo@119: * @param identifier The UUID.
ingo@119: * @param factory The factory that is used to create this artifact.
ingo@119: * @param context The CallContext.
ingo@119: * @param data Some optional data.
ingo@119: */
ingo@119: @Override
ingo@119: public void setup(
ingo@119: String identifier,
ingo@119: ArtifactFactory factory,
ingo@119: Object context,
ingo@119: Document data)
ingo@119: {
ingo@119: logger.debug("Setup this artifact with the uuid: " + identifier);
ingo@119:
ingo@119: super.setup(identifier, factory, context, data);
ingo@119:
ingo@119: String name = XMLUtils.xpathString(
ingo@119: data, XPATH_ARTIFACT_NAME, ArtifactNamespaceContext.INSTANCE);
ingo@119: setName(name);
ingo@119:
ingo@119: FLYSContext flysContext = (FLYSContext) context;
ingo@119: StateEngine engine = (StateEngine) flysContext.get(
ingo@119: FLYSContext.STATE_ENGINE_KEY);
ingo@119:
ingo@119: List states = engine.getStates(name);
ingo@119:
ingo@119: setCurrentState(states.get(0));
ingo@119: }
ingo@119:
ingo@119:
ingo@119: /**
ingo@119: * Insert new data included in input
into the current state.
ingo@119: *
ingo@119: * @param target XML document that contains new data.
ingo@119: * @param context The CallContext.
ingo@119: *
ingo@119: * @return a document that contains a SUCCESS or FAILURE message.
ingo@119: */
ingo@119: @Override
ingo@119: public Document feed(Document target, CallContext context) {
ingo@119: Document result = XMLUtils.newDocument();
ingo@119:
ingo@119: // TODO IMPLEMENT ME
ingo@119:
ingo@119: return result;
ingo@119: }
ingo@119:
ingo@119:
ingo@119: /**
ingo@119: * This method returns the name of the concrete artifact.
ingo@119: *
ingo@119: * @return the name of the concrete artifact.
ingo@119: */
ingo@119: public String getName() {
ingo@119: return name;
ingo@119: }
ingo@119:
ingo@119:
ingo@119:
ingo@119: /**
ingo@119: * This method sets the name of this artifact.
ingo@119: *
ingo@119: * @param name the name for this artifact.
ingo@119: */
ingo@119: protected void setName(String name) {
ingo@119: this.name = name;
ingo@119: }
ingo@119:
ingo@119:
ingo@119: /**
ingo@119: * Returns the identifier of the current state.
ingo@119: *
ingo@119: * @return the identifier of the current state.
ingo@119: */
ingo@119: protected String getCurrentStateId() {
ingo@119: return currentStateId;
ingo@119: }
ingo@119:
ingo@119:
ingo@119: /**
ingo@119: * Sets the identifier of the current state.
ingo@119: *
ingo@119: * @param id the identifier of a state.
ingo@119: */
ingo@119: protected void setCurrentStateId(String id) {
ingo@119: currentStateId = id;
ingo@119: }
ingo@119:
ingo@119:
ingo@119:
ingo@119: /**
ingo@119: * Set the current state of this artifact. NOTEWe don't store the
ingo@119: * State object itself - which is not necessary - but its identifier. So
ingo@119: * this method will just call the setCurrentStateId() method with the
ingo@119: * identifier of state.
ingo@119: *
ingo@119: * @param state The new current state.
ingo@119: */
ingo@119: protected void setCurrentState(State state) {
ingo@119: setCurrentStateId(state.getID());
ingo@119: }
ingo@119:
ingo@119:
ingo@119: /**
ingo@119: * Returns the current state of the artifact.
ingo@119: *
ingo@119: * @return the current State of the artifact.
ingo@119: */
ingo@119: protected State getCurrentState(Object context) {
ingo@119: FLYSContext flysContext = (FLYSContext) context;
ingo@119: StateEngine engine = (StateEngine) flysContext.get(
ingo@119: FLYSContext.STATE_ENGINE_KEY);
ingo@119:
ingo@119: return engine.getState(getCurrentStateId());
ingo@119: }
ingo@119:
ingo@119:
ingo@119: /**
ingo@119: * This method extracts the data that is contained in the FEED document.
ingo@119: *
ingo@119: * @param feed The FEED document.
ingo@119: * @param xpath The XPath that points to the data nodes.
ingo@119: *
ingo@119: * @return a StateData array.
ingo@119: */
ingo@119: public StateData[] extractData(Document feed, String xpath) {
ingo@119:
ingo@119: // TODO IMPLEMENT ME
ingo@119: return null;
ingo@119: }
ingo@119: }
ingo@119: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :