diff src/java/de/intevation/mxd/reader/FeatureLayerReader.java @ 133:6b80d2c7536e

Improved broken layer handling.
author vc11884admin@VC11884.win.bsh.de
date Tue, 21 Jun 2011 15:22:06 +0200
parents 5991c1f90f91
children a4ab239509f1
line wrap: on
line diff
--- a/src/java/de/intevation/mxd/reader/FeatureLayerReader.java	Mon Jun 20 17:54:09 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/FeatureLayerReader.java	Tue Jun 21 15:22:06 2011 +0200
@@ -11,7 +11,7 @@
 
 import de.intevation.mxd.utils.MapToXMLUtils;
 import java.io.IOException;
-
+import com.esri.arcgis.interop.AutomationException;
 /**
  * Reads Layer information.
  *
@@ -67,9 +67,7 @@
         }
         catch(Exception e) {
             logger.error("Failed to create DOM-Element for Layer.");
-            throw new IOException(
-                this.getClass()+toString() +
-                "Error creating dom element");
+            return null;
         }
 
         try {
@@ -159,29 +157,32 @@
             }
         }
         catch(IOException ioe) {
-            logger.warn("Could not read datasource. Stopped reading layer.");
-            throw new IOException(
-                this.getClass().toString() +
-                "Error reading datasource.");
+            logger.warn(
+                "Could not read datasource." +
+                " Stopped reading layer " + layer.getName() + ".");
+            util.removeLayer(layerElement);
+            return null;
         }
 
         try {
             String datatype = layer.getDataSourceType();
-            if(datatype.equals("Shapefile Feature Class")) {
+            if(layer.getWorkspace().getType() == 0) {
                 layerElement.setAttribute("connection_type", "local");
                 layerElement.setAttribute(
                     "workspace",
                     layer.getWorkspace().getPathName());
             }
-            else if(datatype.equals("File Geodatabase Feature Class")){
+            else if(layer.getWorkspace().getType() == 1){
                 layerElement.setAttribute("connection_type", "ogr");
-                layerElement.setAttribute("data", layer.getFeatureClass().getFeatureDataset().getName());
+                layerElement.setAttribute(
+                    "data",
+                    layer.getFeatureClass().getFeatureDataset().getName());
                 layerElement.setAttribute(
                     "workspace",
                     layer.getWorkspace().getPathName());
 
             }
-            else if(datatype.equals("SDE Feature Class")) {
+            else if(layer.getWorkspace().getType() == 2) {
                 IPropertySet set = layer.getWorkspace().getConnectionProperties();
                 Object names[] = new Object[set.getCount()];
                 Object prop[] = new Object[set.getCount()];
@@ -197,29 +198,39 @@
                         }
                     }
                 }
-                layerElement.setAttribute(
-                    "join_table",
-                    layer.getRelationshipClass()
-                         .getOriginClass().getAliasName());
-                layerElement.setAttribute(
-                    "join_field",
-                    layer.getRelationshipClass().getOriginPrimaryKey());
-                layerElement.setAttribute(
-                    "join_table_target",
-                    layer.getRelationshipClass()
-                         .getDestinationClass().getAliasName());
-                layerElement.setAttribute(
-                    "join_field_target",
-                    layer.getRelationshipClass().getOriginForeignKey());
+                try {
+                    layerElement.setAttribute(
+                        "join_table",
+                        layer.getRelationshipClass()
+                             .getOriginClass().getAliasName());
+                    layerElement.setAttribute(
+                        "join_field",
+                        layer.getRelationshipClass().getOriginPrimaryKey());
+                    layerElement.setAttribute(
+                        "join_table_target",
+                        layer.getRelationshipClass()
+                             .getDestinationClass().getAliasName());
+                    layerElement.setAttribute(
+                        "join_field_target",
+                        layer.getRelationshipClass().getOriginForeignKey());
+                }
+                catch(AutomationException ioe) {
+                    //Do nothing, cause no jointable defined.
+                }
+                catch(IOException ae) {
+                    //Do nothing, cause no jointable defined.
+                }
+                catch(NullPointerException npe) {
+                    //Do nothing, cause no jointable defined.
+                }
             }
         }
         catch(Exception e) {
             logger.error(
                 "Could not read layer datasource." +
-                " Stopped reading layer.");
-            throw new IOException(
-                this.getClass().toString() +
-                " Error reading data source.");
+                " Stopped reading layer " + layer.getName() + ".");
+            util.removeLayer(layerElement);
+            return null;            
         }
         return layerElement;
     }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)