Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libGPE / src-test / org / gvsig / gpe / GPEContentHandlerTest.java @ 11602

History | View | Annotate | Download (13.1 KB)

1
package org.gvsig.gpe;
2

    
3
import java.util.ArrayList;
4

    
5
import org.gvsig.gpe.containers.Feature;
6
import org.gvsig.gpe.containers.Bbox;
7
import org.gvsig.gpe.containers.Element;
8
import org.gvsig.gpe.containers.Geometry;
9
import org.gvsig.gpe.containers.Layer;
10
import org.gvsig.gpe.containers.LineString;
11
import org.gvsig.gpe.containers.LinearRing;
12
import org.gvsig.gpe.containers.MultiGeometry;
13
import org.gvsig.gpe.containers.MultiLineString;
14
import org.gvsig.gpe.containers.MultiPoint;
15
import org.gvsig.gpe.containers.MultiPolygon;
16
import org.gvsig.gpe.containers.Point;
17
import org.gvsig.gpe.containers.Polygon;
18

    
19
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
20
 *
21
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
22
 *
23
 * This program is free software; you can redistribute it and/or
24
 * modify it under the terms of the GNU General Public License
25
 * as published by the Free Software Foundation; either version 2
26
 * of the License, or (at your option) any later version.
27
 *
28
 * This program is distributed in the hope that it will be useful,
29
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31
 * GNU General Public License for more details.
32
 *
33
 * You should have received a copy of the GNU General Public License
34
 * along with this program; if not, write to the Free Software
35
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
36
 *
37
 * For more information, contact:
38
 *
39
 *  Generalitat Valenciana
40
 *   Conselleria d'Infraestructures i Transport
41
 *   Av. Blasco Ib??ez, 50
42
 *   46010 VALENCIA
43
 *   SPAIN
44
 *
45
 *      +34 963862235
46
 *   gvsig@gva.es
47
 *      www.gvsig.gva.es
48
 *
49
 *    or
50
 *
51
 *   IVER T.I. S.A
52
 *   Salamanca 50
53
 *   46005 Valencia
54
 *   Spain
55
 *
56
 *   +34 963163400
57
 *   dac@iver.es
58
 */
59
/* CVS MESSAGES:
60
 *
61
 * $Id: GPEContentHandlerTest.java 11602 2007-05-14 09:29:34Z jorpiell $
62
 * $Log$
63
 * Revision 1.10  2007-05-14 09:29:34  jorpiell
64
 * Add some comments when an element is added
65
 *
66
 * Revision 1.9  2007/05/09 10:25:45  jorpiell
67
 * Add the multiGeometries
68
 *
69
 * Revision 1.8  2007/05/09 08:35:58  jorpiell
70
 * fixed an exception
71
 *
72
 * Revision 1.7  2007/05/02 11:46:07  jorpiell
73
 * Writing tests updated
74
 *
75
 * Revision 1.6  2007/04/26 14:39:12  jorpiell
76
 * Add some tests
77
 *
78
 * Revision 1.5  2007/04/19 07:23:20  jorpiell
79
 * Add the add methods to teh contenhandler and change the register mode
80
 *
81
 * Revision 1.4  2007/04/17 07:53:55  jorpiell
82
 * Before to start a new parsing process, the initialize method of the content handlers is throwed
83
 *
84
 * Revision 1.3  2007/04/14 16:06:35  jorpiell
85
 * Add the container classes
86
 *
87
 * Revision 1.2  2007/04/13 13:14:55  jorpiell
88
 * Created the base tests and add some methods to the content handler
89
 *
90
 * Revision 1.1  2007/04/12 17:06:42  jorpiell
91
 * First GML writing tests
92
 *
93
 *
94
 */
95
/**
96
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
97
 */
98
public class GPEContentHandlerTest extends GPEContentHandler{
99
        private String tab = "";
100
        private ArrayList layers = new ArrayList();
101

    
102
        /**
103
         * @return the layers without parent layer
104
         */
105
        public ArrayList getLayers() {
106
                ArrayList newLayers = new ArrayList();
107
                for (int i=0 ; i<layers.size() ; i++){
108
                        if (((Layer)layers.get(i)).getParentLayer() == null){
109
                                newLayers.add(layers.get(i));
110
                        }
111
                }
112
                return newLayers;
113
        }
114

    
115
        public void addNameToFeature(Object feature, String name){
116
                System.out.print(tab + "Feature name changed: " + name + "\n");
117
                ((Feature)feature).setName(name);
118
        }
119

    
120
        public void endFeature(Object feature) {
121
                System.out.print(tab + "End Feature\n");                
122
        }        
123

    
124
        public void initialize(){
125
                layers = new ArrayList();
126
        }
127

    
128
        public void addBboxToGeometry(Object bbox, Object geometry) {
129
                ((Geometry)geometry).setBbox(bbox);
130

    
131
        }
132

    
133
        public void addBboxToLayer(Object bbox, Object layer) {
134
                Bbox box = (Bbox)bbox;
135
                System.out.print(tab + "Layer bbox Added:\n");
136
                tab = tab + "\t";
137
                System.out.print(tab + "MINX: " + box.getX()[0] + "\n");
138
                System.out.print(tab + "MINY: " + box.getY()[0] + "\n");
139
                System.out.print(tab + "MINZ: " + box.getZ()[0] + "\n");
140
                System.out.print(tab + "MAXX: " + box.getX()[1] + "\n");
141
                System.out.print(tab + "MAXY: " + box.getY()[1] + "\n");
142
                System.out.print(tab + "MAXZ: " + box.getZ()[1] + "\n");
143
                System.out.print(tab + "SRS: " + box.getSrs() + "\n");
144
                tab = tab.substring(0, tab.length()-1);
145
                ((Layer)layer).setBbox(bbox);
146
        }
147

    
148
        public void addDescriptionToLayer(String description, Object layer) {
149
                System.out.print(tab + "Layer description changed: " + description + "\n");
150
                ((Layer)layer).setDescription(description);
151
        }
152

    
153
        public void addElementToFeature(Object element, Object feature) {
154
                Element elem = (Element)element;
155
                tab = tab + "\t";
156
                System.out.print(tab + "Add Element " + elem.getName() + "=" +
157
                                elem.getValue() + " to Feature\n");
158
                tab = tab.substring(0, tab.length()-1);
159
                ((Feature)feature).addElement(element);                
160
        }
161

    
162
        public void addFeatureToLayer(Object feature, Object layer) {
163
                ((Layer)layer).addFeature(feature);
164

    
165
        }
166

    
167
        public void addGeometryToFeature(Object geometry, Object feature) {
168
                ((Feature)feature).setGeometry(geometry);
169

    
170
        }
171

    
172
        public void addInnerPolygonToPolygon(Object innerPolygon, Object polygon) {
173
                ((Polygon)polygon).addInnerBoundary(innerPolygon);
174

    
175
        }
176

    
177
        public void addNameToFeature(String name, Object feature) {
178
                ((Feature)feature).setName(name);
179

    
180
        }
181

    
182
        public void addNameToLayer(String name, Object layer) {
183
                System.out.print(tab + "Layer name changed: " + name + "\n");
184
                ((Layer)layer).setName(name);                
185
        }
186

    
187
        public void addParentElementToElement(Object parent, Object element) {
188
                ((Element)element).setParentElement(parent);
189

    
190
        }
191

    
192
        public void addParentLayerToLayer(Object parent, Object layer) {
193
                ((Layer)layer).setParentLayer(parent);
194

    
195
        }
196

    
197
        public void addSrsToLayer(String srs, Object layer) {
198
                ((Layer)layer).setSrs(srs);
199

    
200
        }
201

    
202

    
203
        public Object startBbox(String id, double[] x, double[] y, double[] z, String srs) {
204
                Bbox bbox = new Bbox();
205
                bbox.setX(x);
206
                bbox.setY(y);
207
                bbox.setZ(z);
208
                bbox.setId(id);
209
                bbox.setSrs(srs);
210
                return bbox;
211
        }
212

    
213
        public void endBbox(Object bbox) {
214
                // TODO Ap?ndice de m?todo generado autom?ticamente
215
        }
216

    
217
        public Object startElement(String name, Object value, Object type, Object parentElement) {
218
                Element element = new Element();
219
                element.setParentElement(parentElement);
220
                element.setName(name);
221
                element.setValue(value);
222
                element.setType(type);
223
                return element;
224
        }
225

    
226
        public void endElement(Object element) {
227
                // TODO Ap?ndice de m?todo generado autom?ticamente
228

    
229
        }
230

    
231
        public Object startFeature(String id, String name, Object layer) {
232
                System.out.print(tab + "Start Feature, ID: " +  id + " NAME: " + name + "\n");
233
                Feature feature = new Feature();
234
                feature.setName(name);
235
                feature.setId(id);
236
                if (layer != null){
237
                        addFeatureToLayer(feature, layer);
238
                }
239
                return feature;
240
        }
241

    
242
        public Object startInnerPolygon(String id, double[] x, double[] y, double[] z, String srs) {
243
                tab = tab + "\t";
244
                System.out.print(tab + "Start InnerPolygon, SRS:" + srs + "\n");
245
                tab = tab + "\t";
246
                for (int i=0 ; i<x.length ; i++){
247
                        System.out.print(tab + x[i] + "," + y[i] + "," + z[i] + "\n");
248
                }
249
                tab = tab.substring(0, tab.length()-2);
250
                Polygon inner = new Polygon();
251
                inner.setX(x);
252
                inner.setY(y);
253
                inner.setZ(z);
254
                inner.setId(id);
255
                inner.setSrs(srs);
256
                return inner;
257
        }
258

    
259
        /*
260
         * (non-Javadoc)
261
         * @see org.gvsig.gpe.IGPEContentHandler#endInnerPolygon(java.lang.Object)
262
         */
263
        public void endInnerPolygon(Object polygon){
264
                tab = tab + "\t";
265
                System.out.print(tab + "End InnerPolygon\n");
266
                tab = tab.substring(0, tab.length()-1);
267
        }
268

    
269

    
270
        public Object startLayer(String id, String name, String description, String srs, Object parentLayer, Object bBox) {
271
                System.out.print(tab + "Start Layer, ID: " +  id + " NAME: " + name + "\n");
272
                tab = tab + "\t";
273
                Layer layer = new Layer();
274
                layer.setId(id);
275
                layer.setName(name);
276
                layer.setDescription(description);
277
                layer.setSrs(srs);
278
                layer.setBbox(bBox);
279
                layer.setParentLayer(parentLayer);
280
                if (parentLayer != null){
281
                        ((Layer)parentLayer).addLayer(layer);
282
                }
283
                layers.add(layer);
284
                return layer;
285
        }        
286

    
287
        public void endLayer(Object layer) {
288
                tab = tab.substring(0, tab.length()-1);
289
                System.out.print(tab + "End Layer\n");                
290
        }
291

    
292
        public Object startLineString(String id, double[] x, double[] y, double[] z, String srs) {
293
                System.out.print(tab + "Start LineString, SRS:" + srs + "\n");
294
                tab = tab + "\t";
295
                for (int i=0 ; i<x.length ; i++){
296
                        System.out.print(tab + x[i] + "," + y[i] + "," + z[i] + "\n");
297
                }
298
                tab = tab.substring(0, tab.length()-1);
299
                LineString lineString = new LineString();
300
                lineString.setX(x);
301
                lineString.setY(y);
302
                lineString.setZ(z);
303
                lineString.setId(id);
304
                lineString.setSrs(srs);
305
                return lineString;
306
        }
307

    
308
        public void endLineString(Object line) {
309
                System.out.print(tab + "End LineString:\n");
310
        }        
311

    
312
        public Object startPoint(String id, double x, double y, double z, String srs) {
313
                System.out.print(tab + "Start Point, SRS:" + srs + "\n");
314
                tab = tab + "\t";
315
                System.out.print(tab + x + "," + y + "," + z + "\n");
316
                tab = tab.substring(0, tab.length()-1);
317
                Point point = new Point();
318
                point.setX(x);
319
                point.setY(y);
320
                point.setZ(z);
321
                point.setId(id);
322
                point.setSrs(srs);
323
                return point;
324
        }        
325

    
326
        public void endPoint(Object point) {
327
                System.out.print(tab + "End Point\n");
328
        }
329

    
330
        public Object startPolygon(String id, double[] x, double[] y, double[] z, String srs) {
331
                System.out.print(tab + "Start Polygon, SRS:" + srs + "\n");
332
                tab = tab + "\t";
333
                for (int i=0 ; i<x.length ; i++){
334
                        System.out.print(tab + x[i] + "," + y[i] + "," + z[i] + "\n");
335
                }
336
                tab = tab.substring(0, tab.length()-1);
337
                Polygon polygon = new Polygon();
338
                polygon.setX(x);
339
                polygon.setY(y);
340
                polygon.setZ(z);
341
                polygon.setId(id);
342
                polygon.setSrs(srs);
343
                return polygon;
344
        }
345

    
346

    
347
        public void endPolygon(Object polygon) {
348
                System.out.print(tab + "End Polygon\n");
349
        }
350

    
351

    
352
        public Object startLinearRing(String id, double[] x, double[] y, double[] z, String srs) {
353
                System.out.print(tab + "Start LinearRing, SRS:" + srs + "\n");
354
                tab = tab + "\t";
355
                for (int i=0 ; i<x.length ; i++){
356
                        System.out.print(tab + x[i] + "," + y[i] + "," + z[i] + "\n");
357
                }
358
                tab = tab.substring(0, tab.length()-1);
359
                LinearRing linearRing = new LinearRing();
360
                linearRing.setX(x);
361
                linearRing.setY(y);
362
                linearRing.setZ(z);
363
                linearRing.setId(id);
364
                linearRing.setSrs(srs);
365
                return linearRing;
366
        }
367

    
368

    
369
        public void endLinearRing(Object linearRing) {
370
                System.out.print(tab + "End LinearRing:\n");
371
        }
372
        
373

    
374
        public Object startMultiPoint(String id, String srs) {
375
                System.out.print(tab + "Start MultiPoint, ID: " + id + ", SRS:" + srs + "\n");
376
                tab = tab + "\t";
377
                MultiPoint multiPoint = new MultiPoint();
378
                multiPoint.setId(id);
379
                multiPoint.setSrs(srs);
380
                return multiPoint;
381
        }        
382

    
383
        public void endMultiPoint(Object multiPoint) {
384
                tab = tab.substring(0, tab.length()-1);                
385
                System.out.print(tab + "End MultiPoint\n");                
386
        }
387

    
388
        public void addPointToMultiPoint(Object point, Object multiPoint) {
389
                System.out.print(tab + "Add Point to MultiPoint");        
390
                ((MultiPoint)multiPoint).addPoint((Point)point);
391
        }
392

    
393
        public Object startMultiLineString(String id, String srs) {
394
                System.out.print(tab + "Start MultiLineString, ID: " + id + ", SRS:" + srs + "\n");
395
                tab = tab + "\t";
396
                MultiLineString multiLineString = new MultiLineString();
397
                multiLineString.setId(id);
398
                multiLineString.setSrs(srs);
399
                return multiLineString;                
400
        }
401
        
402
        public void endMultiLineString(Object multiLineString) {
403
                tab = tab.substring(0, tab.length()-1);                
404
                System.out.print(tab + "End MultiLineString\n");                
405
        }        
406
        
407
        public void addLineStringToMultiLineString(Object lineString, Object multiLineString) {
408
                System.out.print(tab + "Add LineString to MultiLineString");        
409
                ((MultiLineString)multiLineString).addLineString((LineString)lineString);
410
        }
411

    
412
        public Object startMultiPolygon(String id, String srs) {
413
                System.out.print(tab + "Start MultiPolygon, ID: " + id + ", SRS:" + srs + "\n");
414
                tab = tab + "\t";
415
                MultiPolygon multiPolygon = new MultiPolygon();
416
                multiPolygon.setId(id);
417
                multiPolygon.setSrs(srs);
418
                return multiPolygon;        
419
        }
420
        
421
        public void endMultiPolygon(Object multiPolygon) {
422
                tab = tab.substring(0, tab.length()-1);                
423
                System.out.print(tab + "End MultiPolygon\n");                
424
        }
425

    
426
        public void addPolygonToMultiPolygon(Object polygon, Object multiPolygon) {
427
                System.out.print(tab + "Add Polygon to MultiPolygon");        
428
                ((MultiPolygon)multiPolygon).addPolygon((Polygon)polygon);
429
        }
430

    
431
        public Object startMultiGeometry(String id, String srs) {
432
                System.out.print(tab + "Start MultiGeometry, ID: " + id + ", SRS:" + srs + "\n");
433
                tab = tab + "\t";
434
                MultiGeometry multiGeometry = new MultiGeometry();
435
                multiGeometry.setId(id);
436
                multiGeometry.setSrs(srs);
437
                return multiGeometry;        
438
        }
439
        
440
        public void endMultiGeometry(Object multiGeometry) {
441
                tab = tab.substring(0, tab.length()-1);                
442
                System.out.print(tab + "End MultiGeometry\n");                
443
        }
444
        
445
        public void addGeometryToMultiGeometry(Object geometry, Object multiGeometry) {
446
                if (geometry instanceof Point){
447
                        System.out.print(tab + "Add Point to MultiGeometry");
448
                }else if (geometry instanceof LineString){
449
                        System.out.print(tab + "Add LineString to MultiGeometry");
450
                }else if (geometry instanceof Polygon){
451
                        System.out.print(tab + "Add Polygon to MultiGeometry");
452
                }else {
453
                        System.out.print(tab + "Add Geometry to MultiGeometry");
454
                }                
455
                ((MultiGeometry)multiGeometry).addGeometry((Geometry)geometry);
456
        }
457

    
458
}
459