changeset 118:39957898c694

Improved top level exception handling and logging.
author Raimund Renkert <rrenkert@intevation.de>
date Thu, 16 Jun 2011 14:06:09 +0200
parents 6c3d880db7c5
children 84f202b6aa65
files ChangeLog src/java/de/intevation/mxd/Converter.java src/java/de/intevation/mxd/reader/FeatureLayerReader.java src/java/de/intevation/mxd/reader/GdbRasterCatalogLayerReader.java src/java/de/intevation/mxd/reader/ILayerReader.java src/java/de/intevation/mxd/reader/MXDReader.java
diffstat 6 files changed, 40 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Jun 16 12:05:34 2011 +0200
+++ b/ChangeLog	Thu Jun 16 14:06:09 2011 +0200
@@ -1,3 +1,15 @@
+2011-06-16  Raimund Renkert  <raimund.renkert@intevation.de>
+
+	Improved top level exception handling and logging.
+
+	* src/java/de/intevation/mxd/Converter.java,
+	  src/java/de/intevation/mxd/reader/FeatureLayerReader.java,
+	  src/java/de/intevation/mxd/reader/GdbRasterCatalogLayerReader.java,
+	  src/java/de/intevation/mxd/reader/ILayerReader.java,
+	  src/java/de/intevation/mxd/reader/MXDReader.java:
+	  The converter stops if an error occured while reading the mxd file.
+	  Replaced console output with a logger that writes to stdout.
+
 2011-06-16  Raimund Renkert  <raimund.renkert@intevation.de>
 
 	* src/java/de/intevation/mxd/reader/FeatureLayerReader.java,
--- a/src/java/de/intevation/mxd/Converter.java	Thu Jun 16 12:05:34 2011 +0200
+++ b/src/java/de/intevation/mxd/Converter.java	Thu Jun 16 14:06:09 2011 +0200
@@ -111,7 +111,7 @@
             reader.shutdown();
         }
         catch(Exception e) {
-            e.printStackTrace();
+            logger.error(e.getMessage());
         }
     }
 
--- a/src/java/de/intevation/mxd/reader/FeatureLayerReader.java	Thu Jun 16 12:05:34 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/FeatureLayerReader.java	Thu Jun 16 14:06:09 2011 +0200
@@ -58,7 +58,8 @@
      *
      * @return The layer XML element.
      */
-    public Element read() {
+    public Element read()
+    throws IOException{
         logger.debug("read()");
         Element layerElement;
         try {
@@ -66,7 +67,9 @@
         }
         catch(Exception e) {
             logger.error("Failed to create DOM-Element for Layer.");
-            return null;
+            throw new IOException(
+                this.getClass()+toString() +
+                "Error creating dom element");
         }
 
         try {
@@ -157,7 +160,9 @@
         }
         catch(IOException ioe) {
             logger.warn("Could not read datasource. Stopped reading layer.");
-            return null;
+            throw new IOException(
+                this.getClass().toString() +
+                "Error reading datasource.");
         }
 
         try {
@@ -198,7 +203,9 @@
             logger.error(
                 "Could not read layer datasource." +
                 " Stopped reading layer.");
-            return null;
+            throw new IOException(
+                this.getClass().toString() +
+                " Error reading data source.");
         }
         return layerElement;
     }
--- a/src/java/de/intevation/mxd/reader/GdbRasterCatalogLayerReader.java	Thu Jun 16 12:05:34 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/GdbRasterCatalogLayerReader.java	Thu Jun 16 14:06:09 2011 +0200
@@ -55,7 +55,8 @@
      *
      * @return The layer XML element.
      */
-    public Element read() {
+    public Element read()
+    throws IOException {
         logger.debug("read()");
 
         Element layerElement;
@@ -66,7 +67,9 @@
             logger.error(
                 "Could not create DOM element for layer." +
                 "Stopped reading layer.");
-            return null;
+            throw new IOException(
+                this.getClass()+toString() +
+                "Error creating dom element");
         }
 
         try {
--- a/src/java/de/intevation/mxd/reader/ILayerReader.java	Thu Jun 16 12:05:34 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/ILayerReader.java	Thu Jun 16 14:06:09 2011 +0200
@@ -1,6 +1,7 @@
 package de.intevation.mxd.reader;
 
 import org.w3c.dom.Element;
+import java.io.IOException;
 
 import de.intevation.mxd.utils.MapToXMLUtils;
 
@@ -12,7 +13,7 @@
 public interface ILayerReader{
 
     void setUtil(MapToXMLUtils util);
-    Element read();
+    Element read() throws IOException;
 
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/src/java/de/intevation/mxd/reader/MXDReader.java	Thu Jun 16 12:05:34 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/MXDReader.java	Thu Jun 16 14:06:09 2011 +0200
@@ -39,13 +39,14 @@
     private ArcGISInitializer initializer = null;
     private MapToXMLUtils util;
     private IMap map;
-
+    private int invalidLayerCount;
 
     public MXDReader()
     throws IOException {
         logger.debug("constructor()");
         initializer = new ArcGISInitializer();
         util = new MapToXMLUtils();
+        invalidLayerCount = 0;
     }
 
 
@@ -188,11 +189,15 @@
                     }
                 }
                 catch(Exception e) {
-                    e.printStackTrace();
-                    return false;
+                    invalidLayerCount++;
+                    if(i == 0 && (i + 1) < map.getLayerCount() ||
+                       invalidLayerCount == map.getLayerCount()) {
+                        throw new IOException(
+                            "No valid layer in MXD file." +
+                            " Aborting.");
+                    }
                 }
             }
-            util.print();
         }
         return true;
     }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)