changeset 1988:158b3aabda2c

Prepare the OutGenerator during the describe() operation of the FLYS Collection to enable the OutGenerator to return an initial Settings object. flys-artifacts/trunk@3422 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 15 Dec 2011 10:09:02 +0000
parents 382e38164200
children 156304542edf
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java
diffstat 2 files changed, 43 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Thu Dec 15 09:43:54 2011 +0000
+++ b/flys-artifacts/ChangeLog	Thu Dec 15 10:09:02 2011 +0000
@@ -1,3 +1,9 @@
+2011-12-15  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java:
+	  Prepare the OutGenerator (process each of the Output's Facets) during the
+	  describe() operation to be able to return an initial Settings object.
+
 2011-12-15  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/exports/BooleanAttribute.java,
--- a/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java	Thu Dec 15 09:43:54 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java	Thu Dec 15 10:09:02 2011 +0000
@@ -245,8 +245,21 @@
     protected Settings createInitialOutputSettings(CallContext cc, String out) {
         OutGenerator outGen = getOutGenerator(cc, out, null);
 
-        // TODO simulate a real out() process and return finally the Settings
-        // object retrieved by the OutGenerator.
+        // XXX NOTE: the outGen is not able to process its generate() operation,
+        // because it has no OutputStream set!
+        outGen.init(XMLUtils.newDocument(), null, cc);
+        prepareMasterArtifact(outGen, cc);
+
+        try {
+            Document attr = getAttribute(cc, out);
+            doOut(outGen, out, out, attr, cc);
+        }
+        catch (ArtifactDatabaseException adbe) {
+            log.error(adbe, adbe);
+        }
+        catch (IOException ioe) {
+            log.error(ioe, ioe);
+        }
 
         return outGen.getSettings();
     }
@@ -291,24 +304,36 @@
         }
 
         generator.init(format, out, context);
+        prepareMasterArtifact(generator, context);
 
+        try {
+            Document attr = getAttribute(context, name);
+            doOut(generator, name, subtype, attr, context);
+            generator.generate();
+        }
+        catch (ArtifactDatabaseException adbe) {
+            log.error(adbe, adbe);
+        }
+    }
+
+
+    /**
+     * Sets the master Artifact at the given <i>generator</i>.
+     *
+     * @param generator The generator that gets a master Artifact.
+     * @param cc The CallContext.
+     */
+    protected void prepareMasterArtifact(OutGenerator generator, CallContext cc
+    ) {
         // Get master artifact.
-        FLYSArtifact master = getMasterArtifact(context);
+        FLYSArtifact master = getMasterArtifact(cc);
         if (master != null) {
-            log.debug("Will set master Artifact to uuid: " + master.identifier());
+            log.debug("Set master Artifact to uuid: " + master.identifier());
             generator.setMasterArtifact(master);
         }
         else {
             log.warn("Could not set master artifact.");
         }
-
-        try {
-            Document attr = getAttribute(context, name);
-            doOut(generator, name, subtype, attr, context);
-        }
-        catch (ArtifactDatabaseException adbe) {
-            log.error(adbe, adbe);
-        }
     }
 
 
@@ -376,8 +401,6 @@
         catch (ArtifactDatabaseException ade) {
             log.error(ade, ade);
         }
-
-        generator.generate();
     }
 
 

http://dive4elements.wald.intevation.org