changeset 226:41404961c804

Added support for facets - facets of output modes are read from configuration now. artifacts/trunk@1626 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 30 Mar 2011 14:45:15 +0000
parents da92e7f8040b
children 4bb6bfaca393
files ChangeLog artifact-database/src/main/java/de/intevation/artifactdatabase/state/AbstractState.java artifact-database/src/main/java/de/intevation/artifactdatabase/state/DefaultFacet.java artifact-database/src/main/java/de/intevation/artifactdatabase/state/DefaultOutput.java artifact-database/src/main/java/de/intevation/artifactdatabase/state/Facet.java artifact-database/src/main/java/de/intevation/artifactdatabase/state/Output.java
diffstat 6 files changed, 182 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Mar 30 13:35:37 2011 +0000
+++ b/ChangeLog	Wed Mar 30 14:45:15 2011 +0000
@@ -1,3 +1,20 @@
+2011-03-30  Ingo Weinzierl <ingo@intevation.de>
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/state/DefaultFacet.java,
+	  artifact-database/src/main/java/de/intevation/artifactdatabase/state/Facet.java:
+	  New. A facet and its default implementation. A facet represents one
+	  piece of an concrete output. E.g. an output can be a chart, a facet can
+	  be a single curve in this chart.
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/state/DefaultOutput.java,
+	  artifact-database/src/main/java/de/intevation/artifactdatabase/state/Output.java:
+	  Added methods to retrieve and set facets.
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/state/AbstractState.java:
+	  Added code to parse facets in the inner of an output node of the
+	  transition configuration. The xpath to a facet relative to a state
+	  should look like this: state/outputmodes/outputmode/facets/facet.
+
 2011-03-30  Ingo Weinzierl <ingo@intevation.de>
 
 	Tagged as RELEASE 1.1
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/state/AbstractState.java	Wed Mar 30 13:35:37 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/state/AbstractState.java	Wed Mar 30 14:45:15 2011 +0000
@@ -14,6 +14,8 @@
 
 import javax.xml.xpath.XPathConstants;
 
+import org.apache.log4j.Logger;
+
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -46,6 +48,14 @@
     /** The XPath to the output nodes of the state configuration.*/
     public static final String XPATH_OUTPUT_MODES = "outputmodes/outputmode";
 
+    /** The XPath to the list of facets relative to the output mode it belongs
+     * to.*/
+    public static final String XPATH_FACETS = "facets/facet";
+
+
+    /** The logger that is used in this class.*/
+    private static Logger logger = Logger.getLogger(AbstractState.class);
+
 
     /** The ID of the state. */
     protected String id;
@@ -163,6 +173,8 @@
      * @param config The state configuration node.
      */
     public void setup(Node config) {
+        logger.info("AbstractState.setup");
+
         id = (String) XMLUtils.xpath(config, XPATH_ID, XPathConstants.STRING);
 
         description = (String) XMLUtils.xpath(
@@ -215,7 +227,52 @@
         String mimetype = XMLUtils.xpathString(
             out, "@mime-type", ArtifactNamespaceContext.INSTANCE);
 
-        return name != null ? new DefaultOutput(name, desc, mimetype) : null;
+        if (name == null) {
+            return null;
+        }
+
+        NodeList facets = (NodeList) XMLUtils.xpath(
+            out,
+            XPATH_FACETS,
+            XPathConstants.NODESET,
+            ArtifactNamespaceContext.INSTANCE);
+
+        if (facets == null || facets.getLength() == 0) {
+            return new DefaultOutput(name, desc, mimetype);
+        }
+
+        int num = facets.getLength();
+
+        List<Facet> facetList = new ArrayList<Facet>(num);
+
+        for (int i = 0; i < num; i++) {
+            Facet facet = buildFacet(facets.item(i));
+
+            if (facet != null) {
+                facetList.add(facet);
+            }
+        }
+
+        return new DefaultOutput(name, desc, mimetype, facetList);
+    }
+
+
+    /**
+     * A helper method that creates a Facet object based on the <i>facet</i>
+     * node.
+     *
+     * @param facet The facet node.
+     *
+     * @return a Facet object or null if no valid Facet was found.
+     */
+    protected Facet buildFacet(Node facet) {
+        String name = XMLUtils.xpathString(
+            facet, "@name", ArtifactNamespaceContext.INSTANCE);
+
+        String desc = XMLUtils.xpathString(
+            facet, "@description", ArtifactNamespaceContext.INSTANCE);
+
+        return name != null ? new DefaultFacet(name, desc) : null;
     }
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/state/DefaultFacet.java	Wed Mar 30 14:45:15 2011 +0000
@@ -0,0 +1,39 @@
+package de.intevation.artifactdatabase.state;
+
+
+/**
+ * The default implementation of a Facet.
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class DefaultFacet implements Facet {
+
+    /** The name of this facet.*/
+    protected String name;
+
+    /** The description of this facet.*/
+    protected String description;
+
+
+    /**
+     * The default constructor to create new Facet objects.
+     *
+     * @param name The name of this new facet.
+     * @param description The description of this new facet.
+     */
+    public DefaultFacet(String name, String description) {
+        this.name        = name;
+        this.description = description;
+    }
+
+
+    public String getName() {
+        return name;
+    }
+
+
+    public String getDescription() {
+        return description;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/state/DefaultOutput.java	Wed Mar 30 13:35:37 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/state/DefaultOutput.java	Wed Mar 30 14:45:15 2011 +0000
@@ -1,5 +1,8 @@
 package de.intevation.artifactdatabase.state;
 
+import java.util.ArrayList;
+import java.util.List;
+
 
 /**
  * The default implementation of an Output.
@@ -14,6 +17,8 @@
 
     protected String mimeType;
 
+    protected List<Facet> facets;
+
 
     /**
      * The default constructor that instantiates a new DefaultOutput object.
@@ -30,6 +35,26 @@
 
 
     /**
+     * This constructor builds a new Output object that contains facets as well.
+     *
+     * @param name The name of this output.
+     * @param description The description of this output.
+     * @param mimeType The mimetype of this output.
+     * @param facets The list of facets supported by this output.
+     */
+    public DefaultOutput(
+        String      name,
+        String      description,
+        String      mimeType,
+        List<Facet> facets)
+    {
+        this(name, description, mimeType);
+
+        this.facets = facets;
+    }
+
+
+    /**
      * Returns the name of this output.
      *
      * @return the name of this output.
@@ -57,5 +82,15 @@
     public String getMimeType() {
         return mimeType;
     }
+
+
+    /**
+     * Returns the list of facets supported by this output.
+     *
+     * @return the list of facets supported by this output.
+     */
+    public List<Facet> getFacets() {
+        return facets;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/state/Facet.java	Wed Mar 30 14:45:15 2011 +0000
@@ -0,0 +1,24 @@
+package de.intevation.artifactdatabase.state;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public interface Facet {
+
+    /**
+     * Returns the name of this facet.
+     *
+     * @return the name of this facet.
+     */
+    String getName();
+
+
+    /**
+     * Returns the description of this facet.
+     *
+     * @return the description of this facet.
+     */
+    String getDescription();
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/state/Output.java	Wed Mar 30 13:35:37 2011 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/state/Output.java	Wed Mar 30 14:45:15 2011 +0000
@@ -1,5 +1,7 @@
 package de.intevation.artifactdatabase.state;
 
+import java.util.List;
+
 
 /**
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
@@ -26,5 +28,12 @@
      * @return the mimetype.
      */
     public String getMimeType();
+
+    /**
+     * Retrieve the facets of this output.
+     *
+     * @return the facets of this output.
+     */
+    public List<Facet> getFacets();
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org