# HG changeset patch # User Ingo Weinzierl # Date 1297077847 0 # Node ID ab646e0f5569aaf7ad099b6f2879fca22de5d8f4 # Parent 9ece61d918b1b6d0e67ea58d2788e633618b57f7 Improved the ProtocolUtils - there are new functions to append a current state and the reachable states to a root node. artifacts/trunk@1298 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 9ece61d918b1 -r ab646e0f5569 ChangeLog --- a/ChangeLog Mon Feb 07 11:20:31 2011 +0000 +++ b/ChangeLog Mon Feb 07 11:24:07 2011 +0000 @@ -1,3 +1,9 @@ +2011-02-07 Ingo Weinzierl + + * artifact-database/src/main/java/de/intevation/artifactdatabase/ProtocolUtils.java: + Added new methods to append the current state and the reachable states to + a root node. + 2011-02-07 Ingo Weinzierl * artifact-database/src/main/java/de/intevation/artifactdatabase/state/StateEngine.java: diff -r 9ece61d918b1 -r ab646e0f5569 artifact-database/src/main/java/de/intevation/artifactdatabase/ProtocolUtils.java --- a/artifact-database/src/main/java/de/intevation/artifactdatabase/ProtocolUtils.java Mon Feb 07 11:20:31 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/ProtocolUtils.java Mon Feb 07 11:24:07 2011 +0000 @@ -7,13 +7,14 @@ */ package de.intevation.artifactdatabase; -import org.apache.log4j.Logger; +import java.util.List; import org.w3c.dom.Element; -import org.w3c.dom.Node; import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.artifactdatabase.state.State; + /** * This class provides methods that help creating the artifact protocol @@ -102,5 +103,46 @@ new String[] {"value"}, new String[] {hash})); } + + + /** + * This method appends a node that describes the current state to + * root. + * + * @param creator The ElementCreator used to create new elements. + * @param root The parent node for new elements. + * @param state The state to be appended. + */ + public static void appendState( + XMLUtils.ElementCreator creator, Element root, State state) + { + root.appendChild(createArtNode( + creator, "state", + new String[] { "description", "name" }, + new String[] { state.getDescription(), state.getID() })); + } + + + /** + * This method appends a node with reachable states to root. + * + * @param creator The ElementCreator used to create new elements. + * @param root The parent node for new elements. + * @param states The reachable states to be appended. + */ + public static void appendReachableStates( + XMLUtils.ElementCreator creator, + Element root, + List states) + { + Element reachable = createArtNode( + creator, "reachable-states", null, null); + + for (State s: states) { + appendState(creator, reachable, s); + } + + root.appendChild(reachable); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: