changeset 4158:a699d6c42a8b

Override describe method to return also a uiprovider.
author Björn Ricks <bjoern.ricks@intevation.de>
date Tue, 16 Oct 2012 15:50:27 +0200
parents 44d27b8bb0bc
children bbae306fcb4f
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/AbstractStaticStateArtifact.java
diffstat 2 files changed, 75 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue Oct 16 15:47:36 2012 +0200
+++ b/flys-artifacts/ChangeLog	Tue Oct 16 15:50:27 2012 +0200
@@ -1,3 +1,9 @@
+2012-10-16	Björn Ricks	<bjoern.ricks@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/AbstractStaticStateArtifact.java:
+	  Use StaticState class instead of State in member staticstate.
+	  Override describe method to return also a uiprovider.
+
 2012-10-16	Björn Ricks	<bjoern.ricks@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/StaticFLYSArtifact.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/AbstractStaticStateArtifact.java	Tue Oct 16 15:47:36 2012 +0200
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/AbstractStaticStateArtifact.java	Tue Oct 16 15:50:27 2012 +0200
@@ -1,8 +1,22 @@
 package de.intevation.flys.artifacts;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 
+import org.apache.log4j.Logger;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import de.intevation.artifacts.CallContext;
+import de.intevation.artifacts.ArtifactNamespaceContext;
+
+import de.intevation.artifacts.common.utils.XMLUtils;
+import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
+
+import de.intevation.artifactdatabase.ProtocolUtils;
+import de.intevation.artifactdatabase.data.StateData;
 import de.intevation.artifactdatabase.state.State;
 
 import de.intevation.flys.artifacts.states.StaticState;
@@ -19,6 +33,9 @@
 
     private transient StaticState staticstate;
 
+    private static final Logger logger =
+        Logger.getLogger(AbstractStaticStateArtifact.class);
+
     /**
      * Get a list containing the one and only State.
      * @param  context ignored.
@@ -68,4 +85,56 @@
     protected State getState(Object context, String stateID) {
         return getStaticState();
     }
+
+    @Override
+    public Document describe(Document data, CallContext cc) {
+        logger.debug("Describe artifact: " + identifier());
+
+        Document desc = XMLUtils.newDocument();
+
+        ElementCreator creator = new ElementCreator(
+            desc,
+            ArtifactNamespaceContext.NAMESPACE_URI,
+            ArtifactNamespaceContext.NAMESPACE_PREFIX);
+
+        Element root = ProtocolUtils.createRootNode(creator);
+        desc.appendChild(root);
+
+        Element name = ProtocolUtils.createArtNode(
+            creator, "name",
+            new String[] { "value" },
+            new String[] { getName() });
+
+        root.appendChild(name);
+        root.appendChild(createOutputModes(cc, desc, creator));
+
+        ProtocolUtils.appendDescribeHeader(creator, root, identifier(), hash());
+
+        // Add the data to an anonymous state.
+        Collection<StateData> datas = getAllData();
+        if (datas.size() > 0) {
+            Element ui = creator.create("ui");
+            Element staticE = creator.create("static");
+
+            StaticState current = getStaticState();
+            Element state = current.describeStatic(this, desc, root, cc, null);
+            staticE.appendChild(state);
+
+            for (StateData dataItem : datas) {
+                Element itemelent = creator.create("data");
+                creator.addAttr(itemelent, "name", dataItem.getName(), true);
+                creator.addAttr(itemelent, "type", dataItem.getType(), true);
+                state.appendChild(itemelent);
+                Element valuement = creator.create("item");
+                creator.addAttr(valuement, "label", dataItem.getDescription(), true);
+                creator.addAttr(valuement, "value", dataItem.getValue().toString(), true);
+                itemelent.appendChild(valuement);
+            }
+
+            ui.appendChild(staticE);
+            root.appendChild(ui);
+        }
+
+        return desc;
+    }
 }

http://dive4elements.wald.intevation.org