Mercurial > dive4elements > river
changeset 107:a228b39494a9
Improved the bootstrap process - the states are initialized.
flys-artifacts/trunk@1292 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 04 Feb 2011 11:09:11 +0000 |
parents | 5864c41219db |
children | 50273a391e53 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContext.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContextFactory.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/State.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/transitions/DefaultTransition.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/transitions/Transition.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/transitions/TransitionEngine.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/transitions/TransitionFactory.java |
diffstat | 8 files changed, 83 insertions(+), 132 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Thu Feb 03 10:23:30 2011 +0000 +++ b/flys-artifacts/ChangeLog Fri Feb 04 11:09:11 2011 +0000 @@ -1,3 +1,23 @@ +2011-02-04 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/states/State.java, + src/main/java/de/intevation/flys/artifacts/transitions/TransitionEngine.java, + src/main/java/de/intevation/flys/artifacts/transitions/Transition.java: + Removed. These classes are placed in the artifact-database now. + + * src/main/java/de/intevation/flys/artifacts/transitions/DefaultTransition.java, + src/main/java/de/intevation/flys/artifacts/transitions/TransitionFactory.java: + Adapted imports of Transition. + + * src/main/java/de/intevation/flys/artifacts/states/StateFactory.java: New. + This factory should be used to create concrete State objects. + + * src/main/java/de/intevation/flys/artifacts/context/FLYSContext.java: Added + a constant key to store the StateEngine in the context. + + * src/main/java/de/intevation/flys/artifacts/context/FLYSContextFactory.java: + New method that initializes the states at application start. + 2011-02-03 Ingo Weinzierl <ingo@intevation.de> * src/main/java/de/intevation/flys/artifacts/states/State.java: New. The
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContext.java Thu Feb 03 10:23:30 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContext.java Fri Feb 04 11:09:11 2011 +0000 @@ -21,6 +21,10 @@ public static final String TRANSITION_ENGINE_KEY = "artifact.transition.engine"; + /** The key that is used to store the StateEngine in the context */ + public static final String STATE_ENGINE_KEY = + "artifact.state.engine"; + /** * The default constructor.
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContextFactory.java Thu Feb 03 10:23:30 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContextFactory.java Fri Feb 04 11:09:11 2011 +0000 @@ -17,9 +17,12 @@ import de.intevation.artifacts.common.utils.XMLUtils; import de.intevation.artifactdatabase.Config; +import de.intevation.artifactdatabase.state.State; +import de.intevation.artifactdatabase.state.StateEngine; +import de.intevation.artifactdatabase.transition.Transition; +import de.intevation.artifactdatabase.transition.TransitionEngine; -import de.intevation.flys.artifacts.transitions.Transition; -import de.intevation.flys.artifacts.transitions.TransitionEngine; +import de.intevation.flys.artifacts.states.StateFactory; import de.intevation.flys.artifacts.transitions.TransitionFactory; @@ -39,7 +42,7 @@ "/artifact-database/artifacts/artifact"; /** The XPath to the name of the artifact. */ - public static final String XPATH_ARTIFACT_NAME = "@name"; + public static final String XPATH_ARTIFACT_NAME = "/artifact/@name"; /** The XPath to the xlink ref in an artifact configuration. */ public static final String XPATH_XLINK = "xlink:href"; @@ -48,6 +51,10 @@ public static final String XPATH_TRANSITIONS = "/artifact/states/transition"; + /** The XPath to the states configured in the artifact config. */ + public static final String XPATH_STATES = + "/artifact/states/state"; + /** * Creates a new FLYSArtifactContext object and initialize all * components required by the application. @@ -59,6 +66,7 @@ FLYSContext context = new FLYSContext(config); configureTransitions(config, context); + configureStates(config, context); return context; } @@ -87,7 +95,7 @@ if (transitionList == null) { logger.warn("The artifact has no transitions configured."); - return; + continue; } int trans = transitionList.getLength(); @@ -136,5 +144,48 @@ return artifactDocs; } + + + /** + * This method initializes the transition configuration. + * + * @param config the config document. + * @param context the FLYSContext. + */ + protected void configureStates(Document config, FLYSContext context) { + StateEngine engine = new StateEngine(); + + Document[] artifacts = getArtifactConfigurations(config); + logger.info("Found " + artifacts.length + " artifacts in the config."); + + for (Document doc: artifacts) { + List<State> states = new ArrayList<State>(); + + String artName = (String) XMLUtils.xpath( + doc, XPATH_ARTIFACT_NAME, XPathConstants.STRING); + + NodeList stateList = (NodeList) XMLUtils.xpath( + doc, XPATH_STATES, XPathConstants.NODESET); + + if (stateList == null) { + logger.warn("The artifact has no states configured."); + continue; + } + + int count = stateList.getLength(); + + logger.info( + "Artifact '" + artName + "' has " + count + " states."); + + for (int i = 0; i < count; i++) { + states.add(StateFactory.createState( + stateList.item(i))); + } + + engine.addStates(artName, states); + } + + context.put(FLYSContext.STATE_ENGINE_KEY, engine); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/State.java Thu Feb 03 10:23:30 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -package de.intevation.flys.artifacts.states; - -import java.io.Serializable; - -/** - * This interface describes the basic method a concrete state class needs to - * implement. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface State extends Serializable { - - /** - * Return the id of the state. - * - * @return the id. - */ - public String getID(); - - /** - * Return the description of the state. - * - * @return the description of the state. - */ - public String getDescription(); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/transitions/DefaultTransition.java Thu Feb 03 10:23:30 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/transitions/DefaultTransition.java Fri Feb 04 11:09:11 2011 +0000 @@ -1,6 +1,7 @@ package de.intevation.flys.artifacts.transitions; -import de.intevation.flys.artifacts.states.State; +import de.intevation.artifactdatabase.state.State; +import de.intevation.artifactdatabase.transition.Transition; /** * The default implementation of a <code>Transition</code>.
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/transitions/Transition.java Thu Feb 03 10:23:30 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -package de.intevation.flys.artifacts.transitions; - -import de.intevation.flys.artifacts.states.State; - - -/** - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public interface Transition { - - /** - * Return the ID of the start State. - */ - public String getFrom(); - - /** - * Return the ID of the target State. - */ - public String getTo(); - - /** - * Set the ID of the current State. - * - * @param from The ID of the current state. - */ - public void setFrom(String from); - - /** - * Set the ID of the target State. - * - * @param to The ID of the target state. - */ - public void setTo(String to); - - /** - * Determines if the transition from <code>state</code> is valid. - */ - public boolean isValid(State state); -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/transitions/TransitionEngine.java Thu Feb 03 10:23:30 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +0,0 @@ -package de.intevation.flys.artifacts.transitions; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.log4j.Logger; - -/** - * The TransitionEngine stores all transitions for each Artifact and should be - * used to determine, if an Artifact is able to advance from one to another - * state. - * - * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> - */ -public class TransitionEngine { - - /** The logger used in this class. */ - private static Logger logger = Logger.getLogger(TransitionEngine.class); - - /** - * A map that contains the transitions of the artifacts. The key is the name - * of the artifact, its value is a list of all transitions of this artifact. - */ - protected Map<String, List> transitions; - - - /** - * The default constructor. - */ - public TransitionEngine() { - transitions = new HashMap<String, List>(); - } - - - /** - * Add new transitions for a specific artifact. - * - * @param artifact the name of the Artifact. - * @param transitions the list of transition of the artifact. - * - * @return true, if the transitions were added, otherwise false. - */ - public boolean addTransition(String artifact, List transitions) { - List tmp = this.transitions.get(artifact); - - if (tmp != null) { - logger.info( - "Transitions for the artifact '" - + artifact - + "' already stored."); - - return false; - } - - logger.debug("Add new transitions for artifact '" + artifact + "'"); - return this.transitions.put(artifact, transitions) != null; - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/transitions/TransitionFactory.java Thu Feb 03 10:23:30 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/transitions/TransitionFactory.java Fri Feb 04 11:09:11 2011 +0000 @@ -6,6 +6,8 @@ import org.w3c.dom.Node; +import de.intevation.artifactdatabase.transition.Transition; + import de.intevation.artifacts.common.utils.XMLUtils;