changeset 1999:02ce03329ef5

Some optimizations during out() operation of FLYSArtifactCollection. flys-artifacts/trunk@3437 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 16 Dec 2011 11:47:57 +0000 (2011-12-16)
parents 3862c50d1cf3
children e71719483546
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java
diffstat 2 files changed, 42 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Dec 16 10:50:19 2011 +0000
+++ b/flys-artifacts/ChangeLog	Fri Dec 16 11:47:57 2011 +0000
@@ -1,3 +1,10 @@
+2011-12-16  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java:
+	  Some optimizations during out() operation - the CollectionAttribute is
+	  parsed a single time now (*i guess*). This code really needs some
+	  refactoring!
+
 2011-12-16  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java	Fri Dec 16 10:50:19 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java	Fri Dec 16 11:47:57 2011 +0000
@@ -228,7 +228,8 @@
 
             if (settings == null) {
                 log.debug("No Settings set for Output '" + outName + "'.");
-                output.setSettings(createInitialOutputSettings(cc, outName));
+                output.setSettings(
+                    createInitialOutputSettings(cc, attribute, outName));
 
                 modified = true;
             }
@@ -241,18 +242,32 @@
     /**
      * This method uses the the OutGenerator for the specified Output
      * <i>out</i> to create an initial Settings object.
+     *
+     * @param cc The CallContext object.
+     * @param attr The CollectionAttribute.
+     * @param out The name of the output.
+     *
+     * @return a default Settings object for the specified Output.
      */
-    protected Settings createInitialOutputSettings(CallContext cc, String out) {
+    protected Settings createInitialOutputSettings(
+        CallContext         cc,
+        CollectionAttribute attr,
+        String              out
+    ) {
         OutGenerator outGen = getOutGenerator(cc, out, null);
 
+        if (outGen == null) {
+            return null;
+        }
+
         // 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);
+            Document outAttr = getAttribute(cc, attr, out);
+            doOut(outGen, out, out, outAttr, cc);
         }
         catch (ArtifactDatabaseException adbe) {
             log.error(adbe, adbe);
@@ -305,11 +320,18 @@
             return;
         }
 
+        Document        oldAttrs  = getAttribute();
+        AttributeParser parser    = new AttributeParser(oldAttrs);
+        CollectionAttribute cAttr = parser.getCollectionAttribute();
+
+        Output   output   = cAttr.getOutput(name);
+        Settings settings = output.getSettings();
+
         generator.init(format, out, context);
         prepareMasterArtifact(generator, context);
 
         try {
-            Document attr = getAttribute(context, name);
+            Document attr = getAttribute(context, cAttr, name);
             doOut(generator, name, subtype, attr, context);
             generator.generate();
         }
@@ -526,19 +548,18 @@
      * Returns the "attribute" (part of description document) for a specific
      * output type.
      *
+     * @param context The CallContext object.
+     * @param cAttr The CollectionAttribute.
      * @param output The name of the desired output type.
      *
      * @return the attribute for the desired output type.
      */
-    protected Document getAttribute(CallContext context, String output)
+    protected Document getAttribute(
+        CallContext         context,
+        CollectionAttribute cAttr,
+        String              output)
     throws    ArtifactDatabaseException
     {
-        CollectionAttribute cAttr = buildOutAttributes(
-            context.getDatabase(),
-            context,
-            new AttributeParser(getAttribute()),
-            getArtifactUUIDs(context));
-
         Document attr = cAttr.toXML();
 
         Node out = (Node) XMLUtils.xpath(
@@ -896,6 +917,8 @@
         String      name,
         String      type)
     {
+        log.debug("Search OutGenerator for Output '" + name + "'");
+
         FLYSContext flysContext = context instanceof FLYSContext
             ? (FLYSContext) context
             : (FLYSContext) context.globalContext();

http://dive4elements.wald.intevation.org