# HG changeset patch # User Tim Englich # Date 1260279501 0 # Node ID a887074460b60cf202ba382eabde14ec30734cd0 # Parent 1b9ca0f2d4989c76e37103045ca5a375ae94e33d Last Step of the Refactoring Work on the Transition Model. Splitted Businesslogic between States and Transitions. Splitted the ConfigurationElements of State and Transition in several XML-Fragments. gnv-artifacts/trunk@403 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 1b9ca0f2d498 -r a887074460b6 gnv-artifacts/ChangeLog --- a/gnv-artifacts/ChangeLog Tue Dec 08 11:18:27 2009 +0000 +++ b/gnv-artifacts/ChangeLog Tue Dec 08 13:38:21 2009 +0000 @@ -1,3 +1,26 @@ +2009-12-08 Tim Englich + + * src/main/java/de/intevation/gnv/transition/profile: + Removed empty needless package. + * src/main/java/de/intevation/gnv/transition/TransitionFactory.java: + src/main/java/de/intevation/gnv/transition/ValueCompareTransition.java, + src/main/java/de/intevation/gnv/transition/TransitionBase.java, + src/main/java/de/intevation/gnv/transition/Transition.java, + src/main/java/de/intevation/gnv/transition/DefaultTransition.java: + The new Transitions which has the only job to provide the connectios between + the different States and look if it is Possible to go the different Ways. + * src/main/java/de/intevation/gnv/state/StateBase.java, + src/main/java/de/intevation/gnv/state/State.java: + Removed the Logic to descide which State is be reacable as next. + Now the Transition configured in the Artifacts will do that according + to the modified TransitionModel. + * src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java (transitions): + Added the Transitions to the Artifact and changed the Logic. + Now the Transition is able to decide if it could be uses or not. + * doc/conf/products/verticalprofile/*.xml: + Modified the Configuration. Splitted States and Transitions into + different XML-Fragments according to the modified Transitionmodel. + 2009-12-08 Ingo Weinzierl * doc/conf/queries.properties: Added marker ('DATAID') for different data diff -r 1b9ca0f2d498 -r a887074460b6 gnv-artifacts/doc/conf/products/horizontalcrosssection/conf_mesh.xml --- a/gnv-artifacts/doc/conf/products/horizontalcrosssection/conf_mesh.xml Tue Dec 08 11:18:27 2009 +0000 +++ b/gnv-artifacts/doc/conf/products/horizontalcrosssection/conf_mesh.xml Tue Dec 08 13:38:21 2009 +0000 @@ -6,10 +6,6 @@ areaid false true - - horizontalcrosssection_subarea - horizontalcrosssection_mesh_without_geom - @@ -17,13 +13,21 @@ + + + + + + + + + + + subarea_filter subareaid false - - horizontalcrosssection_mesh - @@ -32,13 +36,15 @@ + + + + + verticalprofile_mesh meshid false - - horizontalcrosssection_meshpoint_depth - @@ -47,13 +53,15 @@ + + + + + verticalprofile_mesh_with_area meshid false - - horizontalcrosssection_meshpoint_depth - @@ -62,27 +70,31 @@ + + + + + horizontalcrosssection_meshpoint_depth depthid false - - horizontalcrosssection_meshpoint_parameter - - + + + + + + verticalprofile_mesh_parameter parameterid false - - horizontalcrosssection_mesh_date - @@ -91,13 +103,15 @@ + + + + + horizontalcrosssection_mesh_date dateid false - - horizontalcrosssection_mesh_calculate_results - @@ -107,6 +121,11 @@ + + + + + horizontalcrosssection_mesh_data horizontalcrosssection_mesh_odv_data diff -r 1b9ca0f2d498 -r a887074460b6 gnv-artifacts/doc/conf/products/horizontalprofile/conf_instantaneouspoint.xml --- a/gnv-artifacts/doc/conf/products/horizontalprofile/conf_instantaneouspoint.xml Tue Dec 08 11:18:27 2009 +0000 +++ b/gnv-artifacts/doc/conf/products/horizontalprofile/conf_instantaneouspoint.xml Tue Dec 08 13:38:21 2009 +0000 @@ -6,10 +6,6 @@ areaid false true - - horizontalprofile_instantaneouspoint_subarea - horizontalprofile_instantaneouspoint_vehicle_without_geom - @@ -17,13 +13,21 @@ + + + + + + + + + + + subarea_filter subareaid false - - horizontalprofile_instantaneouspoint_vehicle - @@ -31,15 +35,17 @@ + + + + + horizontalprofile_instantaneouspoint_vehicle_with_area vehicleid false - - horizontalprofile_instantaneouspoint_cruise_with_area - @@ -47,13 +53,16 @@ + + + + + + horizontalprofile_instantaneouspoint_cruise_with_area cruiseid false - - horizontalprofile_instantaneouspoint_track_with_area - @@ -62,13 +71,16 @@ + + + + + + horizontalprofile_instantaneouspoint_track_with_area trackid false - - horizontalprofile_instantaneouspoint_surveyinfo - Eisklimatologie @@ -76,6 +88,11 @@ + + + + + @@ -92,13 +109,15 @@ + + + + + horizontalprofile_instantaneouspoint_cruise cruiseid false - - horizontalprofile_instantaneouspoint_track - @@ -106,26 +125,32 @@ + + + + + + horizontalprofile_instantaneouspoint_track trackid false - - horizontalprofile_instantaneouspoint_surveyinfo - Eisklimatologie + + + + + + horizontalprofile_instantaneouspoint_surveyinfo surveyid false - - horizontalprofile_instantaneouspoint_parameter - @@ -133,13 +158,16 @@ + + + + + + horizontalprofile_instantaneouspoint_parameter parameterid true - - horizontalprofile_instantaneouspoint_depth - @@ -148,13 +176,16 @@ + + + + + + horizontalprofile_instantaneouspoint_depth measurementid true - - horizontalprofile_instantaneouspoint_calculate_results - @@ -164,6 +195,12 @@ + + + + + + horizontalprofile_instantaneouspoint_chart_data horizontalprofile_instantaneouspoint_odv_data diff -r 1b9ca0f2d498 -r a887074460b6 gnv-artifacts/doc/conf/products/horizontalprofile/conf_mesh.xml --- a/gnv-artifacts/doc/conf/products/horizontalprofile/conf_mesh.xml Tue Dec 08 11:18:27 2009 +0000 +++ b/gnv-artifacts/doc/conf/products/horizontalprofile/conf_mesh.xml Tue Dec 08 13:38:21 2009 +0000 @@ -6,23 +6,28 @@ areaid false true - - horizontalprofile_mesh_subarea - horizontalprofile_mesh_without_geom - + + + + + + + + + + + + subarea_filter subareaid false - - horizontalprofile_mesh - @@ -31,27 +36,31 @@ + + + + + verticalprofile_mesh meshid false - - horizontalprofile_mesh_coordinate - - + + + + + + verticalprofile_mesh_with_area meshid false - - horizontalprofile_mesh_coordinate - @@ -60,12 +69,14 @@ + + + + + mesh_coordinate false - - horizontalprofile_mesh_point - @@ -73,13 +84,15 @@ + + + + + verticalprofile_mesh_point mesh_point false - - horizontalprofile_mesh_axis - @@ -87,12 +100,15 @@ - + + + + + + + axisid false - - horizontalprofile_meshpoint_parameter - @@ -100,13 +116,16 @@ + + + + + + verticalprofile_mesh_parameter parameterid true - - horizontalprofile_meshpoint_depth - @@ -116,14 +135,15 @@ + + + + horizontalprofile_meshpoint_depth depthid true - - horizontalprofile_mesh_date - @@ -134,13 +154,15 @@ + + + + + verticalprofile_mesh_date dateid true - - horizontalprofile_mesh_calculate_results - @@ -152,6 +174,11 @@ + + + + + horizontalprofile_mesh_chart_data horizontalprofile_mesh_odv_data diff -r 1b9ca0f2d498 -r a887074460b6 gnv-artifacts/doc/conf/products/timeseries/conf_mesh.xml --- a/gnv-artifacts/doc/conf/products/timeseries/conf_mesh.xml Tue Dec 08 11:18:27 2009 +0000 +++ b/gnv-artifacts/doc/conf/products/timeseries/conf_mesh.xml Tue Dec 08 13:38:21 2009 +0000 @@ -6,23 +6,28 @@ areaid false true - - timeseries_mesh_subarea - timeseries_mesh_without_geom - + + + + + + + + + + + + subarea_filter subareaid false - - timeseries_mesh - @@ -31,27 +36,31 @@ + + + + + verticalprofile_mesh meshid false - - timeseries_mesh_coordinate - + + + + + verticalprofile_mesh_with_area meshid false - - timeseries_mesh_coordinate - @@ -60,12 +69,14 @@ + + + + + mesh_coordinate false - - timeseries_meshpoint - @@ -73,13 +84,15 @@ + + + + + timeseries_meshpoint mesh_point false - - timeseries_meshpoint_depth - @@ -88,13 +101,15 @@ + + + + + timeseries_meshpoint_depth depthid true - - timeseries_meshpoint_parameter - @@ -102,14 +117,16 @@ - + + + + + + timeseries_mesh_parameter parameterid true - - timeseries_meshpoint_interval - @@ -119,13 +136,15 @@ + + + + + timeseries_mesh_interval timeinterval false - - timeseries_meshpoint_calculate_results - @@ -137,6 +156,11 @@ + + + + + timeseries_mesh_chart_data timeseries_mesh_odv_data diff -r 1b9ca0f2d498 -r a887074460b6 gnv-artifacts/doc/conf/products/timeseries/conf_timeseriespoint.xml --- a/gnv-artifacts/doc/conf/products/timeseries/conf_timeseriespoint.xml Tue Dec 08 11:18:27 2009 +0000 +++ b/gnv-artifacts/doc/conf/products/timeseries/conf_timeseriespoint.xml Tue Dec 08 13:38:21 2009 +0000 @@ -50,16 +50,6 @@ this state. --> true - - - timeseries_subarea - timeseries_without_geom - - diff -r 1b9ca0f2d498 -r a887074460b6 gnv-artifacts/doc/conf/products/verticalcrosssection/conf_mesh.xml --- a/gnv-artifacts/doc/conf/products/verticalcrosssection/conf_mesh.xml Tue Dec 08 11:18:27 2009 +0000 +++ b/gnv-artifacts/doc/conf/products/verticalcrosssection/conf_mesh.xml Tue Dec 08 13:38:21 2009 +0000 @@ -6,23 +6,28 @@ areaid false true - - verticalcrosssection_mesh_subarea - verticalcrosssection_mesh_without_geom - + + + + + + + + + + + + subarea_filter subareaid false - - verticalcrosssection_mesh - @@ -31,27 +36,31 @@ + + + + + verticalprofile_mesh meshid false - - verticalcrosssection_mesh_coordinate - + + + + + verticalprofile_mesh_with_area meshid false - - verticalcrosssection_mesh_coordinate - @@ -60,12 +69,14 @@ + + + + + mesh_coordinate false - - verticalcrosssection_mesh_point - @@ -73,13 +84,15 @@ + + + + + verticalprofile_mesh_point mesh_point false - - verticalcrosssection_mesh_axis - @@ -87,12 +100,15 @@ + + + + + + axisid false - - verticalcrosssection_mesh_parameter - @@ -100,13 +116,16 @@ + + + + + + verticalprofile_mesh_parameter parameterid false - - verticalcrosssection_mesh_date - @@ -116,14 +135,15 @@ + + + + verticalcrosssection_mesh_date dateid false - - verticalcrosssection_mesh_calculate_results - @@ -134,6 +154,11 @@ + + + + + verticalcrosssection_mesh_chart_data verticalcrosssection_mesh_odv_data diff -r 1b9ca0f2d498 -r a887074460b6 gnv-artifacts/doc/conf/products/verticalprofile/conf_instantaneouspoint.xml --- a/gnv-artifacts/doc/conf/products/verticalprofile/conf_instantaneouspoint.xml Tue Dec 08 11:18:27 2009 +0000 +++ b/gnv-artifacts/doc/conf/products/verticalprofile/conf_instantaneouspoint.xml Tue Dec 08 13:38:21 2009 +0000 @@ -5,22 +5,22 @@ verticalprofile_instantaneouspoint_series seriesid false - - verticalprofile_instantaneouspoint_point - + + + + + + verticalprofile_instantaneouspoint_point instantaneouspoint_point false - - verticalprofile_instantaneouspoint_parameter - @@ -28,13 +28,16 @@ + + + + + + verticalprofile_instantaneouspoint_parameter parameterid true - - verticalprofile_instantaneouspoint_minmaxdepth - @@ -42,13 +45,16 @@ + + + + + + verticalprofile_instantaneouspoint_minmaxdepth depthrange true - - verticalprofile_instantaneouspoint_calculate_results - @@ -58,6 +64,12 @@ + + + + + + verticalprofile_instantaneouspoint_chart_data verticalprofile_instantaneouspoint_odv_data diff -r 1b9ca0f2d498 -r a887074460b6 gnv-artifacts/doc/conf/products/verticalprofile/conf_mesh.xml --- a/gnv-artifacts/doc/conf/products/verticalprofile/conf_mesh.xml Tue Dec 08 11:18:27 2009 +0000 +++ b/gnv-artifacts/doc/conf/products/verticalprofile/conf_mesh.xml Tue Dec 08 13:38:21 2009 +0000 @@ -6,23 +6,28 @@ areaid false true - - verticalprofile_mesh_subarea - verticalprofile_mesh_without_geom - + + + + + + + + + + + + subarea_filter subareaid false - - verticalprofile_mesh - @@ -31,27 +36,31 @@ + + + + + verticalprofile_mesh meshid false - - verticalprofile_mesh_coordinate - - + + + + + + verticalprofile_mesh_with_area meshid false - - verticalprofile_mesh_coordinate - @@ -60,12 +69,14 @@ + + + + + mesh_coordinate false - - verticalprofile_mesh_point - @@ -73,13 +84,15 @@ + + + + + verticalprofile_mesh_point mesh_point false - - verticalprofile_mesh_mindepth - @@ -88,13 +101,15 @@ + + + + + verticalprofile_mesh_mindepth mindepthid false - - verticalprofile_mesh_maxdepth - @@ -103,6 +118,11 @@ + + + + + verticalprofile_mesh_maxdepth maxdepthid @@ -118,13 +138,16 @@ - + + + + + + + verticalprofile_mesh_parameter parameterid true - - verticalprofile_mesh_date - @@ -135,13 +158,15 @@ + + + + + verticalprofile_mesh_date dateid true - - verticalprofile_mesh_calculate_results - @@ -153,6 +178,11 @@ + + + + + verticalprofile_mesh_chart_data verticalprofile_mesh_odv_data diff -r 1b9ca0f2d498 -r a887074460b6 gnv-artifacts/doc/conf/products/verticalprofile/conf_timeseriespoint.xml --- a/gnv-artifacts/doc/conf/products/verticalprofile/conf_timeseriespoint.xml Tue Dec 08 11:18:27 2009 +0000 +++ b/gnv-artifacts/doc/conf/products/verticalprofile/conf_timeseriespoint.xml Tue Dec 08 13:38:21 2009 +0000 @@ -6,10 +6,6 @@ areaid false true - - verticalprofile_subarea - verticalprofile_without_geom - @@ -17,13 +13,21 @@ + + + + + + + + + + + subarea_filter subareaid false - - verticalprofile_timeseriespoint - @@ -32,13 +36,15 @@ + + + + + verticalprofile_point featureid false - - verticalprofile_parameter - @@ -46,13 +52,15 @@ + + + + + timeseries_timeseriespoint_with_area featureid false - - verticalprofile_parameter - @@ -61,13 +69,15 @@ + + + + + verticalprofile_parameter parameterid true - - verticalprofile_date - @@ -75,13 +85,15 @@ + + + + + verticalprofile_date dateid true - - verticalprofile_minmaxdepth - @@ -90,13 +102,15 @@ + + + + + verticalprofile_minmaxdepth depthrange true - - verticalprofile_calculate_results - @@ -107,6 +121,11 @@ + + + + + verticalprofile_chart_data verticalprofile_odv_data diff -r 1b9ca0f2d498 -r a887074460b6 gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java Tue Dec 08 11:18:27 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java Tue Dec 08 13:38:21 2009 +0000 @@ -5,6 +5,7 @@ import java.io.IOException; import java.io.OutputStream; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; @@ -34,6 +35,8 @@ import de.intevation.gnv.state.State; import de.intevation.gnv.state.StateFactory; import de.intevation.gnv.state.exception.StateException; +import de.intevation.gnv.transition.Transition; +import de.intevation.gnv.transition.TransitionFactory; import de.intevation.gnv.utils.ArtifactXMLUtilities; /** @@ -71,6 +74,11 @@ * The States that can be used */ protected Map states = null; + + /** + * The Transitions which can switch between the different States. + */ + protected Collection transitions = null; /** * The Name of the Artifact @@ -98,7 +106,7 @@ if (this.current != null) { String stateName = this.readStateName(target); log.debug("Statename: " + stateName); - if (this.current.isStateReachable(stateName)) { + if (this.isStateCurrentlyReachable(stateName)) { try { State nextStep = this.states .get(stateName); @@ -144,6 +152,21 @@ } + private boolean isStateCurrentlyReachable(String stateid){ + log.debug("GNVArtifactBase.isStateCurrentlyReachable "+stateid); + Iterator it = this.transitions.iterator(); + String from = this.current.getID(); + while (it.hasNext()){ + Transition transition = it.next(); + if (transition.getFrom().equals(from)){ + if (transition.getTo().equals(stateid) && transition.isValid(this.current)){ + return true; + } + } + } + return false; + } + public Document initialize (CallContext context) { Document result = XMLUtils.newDocument(); try { @@ -252,6 +275,17 @@ } } } + + NodeList transitionList = Config.getNodeSetXPath(artifactNode, + "states/transition"); + this.transitions = new ArrayList(transitionList.getLength()); + for (int i = 0; i < transitionList.getLength(); i++) { + Transition tmpTransition = TransitionFactory.getInstance() + .createTransition(transitionList.item(i)); + if (tmpTransition != null) { + this.transitions.add(tmpTransition); + } + } } } @@ -308,17 +342,20 @@ Element stateNode = xmlUtilities.createArtifactElement(document, "reachable-states"); if (this.current != null) { - Iterator states = this.current.reachableStates() - .iterator(); - while (states.hasNext()) { - String value = states.next(); - Element currentNode = xmlUtilities.createArtifactElement( - document, "state"); - currentNode.setAttribute("name", value); - log.debug("Reachable State: " + value); - currentNode.setAttribute("description", this.states.get(value) - .getDescription()); - stateNode.appendChild(currentNode); + Iterator transitions = this.transitions.iterator(); + while (transitions.hasNext()) { + Transition tmpTransition = transitions.next(); + if (tmpTransition.getFrom().equals(current.getID()) && + tmpTransition.isValid(this.current)){ + Element currentNode = xmlUtilities.createArtifactElement( + document, "state"); + currentNode.setAttribute("name", tmpTransition.getTo()); + log.debug("Reachable State: " + tmpTransition.getTo()); + currentNode.setAttribute("description", + this.states.get(tmpTransition.getTo()) + .getDescription()); + stateNode.appendChild(currentNode); + } } } parent.appendChild(stateNode); diff -r 1b9ca0f2d498 -r a887074460b6 gnv-artifacts/src/main/java/de/intevation/gnv/state/State.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/State.java Tue Dec 08 11:18:27 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/State.java Tue Dec 08 13:38:21 2009 +0000 @@ -20,10 +20,6 @@ public void setup(Node configuration); - public Collection reachableStates(); - - public boolean isStateReachable(String stateID); - public String getID(); public String getDescription(); diff -r 1b9ca0f2d498 -r a887074460b6 gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java Tue Dec 08 11:18:27 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java Tue Dec 08 13:38:21 2009 +0000 @@ -46,8 +46,6 @@ */ public abstract class StateBase implements State { - - /** * The UID of this Class */ @@ -77,8 +75,6 @@ protected String queryID = null; - private Collection reachableStates = null; - protected Collection inputValueNames = null; private Map inputValues = null; @@ -109,38 +105,7 @@ return this.description; } - /** - * @see de.intevation.gnv.state.State#reachableStates() - */ - public Collection reachableStates() { - - if (this.couldAlternativeStateUsed()){ - Iterator it = this.reachableStates.iterator(); - String transValue = null; - while (it.hasNext()){ - transValue = it.next(); - } - Collection returnValue = new ArrayList(1); - returnValue.add(transValue); - return returnValue; - }else{ - return this.reachableStates; - } - - } - /** - * @return - */ - private boolean couldAlternativeStateUsed() { - // TODO das muss hier noch etwas freier gestaltet werden. - String key = this.dataName; - boolean returnValue=this.inputData != null && - this.inputData.containsKey(key) && - this.inputData.get(key).getValue(). - equals(NODATASELECTIONKEY); - return returnValue; - } /** * @see de.intevation.gnv.state.State#getRequiredInputValues() @@ -158,15 +123,6 @@ this.description = ((Element)configuration).getAttribute("description"); log.info("State-ID = " + this.id); - NodeList nodes = Config.getNodeSetXPath(configuration, - "reachablestates/state"); - this.reachableStates = new ArrayList(nodes.getLength()); - for (int i = 0; i < nodes.getLength(); i++) { - String reachableState = nodes.item(i).getTextContent(); - log.info("ReachableState ==> " + reachableState); - this.reachableStates.add(reachableState); - - } NodeList inputValuesNodes = Config.getNodeSetXPath(configuration, "inputvalues/inputvalue"); @@ -390,23 +346,6 @@ } /** - * @see de.intevation.gnv.state.State#isStateReachable(java.lang.String) - */ - public boolean isStateReachable(String stateID) { - log.debug("StateBase.isStateReachable"); - boolean returnValue = false; - Iterator states = reachableStates.iterator(); - while (states.hasNext()) { - if (states.next().equals(stateID)) { - log.debug("State " + stateID + " wird unterstützt."); - returnValue = true; - break; - } - } - return returnValue; - } - - /** * @see de.intevation.gnv.state.State#advance(java.lang.String, * de.intevation.artifacts.CallMeta) */ diff -r 1b9ca0f2d498 -r a887074460b6 gnv-artifacts/src/main/java/de/intevation/gnv/transition/DefaultTransition.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/DefaultTransition.java Tue Dec 08 13:38:21 2009 +0000 @@ -0,0 +1,33 @@ +/** + * + */ +package de.intevation.gnv.transition; + +import de.intevation.gnv.state.State; + +/** + * @author Tim Englich + * + */ +public class DefaultTransition extends TransitionBase { + + /** + * The UID of this Class. + */ + private static final long serialVersionUID = -2610338646743984581L; + + /** + * Constructor + */ + public DefaultTransition() { + super(); + } + + /** + * @see de.intevation.gnv.transition.Transition#isValid(de.intevation.gnv.state.State) + */ + public boolean isValid(State state) { + return true; + } + +} diff -r 1b9ca0f2d498 -r a887074460b6 gnv-artifacts/src/main/java/de/intevation/gnv/transition/Transition.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/Transition.java Tue Dec 08 13:38:21 2009 +0000 @@ -0,0 +1,41 @@ +package de.intevation.gnv.transition; + +import java.io.Serializable; + +import org.w3c.dom.Node; + +import de.intevation.gnv.state.State; + +/** + * + * @author Tim Englich + * + */ +public interface Transition extends Serializable{ + + /** + * Returns the ID of the State from which the Transition could be used + * @return the ID of the State from which the Transition could be used + */ + public String getFrom(); + + /** + * Returns the ID of the State where it is possible to go as next. + * @return the ID of the State where it is possible to go as next. + */ + public String getTo(); + + /** + * Determines if it is possible to go along this Transition or not. + * @param state the current State + * @return + */ + public boolean isValid(State state); + + /** + * Configures the Transition. + * @param configuration + */ + public void setup(Node configuration); + +} diff -r 1b9ca0f2d498 -r a887074460b6 gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java Tue Dec 08 13:38:21 2009 +0000 @@ -0,0 +1,52 @@ +/** + * + */ +package de.intevation.gnv.transition; + +import org.w3c.dom.Node; + +import de.intevation.artifactdatabase.Config; + +/** + * @author Tim Englich + * + */ +public abstract class TransitionBase implements Transition { + + /** + * The UID of this Class. + */ + private static final long serialVersionUID = -8542097519466477977L; + + private String from = null; + + private String to = null; + /** + * Constructor + */ + public TransitionBase() { + } + + /** + * @see de.intevation.gnv.transition.Transition#getFrom() + */ + public String getFrom() { + return this.from; + } + + /** + * @see de.intevation.gnv.transition.Transition#getTo() + */ + public String getTo() { + return this.to; + } + + /** + * @see de.intevation.gnv.transition.Transition#setup(org.w3c.dom.Node) + */ + public void setup(Node configuration) { + this.from = Config.getStringXPath(configuration,"from/@state"); + this.to = Config.getStringXPath(configuration,"to/@state"); + } + +} diff -r 1b9ca0f2d498 -r a887074460b6 gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionFactory.java Tue Dec 08 13:38:21 2009 +0000 @@ -0,0 +1,55 @@ +/** + * + */ +package de.intevation.gnv.transition; + +import org.apache.log4j.Logger; +import org.w3c.dom.Node; + +import de.intevation.gnv.artifacts.GNVArtifactBase; + +/** + * @author Tim Englich + * + */ +public class TransitionFactory { + + /** + * the logger, used to log exceptions and additonaly information + */ + private static Logger log = Logger.getLogger(GNVArtifactBase.class); + + private static TransitionFactory instance = null; + + /** + * Constructor + */ + public TransitionFactory() { + super(); + } + + public static TransitionFactory getInstance() { + if (instance == null) { + instance = new TransitionFactory(); + } + return instance; + } + + public Transition createTransition(Node configuration) { + log.debug("TransitionFactory.createTransition"); + Transition state = null; + try { + String classname = ((org.w3c.dom.Element)configuration).getAttribute("transition"); + state = (Transition) (Class.forName(classname).newInstance()); + state.setup(configuration); + } catch (InstantiationException e) { + log.error(e, e); + } catch (IllegalAccessException e) { + log.error(e, e); + } catch (ClassNotFoundException e) { + log.error(e, e); + } + return state; + } + +} diff -r 1b9ca0f2d498 -r a887074460b6 gnv-artifacts/src/main/java/de/intevation/gnv/transition/ValueCompareTransition.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/ValueCompareTransition.java Tue Dec 08 13:38:21 2009 +0000 @@ -0,0 +1,82 @@ +/** + * + */ +package de.intevation.gnv.transition; + +import java.util.Iterator; + +import org.apache.log4j.Logger; +import org.w3c.dom.Node; + +import de.intevation.artifactdatabase.Config; +import de.intevation.gnv.state.InputData; +import de.intevation.gnv.state.State; +import de.intevation.gnv.state.exception.StateException; + +/** + * @author Tim Englich + * + */ +public class ValueCompareTransition extends TransitionBase { + + /** + * the logger, used to log exceptions and additonaly information + */ + private static Logger log = Logger.getLogger(ValueCompareTransition.class); + + private String dataName = null; + private String dataValue = null; + private String operator = null; + + /** + * The UID of this Class. + */ + private static final long serialVersionUID = -7846722158776823205L; + + /** + * Constructor + */ + public ValueCompareTransition() { + super(); + } + + /** + * @see de.intevation.gnv.transition.Transition#isValid(de.intevation.gnv.state.State) + */ + public boolean isValid(State state) { + + try { + Iterator it = state.getInputData().iterator(); + while (it.hasNext()){ + InputData inputData = it.next(); + if (inputData.getName().equals(this.dataName)){ + boolean returnValue = false; + if (operator.equals("equal")){ + returnValue = this.dataValue.equals(inputData.getValue()); + }else if (operator.equals("notequal")){ + returnValue = !this.dataValue.equals(inputData.getValue()); + } + return returnValue; + } + } + if (operator.equals("notequal")){ + // data is not given. So the constraint not Equals is fullfilled. + return true; + } + } catch (StateException e) { + log.error(e,e); + return false; + } + return false; + } + + @Override + public void setup(Node configuration) { + super.setup(configuration); + this.dataName = Config.getStringXPath(configuration,"condition/@inputvalue"); + this.dataValue = Config.getStringXPath(configuration,"condition/@value"); + this.operator = Config.getStringXPath(configuration,"condition/@operator"); + } + + +}