changeset 105:265f150f4f7f

Added an abstract implementation of a State. artifacts/trunk@1290 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 04 Feb 2011 08:55:17 +0000
parents 26bfff409dd3
children ece0fdb07975
files ChangeLog artifact-database/src/main/java/de/intevation/artifactdatabase/state/AbstractState.java
diffstat 2 files changed, 149 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Feb 03 18:00:41 2011 +0000
+++ b/ChangeLog	Fri Feb 04 08:55:17 2011 +0000
@@ -1,3 +1,10 @@
+2011-02-04  Ingo Weinzierl <ingo@intevation.de>
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/state/AbstractState.java:
+	  New. An abstract implementation of a State. Some basic getter and setter
+	  methods are implemented - setup() and describe() need to be implemented by
+	  concrete subclasses.
+
 2011-02-03  Ingo Weinzierl <ingo@intevation.de>
 
 	* artifact-database/src/main/java/de/intevation/artifactdatabase/state/StateEngine.java,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/state/AbstractState.java	Fri Feb 04 08:55:17 2011 +0000
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 2011 by Intevation GmbH
+ *
+ * This program is free software under the LGPL (>=v2.1)
+ * Read the file LGPL.txt coming with the software for details
+ * or visit http://www.gnu.org/licenses/ if it does not exist.
+ */
+package de.intevation.artifactdatabase.state;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+import de.intevation.artifacts.CallContext;
+
+import de.intevation.artifactdatabase.data.StateData;
+
+
+/**
+ * An abstract implementation of a {@link State}. It implements some basic
+ * methods that return the id, description and data. The methods
+ * <code>describe()</code> and <code>setup()</code> depend on the concrete class
+ * and need to be implemented by those.
+ */
+public abstract class AbstractState implements State {
+
+    /** The ID of the state. */
+    protected String id;
+
+    /** The description of the state. */
+    protected String description;
+
+    /** The data provided by this state. */
+    protected Map<String, StateData> data;
+
+
+    /**
+     * The default constructor.
+     *
+     * @param id The ID of the state.
+     * @param description The description of the state.
+     */
+    public AbstractState(String id, String description) {
+        this.id          = id;
+        this.description = description;
+    }
+
+
+    /**
+     * Returns the ID of the state.
+     *
+     * @return the ID of the state.
+     */
+    public String getID() {
+        return id;
+    }
+
+
+    /**
+     * Set the ID of the state.
+     *
+     * @param id The ID of the state.
+     */
+    public void setID(String id) {
+        this.id = id;
+    }
+
+
+    /**
+     * Returns the description of the state.
+     *
+     * @return the description of the state.
+     */
+    public String getDescription() {
+        return description;
+    }
+
+
+    /**
+     * Set the description of the state.
+     *
+     * @param description The description of the state.
+     */
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+
+    /**
+     * Returns the data of the state.
+     *
+     * @return the data of the state.
+     */
+    public Map<String, StateData> getData() {
+        return data;
+    }
+
+
+    /**
+     * Add new data to the state. NOTE: If there is already an object existing
+     * with the key <i>name</i>, this object is overwritten by the new value.
+     *
+     * @param name The name of the data object.
+     * @param StateData The data object.
+     */
+    public void addData(String name, StateData data) {
+        if (this.data == null) {
+            this.data = new HashMap<String, StateData>();
+        }
+
+        this.data.put(name, data);
+    }
+
+
+    /**
+     * Initialize the state based on the state node in the configuration. This
+     * method needs to be implemented by concrete subclasses.
+     *
+     * @param config The state configuration node.
+     */
+    public abstract void setup(Node config);
+
+
+    /**
+     * Describes the UI of the state. This method needs to be implemented by
+     * concrete subclasses.
+     *
+     * @param document Describe doucment.
+     * @param rootNode Parent node for all new elements.
+     * @param context The CallContext.
+     * @param uuid The uuid of an artifact.
+     */
+    public abstract void describe(
+        Document    document,
+        Node        rootNode,
+        CallContext context,
+        String      uuid
+    );
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org