changeset 117:6c3d880db7c5

Improved exception handling for layer reader.
author Raimund Renkert <rrenkert@intevation.de>
date Thu, 16 Jun 2011 12:05:34 +0200
parents c8a1361ddd38
children 39957898c694
files ChangeLog 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/UniqueValueRendererReader.java
diffstat 5 files changed, 202 insertions(+), 67 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Jun 15 18:37:27 2011 +0200
+++ b/ChangeLog	Thu Jun 16 12:05:34 2011 +0200
@@ -1,3 +1,11 @@
+2011-06-16  Raimund Renkert  <raimund.renkert@intevation.de>
+
+	* 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/UniqueValueRendererReader.java:
+	  Improved exception handling for layer reader.
+
 2011-06-15  Raimund Renkert  <raimund.renkert@intevation.de>
 
 	* src/java/de/intevation/mxd/reader/ClassBreakRendererReader.java,
--- a/src/java/de/intevation/mxd/reader/FeatureLayerReader.java	Wed Jun 15 18:37:27 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/FeatureLayerReader.java	Thu Jun 16 12:05:34 2011 +0200
@@ -10,6 +10,7 @@
 import org.w3c.dom.Element;
 
 import de.intevation.mxd.utils.MapToXMLUtils;
+import java.io.IOException;
 
 /**
  * Reads Layer information.
@@ -57,24 +58,74 @@
      *
      * @return The layer XML element.
      */
-    public Element read()
-    throws Exception {
+    public Element read() {
         logger.debug("read()");
-        Element layerElement = util.addLayer();
+        Element layerElement;
+        try {
+            layerElement = util.addLayer();
+        }
+        catch(Exception e) {
+            logger.error("Failed to create DOM-Element for Layer.");
+            return null;
+        }
 
-        layerElement.setAttribute("name", layer.getName());
-        layerElement.setAttribute("min_scale",
-            String.valueOf(layer.getMinimumScale()));
-        layerElement.setAttribute("max_scale",
-            String.valueOf(layer.getMaximumScale()));
-        if(layer.isVisible()) {
+        try {
+            layerElement.setAttribute("name", layer.getName());
+        }
+        catch(IOException ioe) {
+            logger.warn(
+                "Could not read name." +
+                " Setting name to \"default-layer\"");
+            layerElement.setAttribute("name", "default-layer");
+        }
+
+        try {
+            layerElement.setAttribute("min_scale",
+                String.valueOf(layer.getMinimumScale()));
+        }
+        catch(IOException ioe) {
+            logger.warn(
+                "Could not read minimum scale." +
+                " Setting minimum scale to 0.");
+            layerElement.setAttribute("min_scale", "0");
+        }
+
+        try {
+            layerElement.setAttribute("max_scale",
+                String.valueOf(layer.getMaximumScale()));
+        }
+        catch(IOException ioe) {
+            logger.warn(
+                "Could not read maximum scale." +
+                " Setting maximum scale to 0.");
+            layerElement.setAttribute("max_scale", "0");
+        }
+
+        try {
+            if(layer.isVisible()) {
+                layerElement.setAttribute("status", "on");
+            }
+            else {
+                layerElement.setAttribute("status", "off");
+            }
+        }
+        catch(IOException ioe) {
+            logger.warn(
+                "Could not read layer status." +
+                " Setting layer status to \"on\".");
             layerElement.setAttribute("status", "on");
         }
-        else {
-            layerElement.setAttribute("status", "off");
+
+        int type = 0;
+        try {
+            type = layer.getShapeType();
         }
-
-        int type = layer.getShapeType();
+        catch(IOException ioe) {
+            logger.warn(
+                "Could not read shape type." +
+                " Setting shape type to \"none\".");
+            type = 0;
+        }
         switch (type) {
             case 0: layerElement.setAttribute("type", "none"); break;
             case 1: layerElement.setAttribute("type", "point"); break;
@@ -82,50 +133,73 @@
             case 4: layerElement.setAttribute("type", "polygon"); break;
         }
 
-        layerElement.setAttribute("definition_query",
-            layer.getDefinitionExpression());
-        IName fcn = layer.getDataSourceName();
-        if(fcn instanceof FeatureClassName) {
-            FeatureClassName name = (FeatureClassName)fcn;
-            layerElement.setAttribute("data_source", name.getName());
+        try {
+            layerElement.setAttribute("definition_query",
+                layer.getDefinitionExpression());
         }
-        else {
-            logger.debug ("Unknown FeatureClass name:" + fcn.getClass().toString());
+        catch(IOException ioe) {
+            logger.warn(
+                "Could not read definition query." +
+                " Setting empty definition query.");
+            layerElement.setAttribute("definition_query", "");
+        }
+        try {
+            IName fcn = layer.getDataSourceName();
+            if(fcn instanceof FeatureClassName) {
+                FeatureClassName name = (FeatureClassName)fcn;
+                layerElement.setAttribute("data_source", name.getName());
+            }
+            else {
+                logger.debug (
+                    "Unknown FeatureClass name:" +
+                    fcn.getClass().toString());
+            }
+        }
+        catch(IOException ioe) {
+            logger.warn("Could not read datasource. Stopped reading layer.");
+            return null;
         }
 
+        try {
+            String datatype = layer.getDataSourceType();
+            if(datatype.equals("Shapefile Feature Class")) {
+                layerElement.setAttribute("connection_type", "local");
+                layerElement.setAttribute(
+                    "workspace",
+                    layer.getWorkspace().getPathName());
+            }
+            else if(datatype.equals("File Geodatabase Feature Class")){
+                layerElement.setAttribute("connection_type", "ogr");
+                layerElement.setAttribute("data", layer.getFeatureClass().getFeatureDataset().getName());
+                layerElement.setAttribute(
+                    "workspace",
+                    layer.getWorkspace().getPathName());
 
-        String datatype = layer.getDataSourceType();
-        if(datatype.equals("Shapefile Feature Class")) {
-            layerElement.setAttribute("connection_type", "local");
-            layerElement.setAttribute(
-                "workspace",
-                layer.getWorkspace().getPathName());
-        }
-        else if(datatype.equals("File Geodatabase Feature Class")){
-            layerElement.setAttribute("connection_type", "ogr");
-            layerElement.setAttribute("data", layer.getFeatureClass().getFeatureDataset().getName());
-            layerElement.setAttribute(
-                "workspace",
-                layer.getWorkspace().getPathName());
-
-        }
-        else if(datatype.equals("SDE Feature Class")) {
-            IPropertySet set = layer.getWorkspace().getConnectionProperties();
-            Object names[] = new Object[set.getCount()];
-            Object prop[] = new Object[set.getCount()];
-            set.getAllProperties(names, prop);
-            layerElement.setAttribute("connection_type", "SDE");
-            for(int i = 0; i < names.length; i++) {
-                if(names[i] != null) {
-                    String[] prop_names = (String[])names[i];
-                    for(int j = 0; j < prop_names.length; j++) {
-                        layerElement.setAttribute(
-                            prop_names[j].toLowerCase(),
-                            set.getProperty(prop_names[j]).toString());
+            }
+            else if(datatype.equals("SDE Feature Class")) {
+                IPropertySet set = layer.getWorkspace().getConnectionProperties();
+                Object names[] = new Object[set.getCount()];
+                Object prop[] = new Object[set.getCount()];
+                set.getAllProperties(names, prop);
+                layerElement.setAttribute("connection_type", "SDE");
+                for(int i = 0; i < names.length; i++) {
+                    if(names[i] != null) {
+                        String[] prop_names = (String[])names[i];
+                        for(int j = 0; j < prop_names.length; j++) {
+                            layerElement.setAttribute(
+                                prop_names[j].toLowerCase(),
+                                set.getProperty(prop_names[j]).toString());
+                        }
                     }
                 }
             }
         }
+        catch(Exception e) {
+            logger.error(
+                "Could not read layer datasource." +
+                " Stopped reading layer.");
+            return null;
+        }
         return layerElement;
     }
 }
--- a/src/java/de/intevation/mxd/reader/GdbRasterCatalogLayerReader.java	Wed Jun 15 18:37:27 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/GdbRasterCatalogLayerReader.java	Thu Jun 16 12:05:34 2011 +0200
@@ -6,7 +6,7 @@
 import com.esri.arcgis.carto.GdbRasterCatalogLayer;
 
 import org.w3c.dom.Element;
-
+import java.io.IOException;
 import de.intevation.mxd.utils.MapToXMLUtils;
 
 /**
@@ -55,26 +55,77 @@
      *
      * @return The layer XML element.
      */
-    public Element read()
-    throws Exception {
+    public Element read() {
         logger.debug("read()");
-        Element layerElement = util.addLayer();
 
-        layerElement.setAttribute("name", layer.getName());
-        layerElement.setAttribute("min_scale",
-            String.valueOf(layer.getMinimumScale()));
-        layerElement.setAttribute("max_scale",
-            String.valueOf(layer.getMaximumScale()));
-        if(layer.isVisible()) {
+        Element layerElement;
+        try {
+            layerElement = util.addLayer();
+        }
+        catch(Exception e) {
+            logger.error(
+                "Could not create DOM element for layer." +
+                "Stopped reading layer.");
+            return null;
+        }
+
+        try {
+            layerElement.setAttribute("name", layer.getName());
+        }
+        catch(IOException ioe) {
+            logger.warn(
+                "Could not read layer name. " +
+                "Setting layer name to \"default\".");
+            layerElement.setAttribute("name", "default");
+        }
+
+        try {
+            layerElement.setAttribute("min_scale",
+                String.valueOf(layer.getMinimumScale()));
+        }
+        catch(IOException ioe) {
+            logger.warn(
+                "Could not read minimum layer scale." +
+                "Setting minimum layer scale to 1000");
+            layerElement.setAttribute("min_scale", "1000");
+        }
+
+        try {
+            layerElement.setAttribute("max_scale",
+                String.valueOf(layer.getMaximumScale()));
+        }
+        catch(IOException ioe) {
+            logger.warn(
+                "Could not read maximum layer scale." +
+                "Setting maximum layer scale to 1000000");
+            layerElement.setAttribute("max_scale", "1000000");
+        }
+
+        try {
+            if(layer.isVisible()) {
+                layerElement.setAttribute("status", "on");
+            }
+            else {
+                layerElement.setAttribute("status", "off");
+            }
+        }
+        catch(IOException ioe) {
+            logger.warn(
+                "Could not read layer status." +
+                " Setting layer status to \"on\"");
             layerElement.setAttribute("status", "on");
         }
-        else {
-            layerElement.setAttribute("status", "off");
+
+        try {
+            layerElement.setAttribute("definition_query",
+                layer.getDefinitionExpression());
         }
-
-        layerElement.setAttribute("definition_query",
-            layer.getDefinitionExpression());
-
+        catch(IOException ioe) {
+            logger.warn(
+                "Could not read layer definition query." +
+                "Setting empty definition query.");
+            layerElement.setAttribute("definition_query", "");
+        }
         return layerElement;
     }
 }
--- a/src/java/de/intevation/mxd/reader/ILayerReader.java	Wed Jun 15 18:37:27 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/ILayerReader.java	Thu Jun 16 12:05:34 2011 +0200
@@ -12,7 +12,7 @@
 public interface ILayerReader{
 
     void setUtil(MapToXMLUtils util);
-    Element read() throws Exception;
+    Element read();
 
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/src/java/de/intevation/mxd/reader/UniqueValueRendererReader.java	Wed Jun 15 18:37:27 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/UniqueValueRendererReader.java	Thu Jun 16 12:05:34 2011 +0200
@@ -74,7 +74,9 @@
             count = renderer.getClassCount();
         }
         catch(IOException ioe) {
-            logger.error("Could not read class count. Stopped reading renderer.");
+            logger.error(
+                "Could not read class count."+
+                " Stopped reading renderer.");
             return layer;
         }
         for(int i = 0; i < count - 1; i++) {
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)