changeset 1779:2fe270661b20

Let Output and Attribute Parsers collect Facets during processing. flys-artifacts/trunk@3101 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 28 Oct 2011 09:08:48 +0000
parents 5a1d59926a72
children b503d92dd709
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeParser.java flys-artifacts/src/main/java/de/intevation/flys/collections/OutputParser.java
diffstat 3 files changed, 56 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Oct 28 09:02:48 2011 +0000
+++ b/flys-artifacts/ChangeLog	Fri Oct 28 09:08:48 2011 +0000
@@ -1,3 +1,12 @@
+2011-10-28	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	Let OutputParser and AttributeParser collect all facets on the way.
+
+	* src/main/java/de/intevation/flys/collections/OutputParser.java,
+	  src/main/java/de/intevation/flys/collections/AttributeParser.java:
+	  Collect all facets while iterating over Outputs and Attributes,
+	  documentation added.
+
 2011-10-28	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	Extracted getFlysContext from FLYSArtifacts into FLYSUtils.
--- a/flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeParser.java	Fri Oct 28 09:02:48 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeParser.java	Fri Oct 28 09:08:48 2011 +0000
@@ -1,6 +1,8 @@
 package de.intevation.flys.collections;
 
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import javax.xml.xpath.XPathConstants;
@@ -15,6 +17,7 @@
 import de.intevation.artifacts.ArtifactNamespaceContext;
 
 import de.intevation.artifactdatabase.state.DefaultOutput;
+import de.intevation.artifactdatabase.state.Facet;
 import de.intevation.artifactdatabase.state.Output;
 
 import de.intevation.artifacts.common.utils.XMLUtils;
@@ -22,22 +25,27 @@
 import de.intevation.flys.artifacts.model.ManagedFacet;
 import de.intevation.flys.artifacts.model.ManagedDomFacet;
 
-
+/**
+ * Access parts of the Attribute parts of a FLYSCollections description
+ * document.
+ */
 public class AttributeParser {
 
     /** Constant XPath that points to the outputmodes of an artifact. */
     public static final String XPATH_ARTIFACT_OUTPUTMODES =
         "/art:attribute/art:outputs/art:output";
 
-
     private static Logger logger = Logger.getLogger(AttributeParser.class);
 
-
     protected Map<String, Output> outs;
 
+    /** List of facets. */
+    protected List<Facet> facets;
+
 
     public AttributeParser() {
-        this.outs = new HashMap<String, Output>();
+        this.outs   = new HashMap<String, Output>();
+        this.facets = new ArrayList<Facet>();
     }
 
 
@@ -67,7 +75,11 @@
     }
 
 
+    /**
+     * Adds item (a ManagedFacet) to an out.
+     */
     protected void addItem(String out, ManagedFacet item) {
+        this.facets.add(item);
         Output o = outs.get(out);
 
         if (o != null) {
@@ -91,6 +103,15 @@
     }
 
 
+    /**
+     * Access all facets.
+     * @return list of all facets.
+     */
+    public List<Facet> getFacets() {
+        return this.facets;
+    }
+
+
     protected void parseItems(Node out, String outname) {
         NodeList themes = (NodeList) XMLUtils.xpath(
             out, "art:facet",
--- a/flys-artifacts/src/main/java/de/intevation/flys/collections/OutputParser.java	Fri Oct 28 09:02:48 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/OutputParser.java	Fri Oct 28 09:08:48 2011 +0000
@@ -32,8 +32,12 @@
     protected CallMeta         meta;
     protected CallContext      context;
 
+    /** Map outputs name to Output. */
     protected Map<String, Output> outs;
 
+    /** Map facets name to list of Facets. */
+    protected List<Facet> facets;
+
 
     /**
      * @param db Database used to fetch artifacts, outputs and facets.
@@ -43,11 +47,12 @@
         this.meta    = context.getMeta();
         this.context = context;
         this.outs    = new HashMap<String, Output>();
+        this.facets  = new ArrayList<Facet>();
     }
 
 
     /**
-     * Gets raw facet with given id and sorts outputs in mapping.
+     * Gets raw artifact with given id and sorts outputs in mapping.
      * Converts Facets to ManagedFacets on the way.
      * @param uuid uuid of artifact to load from database.
      */
@@ -80,8 +85,9 @@
                 pos = o.getFacets().size() + 1;
             }
 
-            List<Facet> facets = facet2ManagedFacet(uuid, out.getFacets(), pos);
-            o.addFacets(facets);
+            List<Facet> mfacets = facet2ManagedFacet(uuid, out.getFacets(), pos);
+            o.addFacets(mfacets);
+            this.facets.addAll(mfacets);
         }
     }
 
@@ -94,6 +100,19 @@
     }
 
 
+    /**
+     * Access all facets.
+     */
+    public List<Facet> getFacets() {
+        return this.facets;
+    }
+
+
+    /**
+     * Creates a list of ManagedFacets from list of Facets.
+     * @param pos Position of first facet (for each other the positions
+     *            will be increased).
+     */
     protected List<Facet> facet2ManagedFacet(
         String      uuid,
         List<Facet> old,

http://dive4elements.wald.intevation.org