ingo@104: package de.intevation.artifactdatabase.state;
ingo@104:
ingo@104: import java.util.HashMap;
ingo@104: import java.util.List;
ingo@104: import java.util.Map;
ingo@104:
ingo@104: import org.apache.log4j.Logger;
ingo@104:
ingo@104: /**
ingo@104: * The StateEngine stores all states for each Artifact.
ingo@104: *
ingo@104: * @author Ingo Weinzierl
ingo@104: */
ingo@104: public class StateEngine {
ingo@104:
ingo@104: /** The logger used in this class. */
ingo@104: private static Logger logger = Logger.getLogger(StateEngine.class);
ingo@104:
ingo@104: /**
ingo@104: * A map that contains the states of the artifacts. The key of this map is
ingo@104: * the name of an artifact, its value is a list of all states the artifact
ingo@104: * can reach.
ingo@104: */
ingo@104: protected Map states;
ingo@104:
ingo@104:
ingo@104: /**
ingo@104: * The default constructor.
ingo@104: */
ingo@104: public StateEngine() {
ingo@104: states = new HashMap();
ingo@104: }
ingo@104:
ingo@104:
ingo@104: /**
ingo@104: * Add new states for a specific artifact.
ingo@104: *
ingo@104: * @param artifact The name of the artifact.
ingo@104: * @param states A list of states that the artifact can reach.
ingo@104: *
ingo@104: * @return true, if the states were added, otherwise false.
ingo@104: */
ingo@104: public boolean addStates(String artifact, List states) {
ingo@104: List tmp = this.states.get(artifact);
ingo@104:
ingo@104: if (tmp != null) {
ingo@104: logger.info(
ingo@104: "States for the artifact '" + artifact + "' already stored.");
ingo@104:
ingo@104: return false;
ingo@104: }
ingo@104:
ingo@104: logger.debug("Add new states for the artifact '" + artifact + "'");
ingo@104: return this.states.put(artifact, states) != null;
ingo@104: }
ingo@104: }
ingo@104: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :