comparison src/java/de/intevation/mxd/reader/MXDReader.java @ 43:ef7ca23c4233

Added comments, done some code styling and removed typos.
author Raimund Renkert <rrenkert@intevation.de>
date Fri, 15 Apr 2011 15:44:54 +0200
parents a1bc7220efe7
children b41fcf268827
comparison
equal deleted inserted replaced
42:395307e8b7ee 43:ef7ca23c4233
23 /** 23 /**
24 * The MXD file reader. 24 * The MXD file reader.
25 * 25 *
26 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> 26 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
27 */ 27 */
28 public class MXDReader implements IReader { 28 public class MXDReader
29 29 implements IReader {
30 //Member 30 /**
31 * The Logger.
32 */
33 private static final Logger logger = Logger.getLogger(MXDReader.class);
34
35 /**
36 * Private member.
37 */
31 private String filename = ""; 38 private String filename = "";
32 private ArcGISInitializer initializer = null; 39 private ArcGISInitializer initializer = null;
33 private MapToXMLUtils util; 40 private MapToXMLUtils util;
34 private IMap map; 41 private IMap map;
35 42
36 private static final Logger logger = Logger.getLogger(MXDReader.class); 43
37 44 public MXDReader()
38 //Constructor 45 throws IOException {
39 public MXDReader() throws IOException{
40 logger.debug("constructor()"); 46 logger.debug("constructor()");
41 initializer = new ArcGISInitializer(); 47 initializer = new ArcGISInitializer();
42 util = new MapToXMLUtils(); 48 util = new MapToXMLUtils();
43 } 49 }
44 50
45 51
46 //Methods
47
48 /** 52 /**
49 * Initialize the ArcGIS Objects. 53 * Initialize the ArcGIS Objects.
50 */ 54 */
51 public boolean init() throws IOException{ 55 public boolean init()
56 throws IOException {
52 logger.debug("init()"); 57 logger.debug("init()");
53 initializer.initArcGIS(); 58 initializer.initArcGIS();
54 initializer.initArcGISLicenses(); 59 initializer.initArcGISLicenses();
55 return true; 60 return true;
56 } 61 }
57 62
58 /** 63 /**
59 * Shutdown the ArcGIS Objects. 64 * Shutdown the ArcGIS Objects.
60 */ 65 */
61 public boolean shutdown() throws IOException{ 66 public boolean shutdown()
67 throws IOException {
62 logger.debug("shutdown()"); 68 logger.debug("shutdown()");
63 if(initializer == null){ 69 if(initializer == null) {
64 throw new IOException("Faild to shutdown!"); 70 throw new IOException("Faild to shutdown!");
65 } 71 }
66 else{ 72 else {
67 initializer.shutdownArcGIS(); 73 initializer.shutdownArcGIS();
68 return true; 74 return true;
69 } 75 }
70 } 76 }
71 77
72 /** 78 /**
73 * Set the path and filename to the MXD-File. 79 * Set the path and filename to the MXD-File.
74 */ 80 */
75 public void setFilename(String name){ 81 public void setFilename(String name) {
76 logger.debug("setFilename()"); 82 logger.debug("setFilename()");
77 filename = name; 83 filename = name;
78 } 84 }
79 85
80 86
81 private void openMapDocument() throws IOException{ 87 private void openMapDocument()
88 throws IOException {
82 MapDocument m = new MapDocument(); 89 MapDocument m = new MapDocument();
83 if(!m.isMapDocument(filename)){ 90 if(!m.isMapDocument(filename)) {
84 throw new IOException(filename + " is not a map!"); 91 throw new IOException(filename + " is not a map!");
85 } 92 }
86 m.open(filename, null); 93 m.open(filename, null);
87 map = m.getMap(0); 94 map = m.getMap(0);
88 } 95 }
96
89 /** 97 /**
90 * Read the MXD file content. 98 * Read the MXD file content.
91 */ 99 */
92 public boolean read() throws IOException{ 100 public boolean read()
101 throws IOException {
93 logger.debug("read()"); 102 logger.debug("read()");
94 if(filename == ""){ 103 if(filename == "") {
95 throw new IOException("Please set filename!"); 104 throw new IOException("Please set filename!");
96 } 105 }
97 else{ 106 else {
98 util.addFilename(filename); 107 util.addFilename(filename);
99 openMapDocument(); 108 openMapDocument();
100 MapReader mreader; 109 MapReader mreader;
101 try { 110 try {
102 mreader = new MapReader (map); 111 mreader = new MapReader (map);
106 } 115 }
107 catch(Exception e) { 116 catch(Exception e) {
108 e.printStackTrace(); 117 e.printStackTrace();
109 } 118 }
110 119
111 for(int i = 0; i < map.getLayerCount();i++){ 120 for(int i = 0; i < map.getLayerCount();i++) {
112 ILayer layer = map.getLayer(i); 121 ILayer layer = map.getLayer(i);
113 try{ 122 try {
114 if (layer instanceof FeatureLayer){ 123 if (layer instanceof FeatureLayer) {
115 FeatureLayerReader lr = new FeatureLayerReader(layer); 124 FeatureLayerReader lr = new FeatureLayerReader(layer);
116 lr.setUtil(util); 125 lr.setUtil(util);
117 Element layerElement = lr.read(); 126 Element layerElement = lr.read();
118 IFeatureRenderer renderer = ((FeatureLayer)layer).getRenderer(); 127 IFeatureRenderer renderer =
128 ((FeatureLayer)layer).getRenderer();
119 IRendererReader rreader; 129 IRendererReader rreader;
120 if(renderer instanceof SimpleRenderer){ 130 if(renderer instanceof SimpleRenderer) {
121 rreader = new SimpleRendererReader(renderer); 131 rreader = new SimpleRendererReader(renderer);
122 rreader.setParent(layerElement); 132 rreader.setParent(layerElement);
123 rreader.setUtil(util); 133 rreader.setUtil(util);
124 rreader.read(); 134 rreader.read();
125 } 135 }
126 else if(renderer instanceof ClassBreaksRenderer){ 136 else if(renderer instanceof ClassBreaksRenderer) {
127 rreader = new ClassBreakRendererReader(renderer); 137 rreader = new ClassBreakRendererReader(renderer);
128 rreader.setParent(layerElement); 138 rreader.setParent(layerElement);
129 rreader.setUtil(util); 139 rreader.setUtil(util);
130 rreader.read(); 140 rreader.read();
131 } 141 }
132 else if(renderer instanceof UniqueValueRenderer){ 142 else if(renderer instanceof UniqueValueRenderer) {
133 rreader = new UniqueValueRendererReader(renderer); 143 rreader = new UniqueValueRendererReader(renderer);
134 rreader.setParent(layerElement); 144 rreader.setParent(layerElement);
135 rreader.setUtil(util); 145 rreader.setUtil(util);
136 rreader.read(); 146 rreader.read();
137 } 147 }
144 else if(layer instanceof GdbRasterCatalogLayer) { 154 else if(layer instanceof GdbRasterCatalogLayer) {
145 GdbRasterCatalogLayerReader gclr = 155 GdbRasterCatalogLayerReader gclr =
146 new GdbRasterCatalogLayerReader(layer); 156 new GdbRasterCatalogLayerReader(layer);
147 gclr.setUtil(util); 157 gclr.setUtil(util);
148 Element layerElement = gclr.read(); 158 Element layerElement = gclr.read();
149 IFeatureRenderer renderer = ((GdbRasterCatalogLayer)layer).getRenderer(); 159 IFeatureRenderer renderer =
160 ((GdbRasterCatalogLayer)layer).getRenderer();
150 IRendererReader rreader; 161 IRendererReader rreader;
151 if(renderer instanceof SimpleRenderer){ 162 if(renderer instanceof SimpleRenderer) {
152 rreader = new SimpleRendererReader(renderer); 163 rreader = new SimpleRendererReader(renderer);
153 rreader.setParent(layerElement); 164 rreader.setParent(layerElement);
154 rreader.setUtil(util); 165 rreader.setUtil(util);
155 rreader.read(); 166 rreader.read();
156 } 167 }
157 else if(renderer instanceof ClassBreaksRenderer){ 168 else if(renderer instanceof ClassBreaksRenderer) {
158 rreader = new ClassBreakRendererReader(renderer); 169 rreader = new ClassBreakRendererReader(renderer);
159 rreader.setParent(layerElement); 170 rreader.setParent(layerElement);
160 rreader.setUtil(util); 171 rreader.setUtil(util);
161 rreader.read(); 172 rreader.read();
162 } 173 }
163 else if(renderer instanceof UniqueValueRenderer){ 174 else if(renderer instanceof UniqueValueRenderer) {
164 rreader = new UniqueValueRendererReader(renderer); 175 rreader = new UniqueValueRendererReader(renderer);
165 rreader.setParent(layerElement); 176 rreader.setParent(layerElement);
166 rreader.setUtil(util); 177 rreader.setUtil(util);
167 rreader.read(); 178 rreader.read();
168 } 179 }
169 else{ 180 else {
170 System.out.println("No known renderer!"); 181 System.out.println("No known renderer!");
171 System.out.println("Implement new renderer for " + 182 System.out.println("Implement new renderer for " +
172 renderer.getClass().toString()); 183 renderer.getClass().toString());
173 } 184 }
174 } 185 }
175 } 186 }
176 catch(Exception e){ 187 catch(Exception e) {
177 e.printStackTrace(); 188 e.printStackTrace();
178 } 189 }
179 } 190 }
180 util.print(); 191 util.print();
181 } 192 }
182 return true; 193 return true;
183 } 194 }
184 195
185 196 /**
186 public Document getMapDocument(){ 197 * Get the root DOM document.
198 */
199 public Document getMapDocument() {
187 logger.debug("getMapDocument()"); 200 logger.debug("getMapDocument()");
188 return util.getDocument(); 201 return util.getDocument();
189 } 202 }
190 } 203 }
191 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 204 // 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)