Statistics
| Revision:

root / trunk / libraries / libGPE / src-test / org / gvsig / gpe / GPEContentHandlerTest.java @ 11379

History | View | Annotate | Download (8.34 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.Point;
12
import org.gvsig.gpe.containers.Polygon;
13

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

    
85
        /**
86
         * @return the layers
87
         */
88
        public ArrayList getLayers() {
89
                return layers;
90
        }
91

    
92
        public void addNameToFeature(Object feature, String name){
93
                System.out.print(tab + "Feature name changed: " + name + "\n");
94
                ((Feature)feature).setName(name);
95
        }
96

    
97
        public void endFeature(Object feature) {
98
                System.out.print(tab + "End Feature\n");                
99
        }        
100

    
101
        public void initialize(){
102
                layers = new ArrayList();
103
        }
104

    
105
        public void addBboxToGeometry(Object bbox, Object geometry) {
106
                ((Geometry)geometry).setBbox(bbox);
107

    
108
        }
109

    
110
        public void addBboxToLayer(Object bbox, Object layer) {
111
                ((Layer)layer).setBbox(bbox);
112

    
113
        }
114

    
115
        public void addDescriptionToLayer(String description, Object layer) {
116
                System.out.print(tab + "Layer description changed: " + description + "\n");
117
                ((Layer)layer).setDescription(description);
118
        }
119

    
120
        public void addElementToFeature(Object element, Object feature) {
121
                ((Feature)feature).addElement(element);                
122
        }
123

    
124
        public void addFeatureToLayer(Object feature, Object layer) {
125
                ((Layer)layer).addFeature(feature);
126

    
127
        }
128

    
129
        public void addGeometryToFeature(Object geometry, Object feature) {
130
                ((Feature)feature).setGeometry(geometry);
131

    
132
        }
133

    
134
        public void addInnerPolygonToPolygon(Object innerPolygon, Object polygon) {
135
                ((Polygon)polygon).addInnerBoundary(innerPolygon);
136

    
137
        }
138

    
139
        public void addNameToFeature(String name, Object feature) {
140
                ((Feature)feature).setName(name);
141

    
142
        }
143

    
144
        public void addNameToLayer(String name, Object layer) {
145
                System.out.print(tab + "Layer name changed: " + name + "\n");
146
                ((Layer)layer).setName(name);                
147
        }
148

    
149
        public void addParentElementToElement(Object parent, Object element) {
150
                ((Element)element).setParentElement(parent);
151

    
152
        }
153

    
154
        public void addParentLayerToLayer(Object parent, Object layer) {
155
                ((Layer)layer).setParentLayer(parent);
156

    
157
        }
158

    
159
        public void addSrsToLayer(String srs, Object layer) {
160
                ((Layer)layer).setSrs(srs);
161

    
162
        }
163

    
164

    
165
        public Object startBbox(String id, double[] x, double[] y, double[] z, String srs) {
166
                Bbox bbox = new Bbox();
167
                bbox.setX(x);
168
                bbox.setY(y);
169
                bbox.setZ(z);
170
                bbox.setId(id);
171
                bbox.setSrs(srs);
172
                return bbox;
173
        }
174

    
175
        public void endBbox(Object bbox) {
176
                // TODO Ap?ndice de m?todo generado autom?ticamente
177
        }
178

    
179
        public Object startElement(String name, Object value, Object type, Object parentElement) {
180
                Element element = new Element();
181
                element.setParentElement(parentElement);
182
                element.setName(name);
183
                element.setValue(value);
184
                element.setType(type);
185
                return element;
186
        }
187

    
188
        public void endElement(Object element) {
189
                // TODO Ap?ndice de m?todo generado autom?ticamente
190

    
191
        }
192

    
193
        public Object startFeature(String id, String name, Object layer) {
194
                System.out.print(tab + "Start Feature, ID: " +  id + " NAME: " + name + "\n");
195
                Feature feature = new Feature();
196
                feature.setName(name);
197
                feature.setId(id);
198
                if (layer != null){
199
                        addFeatureToLayer(feature, layer);
200
                }
201
                return feature;
202
        }
203

    
204
        public Object startInnerPolygon(String id, double[] x, double[] y, double[] z, String srs) {
205
                tab = tab + "\t";
206
                System.out.print(tab + "Start InnerPolygon, SRS:" + srs + "\n");
207
                tab = tab + "\t";
208
                for (int i=0 ; i<x.length ; i++){
209
                        System.out.print(tab + x[i] + "," + y[i] + "," + z[i] + "\n");
210
                }
211
                tab = tab.substring(0, tab.length()-2);
212
                Polygon inner = new Polygon();
213
                inner.setX(x);
214
                inner.setY(y);
215
                inner.setZ(z);
216
                inner.setId(id);
217
                inner.setSrs(srs);
218
                return inner;
219
        }
220

    
221
        /*
222
         * (non-Javadoc)
223
         * @see org.gvsig.gpe.IGPEContentHandler#endInnerPolygon(java.lang.Object)
224
         */
225
        public void endInnerPolygon(Object polygon){
226
                tab = tab + "\t";
227
                System.out.print(tab + "End InnerPolygon\n");
228
                tab = tab.substring(0, tab.length()-1);
229
        }
230

    
231

    
232
        public Object startLayer(String id, String name, String description, String srs, Object parentLayer, Object bBox) {
233
                System.out.print(tab + "Start Layer, ID: " +  id + " NAME: " + name + "\n");
234
                tab = tab + "\t";
235
                Layer layer = new Layer();
236
                layer.setId(id);
237
                layer.setName(name);
238
                layer.setDescription(description);
239
                layer.setSrs(srs);
240
                layer.setParentLayer(parentLayer);
241
                layer.setBbox(bBox);
242
                layers.add(layer);
243
                return layer;
244
        }        
245

    
246
        public void endLayer(Object layer) {
247
                tab = tab.substring(0, tab.length()-1);
248
                System.out.print(tab + "End Layer\n");                
249
        }
250

    
251
        public Object startLineString(String id, double[] x, double[] y, double[] z, String srs) {
252
                System.out.print(tab + "Start LineString, SRS:" + srs + "\n");
253
                tab = tab + "\t";
254
                for (int i=0 ; i<x.length ; i++){
255
                        System.out.print(tab + x[i] + "," + y[i] + "," + z[i] + "\n");
256
                }
257
                tab = tab.substring(0, tab.length()-1);
258
                LineString lineString = new LineString();
259
                lineString.setX(x);
260
                lineString.setY(y);
261
                lineString.setZ(z);
262
                lineString.setId(id);
263
                lineString.setSrs(srs);
264
                return lineString;
265
        }
266

    
267
        public void endLineString(Object line) {
268
                System.out.print(tab + "End LineString:\n");
269
        }        
270

    
271
        public Object startPoint(String id, double x, double y, double z, String srs) {
272
                System.out.print(tab + "Start Point, SRS:" + srs + "\n");
273
                tab = tab + "\t";
274
                System.out.print(tab + x + "," + y + "," + z + "\n");
275
                tab = tab.substring(0, tab.length()-1);
276
                Point point = new Point();
277
                point.setX(x);
278
                point.setY(y);
279
                point.setZ(z);
280
                point.setId(id);
281
                point.setSrs(srs);
282
                return point;
283
        }        
284

    
285
        public void endPoint(Object point) {
286
                System.out.print(tab + "End Point\n");
287
        }
288

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

    
305

    
306
        public void endPolygon(Object polygon) {
307
                System.out.print(tab + "End Polygon\n");
308
        }
309

    
310

    
311
        public Object startLinearRing(String id, double[] x, double[] y, double[] z, String srs) {
312
                // TODO Auto-generated method stub
313
                return null;
314
        }
315

    
316

    
317
        public void endLinearRing(Object linearRing) {
318
                // TODO Auto-generated method stub
319

    
320
        }
321

    
322

    
323
}
324