# HG changeset patch # User Ingo Weinzierl # Date 1296816653 0 # Node ID ece0fdb07975de96881171ce5447e0dbad24bca4 # Parent 265f150f4f7f74378f0d9178e99f4afb6a7cc34d Implementations to initialize and retrieve states. artifacts/trunk@1291 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 265f150f4f7f -r ece0fdb07975 ChangeLog --- a/ChangeLog Fri Feb 04 08:55:17 2011 +0000 +++ b/ChangeLog Fri Feb 04 10:50:53 2011 +0000 @@ -1,3 +1,15 @@ +2011-02-04 Ingo Weinzierl + + * artifact-database/src/main/java/de/intevation/artifactdatabase/state/AbstractState.java: + Implements the method setup() - the ID and the description of the state + are extracted at this place. + + * artifact-database/src/main/java/de/intevation/artifactdatabase/state/StateEngine.java: + Added a method to retrieve the states of a specified artifact. + + * artifact-database/pom.xml: Added a dependency to the artifacts-common + package. + 2011-02-04 Ingo Weinzierl * artifact-database/src/main/java/de/intevation/artifactdatabase/state/AbstractState.java: diff -r 265f150f4f7f -r ece0fdb07975 artifact-database/pom.xml --- a/artifact-database/pom.xml Fri Feb 04 08:55:17 2011 +0000 +++ b/artifact-database/pom.xml Fri Feb 04 10:50:53 2011 +0000 @@ -50,6 +50,11 @@ 1.0-SNAPSHOT + de.intevation.artifacts.common + artifacts-common + 1.0-SNAPSHOT + + org.restlet.jse org.restlet 2.0.4 diff -r 265f150f4f7f -r ece0fdb07975 artifact-database/src/main/java/de/intevation/artifactdatabase/state/AbstractState.java --- a/artifact-database/src/main/java/de/intevation/artifactdatabase/state/AbstractState.java Fri Feb 04 08:55:17 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/state/AbstractState.java Fri Feb 04 10:50:53 2011 +0000 @@ -10,11 +10,15 @@ import java.util.HashMap; import java.util.Map; +import javax.xml.xpath.XPathConstants; + import org.w3c.dom.Document; import org.w3c.dom.Node; import de.intevation.artifacts.CallContext; +import de.intevation.artifacts.common.utils.XMLUtils; + import de.intevation.artifactdatabase.data.StateData; @@ -26,6 +30,15 @@ */ public abstract class AbstractState implements State { + /** The XPath to the ID of the state relative to the state node in the + * configuration. */ + public static final String XPATH_ID = "@id"; + + /** The XPath to the description of the state relative to the state node in + * the configuration. */ + public static final String XPATH_DESCRIPTION = "@description"; + + /** The ID of the state. */ protected String id; @@ -115,12 +128,16 @@ /** - * Initialize the state based on the state node in the configuration. This - * method needs to be implemented by concrete subclasses. + * Initialize the state based on the state node in the configuration. * * @param config The state configuration node. */ - public abstract void setup(Node config); + public void setup(Node config) { + id = (String) XMLUtils.xpath(config, XPATH_ID, XPathConstants.STRING); + + description = (String) XMLUtils.xpath( + config, XPATH_DESCRIPTION, XPathConstants.STRING); + } /** diff -r 265f150f4f7f -r ece0fdb07975 artifact-database/src/main/java/de/intevation/artifactdatabase/state/StateEngine.java --- a/artifact-database/src/main/java/de/intevation/artifactdatabase/state/StateEngine.java Fri Feb 04 08:55:17 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/state/StateEngine.java Fri Feb 04 10:50:53 2011 +0000 @@ -53,5 +53,18 @@ logger.debug("Add new states for the artifact '" + artifact + "'"); return this.states.put(artifact, states) != null; } + + + /** + * Returns the state list of an artifact specified by its name. + * + * @param artifact The name of the artifact. + * + * @return the list of states of this artifact or null if no states + * are existing for this artifact. + */ + public List getStates(String artifact) { + return states.get(artifact); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :