ingo@104: package de.intevation.artifactdatabase.transition;
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 TransitionEngine stores all transitions for each Artifact and should be
ingo@104: * used to determine, if an Artifact is able to advance from one to another
ingo@104: * state.
ingo@104: *
ingo@104: * @author Ingo Weinzierl
ingo@104: */
ingo@104: public class TransitionEngine {
ingo@104:
ingo@104: /** The logger used in this class. */
ingo@104: private static Logger logger = Logger.getLogger(TransitionEngine.class);
ingo@104:
ingo@104: /**
ingo@104: * A map that contains the transitions of the artifacts. The key is the name
ingo@104: * of the artifact, its value is a list of all transitions of this artifact.
ingo@104: */
ingo@104: protected Map transitions;
ingo@104:
ingo@104:
ingo@104: /**
ingo@104: * The default constructor.
ingo@104: */
ingo@104: public TransitionEngine() {
ingo@104: transitions = new HashMap();
ingo@104: }
ingo@104:
ingo@104:
ingo@104: /**
ingo@104: * Add new transitions for a specific artifact.
ingo@104: *
ingo@104: * @param stateId the name of the Artifact.
ingo@104: * @param transitions the list of transition of the artifact.
ingo@104: *
ingo@104: * @return true, if the transitions were added, otherwise false.
ingo@104: */
ingo@104: public boolean addTransition(String stateId, List transitions) {
ingo@104: List tmp = this.transitions.get(stateId);
ingo@104:
ingo@104: if (tmp != null) {
ingo@104: logger.info(
ingo@104: "Transitions for the state '"
ingo@104: + stateId
ingo@104: + "' already stored.");
ingo@104:
ingo@104: return false;
ingo@104: }
ingo@104:
ingo@104: logger.debug("Add new transitions for state '" + stateId + "'");
ingo@104: return this.transitions.put(stateId, transitions) != null;
ingo@104: }
ingo@104: }
ingo@104: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :