Mercurial > mxd2map
changeset 116:c8a1361ddd38
Improved exceptionhandlin for renderer reader.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Wed, 15 Jun 2011 18:37:27 +0200 |
parents | fb93f20478cc |
children | 6c3d880db7c5 |
files | ChangeLog src/java/de/intevation/mxd/reader/ClassBreakRendererReader.java src/java/de/intevation/mxd/reader/IRendererReader.java src/java/de/intevation/mxd/reader/SimpleRendererReader.java src/java/de/intevation/mxd/reader/UniqueValueRendererReader.java |
diffstat | 5 files changed, 182 insertions(+), 111 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Wed Jun 15 16:48:42 2011 +0200 +++ b/ChangeLog Wed Jun 15 18:37:27 2011 +0200 @@ -1,3 +1,11 @@ +2011-06-15 Raimund Renkert <raimund.renkert@intevation.de> + + * src/java/de/intevation/mxd/reader/ClassBreakRendererReader.java, + src/java/de/intevation/mxd/reader/IRendererReader.java, + src/java/de/intevation/mxd/reader/SimpleRendererReader.java, + src/java/de/intevation/mxd/reader/UniqueValueRendererReader.java: + Improved exception handling. + 2011-06-15 Raimund Renkert <raimund.renkert@intevation.de> Improved exception handling.
--- a/src/java/de/intevation/mxd/reader/ClassBreakRendererReader.java Wed Jun 15 16:48:42 2011 +0200 +++ b/src/java/de/intevation/mxd/reader/ClassBreakRendererReader.java Wed Jun 15 18:37:27 2011 +0200 @@ -11,6 +11,7 @@ import org.w3c.dom.Element; import de.intevation.mxd.utils.MapToXMLUtils; +import java.io.IOException; /** * Reads the ClassBreaksRender Object Attributes. @@ -66,53 +67,72 @@ * * @return The XML node. */ - public Element read() - throws Exception { + public Element read() { logger.debug("read()"); - for(int i = 0; i < renderer.getBreakCount(); i++){ - Element rendererElement = util.addRenderer(layer); - rendererElement.setAttribute("value", - String.valueOf(renderer.getBreak(i))); - rendererElement.setAttribute( - "field_count", - String.valueOf(renderer.getFieldCount())); - for(int j = 0; j < renderer.getFieldCount(); j++) { - rendererElement.setAttribute( - "expression_field_" + j, - renderer.getField(j)); - - } - rendererElement.setAttribute( - "min_value", - String.valueOf(renderer.getMinimumBreak())); - rendererElement.setAttribute("expression_operator", "<="); + int count = 0; + try { + count = renderer.getBreakCount(); + } + catch(IOException ioe) { + logger.warn( + "No break symbols found in renderer." + + " Stopped reading this renderer."); + return layer; + } - ISymbol sym = renderer.getSymbol(i); - MarkerSymbolReader markerReader = new MarkerSymbolReader(); - LineSymbolReader lineReader = new LineSymbolReader(); - FillSymbolReader fillReader = new FillSymbolReader(); - if(markerReader.canRead(sym)) { - markerReader.setSymbol(sym); - markerReader.setUtil(util); - markerReader.setParent(rendererElement); - markerReader.read(); + for(int i = 0; i < count; i++){ + Element rendererElement = util.addRenderer(layer); + try { + rendererElement.setAttribute("value", + String.valueOf(renderer.getBreak(i))); + + rendererElement.setAttribute( + "field_count", + String.valueOf(renderer.getFieldCount())); + for(int j = 0; j < renderer.getFieldCount(); j++) { + rendererElement.setAttribute( + "expression_field_" + j, + renderer.getField(j)); + + } + rendererElement.setAttribute( + "min_value", + String.valueOf(renderer.getMinimumBreak())); + rendererElement.setAttribute("expression_operator", "<="); + + ISymbol sym = renderer.getSymbol(i); + MarkerSymbolReader markerReader = new MarkerSymbolReader(); + LineSymbolReader lineReader = new LineSymbolReader(); + FillSymbolReader fillReader = new FillSymbolReader(); + if(markerReader.canRead(sym)) { + markerReader.setSymbol(sym); + markerReader.setUtil(util); + markerReader.setParent(rendererElement); + markerReader.read(); + } + else if(lineReader.canRead(sym)) { + lineReader.setSymbol(sym); + lineReader.setUtil(util); + lineReader.setParent(rendererElement); + lineReader.read(); + } + else if(fillReader.canRead(sym)) { + fillReader.setSymbol(sym); + fillReader.setUtil(util); + fillReader.setParent(rendererElement); + fillReader.read(); + } + else { + logger.debug("Not a known symbol type: " + + sym.getClass().toString()); + } } - else if(lineReader.canRead(sym)) { - lineReader.setSymbol(sym); - lineReader.setUtil(util); - lineReader.setParent(rendererElement); - lineReader.read(); - } - else if(fillReader.canRead(sym)) { - fillReader.setSymbol(sym); - fillReader.setUtil(util); - fillReader.setParent(rendererElement); - fillReader.read(); - } - else { - logger.debug("Not a known symbol type: " + - sym.getClass().toString()); + catch(Exception e) { + logger.error( + "Could not read data for " + i + + ". break of renderer. Stopped reading this renderer."); + return layer; } } return layer;
--- a/src/java/de/intevation/mxd/reader/IRendererReader.java Wed Jun 15 16:48:42 2011 +0200 +++ b/src/java/de/intevation/mxd/reader/IRendererReader.java Wed Jun 15 18:37:27 2011 +0200 @@ -13,7 +13,7 @@ */ public interface IRendererReader{ - Element read() throws Exception; + Element read(); void setParent(Element parent); void setUtil(MapToXMLUtils util);
--- a/src/java/de/intevation/mxd/reader/SimpleRendererReader.java Wed Jun 15 16:48:42 2011 +0200 +++ b/src/java/de/intevation/mxd/reader/SimpleRendererReader.java Wed Jun 15 18:37:27 2011 +0200 @@ -7,6 +7,7 @@ import com.esri.arcgis.carto.SimpleRenderer; import org.w3c.dom.Element; +import java.io.IOException; import de.intevation.mxd.utils.MapToXMLUtils; @@ -67,39 +68,65 @@ * * @return The XML node. */ - public Element read() - throws Exception { + public Element read() { logger.debug("read()"); Element rendererElement; rendererElement = util.addRenderer(layer); - rendererElement.setAttribute("label", renderer.getLabel()); - rendererElement.setAttribute("description", renderer.getDescription()); - symbol = renderer.getSymbol(); - - MarkerSymbolReader markerReader = new MarkerSymbolReader(); - LineSymbolReader lineReader = new LineSymbolReader(); - FillSymbolReader fillReader = new FillSymbolReader(); - if(markerReader.canRead(symbol)) { - markerReader.setSymbol(symbol); - markerReader.setUtil(util); - markerReader.setParent(rendererElement); - markerReader.read(); + try { + rendererElement.setAttribute("label", renderer.getLabel()); } - else if(lineReader.canRead(symbol)) { - lineReader.setSymbol(symbol); - lineReader.setUtil(util); - lineReader.setParent(rendererElement); - lineReader.read(); + catch(IOException ioe) { + logger.warn( + "Could not read label name." + + "Setting label name to \"default-label\""); + rendererElement.setAttribute("label", "default-label"); } - else if(fillReader.canRead(symbol)) { - fillReader.setSymbol(symbol); - fillReader.setUtil(util); - fillReader.setParent(rendererElement); - fillReader.read(); + + try { + rendererElement.setAttribute( + "description", + renderer.getDescription()); } - else { - logger.debug("No known Symbol type: " + symbol.getClass().toString()); + catch(IOException ioe) { + logger.warn( + "Could not read description." + + " Setting empty description."); + rendererElement.setAttribute("description", ""); + } + + try { + symbol = renderer.getSymbol(); + + MarkerSymbolReader markerReader = new MarkerSymbolReader(); + LineSymbolReader lineReader = new LineSymbolReader(); + FillSymbolReader fillReader = new FillSymbolReader(); + if(markerReader.canRead(symbol)) { + markerReader.setSymbol(symbol); + markerReader.setUtil(util); + markerReader.setParent(rendererElement); + markerReader.read(); + } + else if(lineReader.canRead(symbol)) { + lineReader.setSymbol(symbol); + lineReader.setUtil(util); + lineReader.setParent(rendererElement); + lineReader.read(); + } + else if(fillReader.canRead(symbol)) { + fillReader.setSymbol(symbol); + fillReader.setUtil(util); + fillReader.setParent(rendererElement); + fillReader.read(); + } + else { + logger.debug( + "No known Symbol type: " + + symbol.getClass().toString()); + } + } + catch(Exception e) { + logger.error("Could not read symbol. Stopped reading renderer."); } return layer; }
--- a/src/java/de/intevation/mxd/reader/UniqueValueRendererReader.java Wed Jun 15 16:48:42 2011 +0200 +++ b/src/java/de/intevation/mxd/reader/UniqueValueRendererReader.java Wed Jun 15 18:37:27 2011 +0200 @@ -7,6 +7,7 @@ import com.esri.arcgis.carto.UniqueValueRenderer; import org.w3c.dom.Element; +import java.io.IOException; import de.intevation.mxd.utils.MapToXMLUtils; @@ -66,53 +67,68 @@ * * @return The parent XML node. */ - public Element read() - throws Exception { + public Element read() { logger.debug("read()"); - for(int i = 0; i < renderer.getClassCount() - 1; i++) { + int count = 0; + try { + count = renderer.getClassCount(); + } + catch(IOException ioe) { + logger.error("Could not read class count. Stopped reading renderer."); + return layer; + } + for(int i = 0; i < count - 1; i++) { Element rendererElement = util.addRenderer(layer); - String value = renderer.getValue(i); - rendererElement.setAttribute("name", renderer.esri_getClass(i)); - rendererElement.setAttribute("description", - renderer.getDescription(value)); - rendererElement.setAttribute("value", value); - rendererElement.setAttribute("label", renderer.getLabel(value)); - rendererElement.setAttribute( - "field_count", - String.valueOf(renderer.getFieldCount())); - for(int j = 0; j < renderer.getFieldCount(); j++) { + try { + String value = renderer.getValue(i); + rendererElement.setAttribute("name", renderer.esri_getClass(i)); + rendererElement.setAttribute("description", + renderer.getDescription(value)); + rendererElement.setAttribute("value", value); + rendererElement.setAttribute("label", renderer.getLabel(value)); rendererElement.setAttribute( - "expression_field_" + j, - renderer.getField(j)); - } - rendererElement.setAttribute("expression_operator", "="); + "field_count", + String.valueOf(renderer.getFieldCount())); + for(int j = 0; j < renderer.getFieldCount(); j++) { + rendererElement.setAttribute( + "expression_field_" + j, + renderer.getField(j)); + } + rendererElement.setAttribute("expression_operator", "="); - ISymbol sym = renderer.getSymbol(value); - MarkerSymbolReader markerReader = new MarkerSymbolReader(); - LineSymbolReader lineReader = new LineSymbolReader(); - FillSymbolReader fillReader = new FillSymbolReader(); - if(markerReader.canRead(sym)) { - markerReader.setSymbol(sym); - markerReader.setUtil(util); - markerReader.setParent(rendererElement); - markerReader.read(); + ISymbol sym = renderer.getSymbol(value); + MarkerSymbolReader markerReader = new MarkerSymbolReader(); + LineSymbolReader lineReader = new LineSymbolReader(); + FillSymbolReader fillReader = new FillSymbolReader(); + if(markerReader.canRead(sym)) { + markerReader.setSymbol(sym); + markerReader.setUtil(util); + markerReader.setParent(rendererElement); + markerReader.read(); + } + else if(lineReader.canRead(sym)) { + lineReader.setSymbol(sym); + lineReader.setUtil(util); + lineReader.setParent(rendererElement); + lineReader.read(); + } + else if(fillReader.canRead(sym)) { + fillReader.setSymbol(sym); + fillReader.setUtil(util); + fillReader.setParent(rendererElement); + fillReader.read(); + } + else { + logger.debug("Not a known symbol type: " + + sym.getClass().toString()); + } } - else if(lineReader.canRead(sym)) { - lineReader.setSymbol(sym); - lineReader.setUtil(util); - lineReader.setParent(rendererElement); - lineReader.read(); - } - else if(fillReader.canRead(sym)) { - fillReader.setSymbol(sym); - fillReader.setUtil(util); - fillReader.setParent(rendererElement); - fillReader.read(); - } - else { - logger.debug("Not a known symbol type: " + - sym.getClass().toString()); + catch(Exception e) { + logger.error( + "Could not read unique value data." + + e.toString()); + return layer; } } return layer;