comparison src/java/de/intevation/mxd/reader/GroupLayerReader.java @ 165:87afe66f7d88

Merged with raimunds changes
author Stephan Holl <stephan.holl@intevation.de>
date Thu, 30 Jun 2011 14:59:44 +0200
parents 2bf35f0babd0
children f4eb506499f5
comparison
equal deleted inserted replaced
164:ba2252ceb6f9 165:87afe66f7d88
1 package de.intevation.mxd.reader;
2
3 import java.io.IOException;
4
5 import org.apache.log4j.Logger;
6
7 import com.esri.arcgis.carto.ILayer;
8 import com.esri.arcgis.carto.FeatureLayer;
9 import com.esri.arcgis.carto.GdbRasterCatalogLayer;
10 import com.esri.arcgis.carto.IFeatureRenderer;
11 import com.esri.arcgis.carto.SimpleRenderer;
12 import com.esri.arcgis.carto.ClassBreaksRenderer;
13 import com.esri.arcgis.carto.UniqueValueRenderer;
14 import com.esri.arcgis.carto.GroupLayer;
15
16 import org.w3c.dom.Document;
17 import org.w3c.dom.Element;
18
19 import de.intevation.mxd.ArcGISInitializer;
20 import de.intevation.mxd.utils.MapToXMLUtils;
21
22
23 /**
24 * Reads Layer information.
25 *
26 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
27 */
28 public class GroupLayerReader
29 implements ILayerReader {
30
31 /**
32 * The logger.
33 */
34 private static final Logger logger =
35 Logger.getLogger(FeatureLayerReader.class);
36
37 /**
38 * Privte member.
39 */
40 private GroupLayer layer;
41 private MapToXMLUtils util;
42 private int invalidLayerCount;
43
44 public GroupLayerReader(ILayer layer)
45 throws Exception {
46 if(layer instanceof GroupLayer) {
47 this.layer = (GroupLayer)layer;
48 invalidLayerCount = 0;
49 }
50 else {
51 throw new Exception("Not an instance of GroupLayer: " +
52 layer.getClass().toString());
53 }
54 }
55
56 /**
57 * Setter for XML document helper.
58 *
59 * @param util The helper for storing map information.
60 */
61 public void setUtil(MapToXMLUtils util) {
62 this.util = util;
63 }
64
65 /**
66 * Reads the Layer content.
67 *
68 * @return The layer XML element.
69 */
70 public Element read()
71 throws IOException{
72 logger.debug("read()");
73 Element layerElement = null;
74 for(int i = 0; i < layer.getCount();i++) {
75 ILayer lay = layer.getLayer(i);
76 try {
77 if (lay instanceof FeatureLayer) {
78 FeatureLayerReader lr = new FeatureLayerReader(lay);
79 lr.setUtil(util);
80 layerElement = lr.read();
81 if (layerElement == null) {
82 continue;
83 }
84 layerElement.setAttribute("group", layer.getName());
85 IFeatureRenderer renderer =
86 ((FeatureLayer)lay).getRenderer();
87 IRendererReader rreader;
88 if(renderer instanceof SimpleRenderer) {
89 rreader = new SimpleRendererReader(renderer);
90 rreader.setParent(layerElement);
91 rreader.setUtil(util);
92 rreader.read();
93 }
94 else if(renderer instanceof ClassBreaksRenderer) {
95 rreader = new ClassBreakRendererReader(renderer);
96 rreader.setParent(layerElement);
97 rreader.setUtil(util);
98 rreader.read();
99 }
100 else if(renderer instanceof UniqueValueRenderer) {
101 rreader = new UniqueValueRendererReader(renderer);
102 rreader.setParent(layerElement);
103 rreader.setUtil(util);
104 rreader.read();
105 }
106 else{
107 logger.debug("Not a known renderer type " +
108 renderer.getClass().toString());
109 }
110 }
111 else if(lay instanceof GdbRasterCatalogLayer) {
112 GdbRasterCatalogLayerReader gclr =
113 new GdbRasterCatalogLayerReader(lay);
114 gclr.setUtil(util);
115 layerElement = gclr.read();
116 layerElement.setAttribute("group", layer.getName());
117 IFeatureRenderer renderer =
118 ((GdbRasterCatalogLayer)lay).getRenderer();
119 IRendererReader rreader;
120 if(renderer instanceof SimpleRenderer) {
121 rreader = new SimpleRendererReader(renderer);
122 rreader.setParent(layerElement);
123 rreader.setUtil(util);
124 rreader.read();
125 }
126 else if(renderer instanceof ClassBreaksRenderer) {
127 rreader = new ClassBreakRendererReader(renderer);
128 rreader.setParent(layerElement);
129 rreader.setUtil(util);
130 rreader.read();
131 }
132 else if(renderer instanceof UniqueValueRenderer) {
133 rreader = new UniqueValueRendererReader(renderer);
134 rreader.setParent(layerElement);
135 rreader.setUtil(util);
136 rreader.read();
137 }
138 else {
139 logger.debug("Not a known renderer type " +
140 renderer.getClass().toString());
141 }
142 }
143 }
144 catch(Exception e) {
145 invalidLayerCount++;
146 if(i == 0 && (i + 1) == layer.getCount() ||
147 invalidLayerCount == layer.getCount()) {
148 throw new IOException(
149 "No valid layer in MXD file." +
150 " Aborting.");
151 }
152 }
153 }
154 return layerElement;
155 }
156 }
157 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)