Statistics
| Revision:

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

History | View | Annotate | Download (8.28 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 11247 2007-04-19 07:30:40Z jorpiell $
57
 * $Log$
58
 * Revision 1.5  2007-04-19 07:23:20  jorpiell
59
 * Add the add methods to teh contenhandler and change the register mode
60
 *
61
 * Revision 1.4  2007/04/17 07:53:55  jorpiell
62
 * Before to start a new parsing process, the initialize method of the content handlers is throwed
63
 *
64
 * Revision 1.3  2007/04/14 16:06:35  jorpiell
65
 * Add the container classes
66
 *
67
 * Revision 1.2  2007/04/13 13:14:55  jorpiell
68
 * Created the base tests and add some methods to the content handler
69
 *
70
 * Revision 1.1  2007/04/12 17:06:42  jorpiell
71
 * First GML writing tests
72
 *
73
 *
74
 */
75
/**
76
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
77
 */
78
public class GPEContentHandlerTest extends GPEContentHandler{
79
        private String tab = "";
80
        private ArrayList layers = new ArrayList();
81

    
82
        /**
83
         * @return the layers
84
         */
85
        public ArrayList getLayers() {
86
                return layers;
87
        }
88

    
89
        public Object startFeature(String name, String id) {
90
                System.out.print(tab + "Start Feature: " + name + "\n");
91
                Feature feature = new Feature();
92
                feature.setName(name);
93
                feature.setId(id);
94
                return feature;
95
        }
96

    
97
        public void addNameToFeature(Object feature, String name){
98
                System.out.print(tab + "Feature name changed: " + name + "\n");
99
                ((Feature)feature).setName(name);
100
        }
101

    
102
        public void endFeature(Object feature) {
103
                System.out.print(tab + "End Feature\n");                
104
        }        
105

    
106
        public void initialize(){
107
                layers = new ArrayList();
108
        }
109

    
110
        public void addBboxToGeometry(Object bbox, Object geometry) {
111
                ((Geometry)geometry).setBbox(bbox);
112

    
113
        }
114

    
115
        public void addBboxToLayer(Object bbox, Object layer) {
116
                ((Layer)layer).setBbox(bbox);
117

    
118
        }
119

    
120
        public void addDescriptionToLayer(String description, Object layer) {
121
                System.out.print(tab + "Layer description changed: " + description + "\n");
122
                ((Layer)layer).setDescription(description);
123
        }
124

    
125
        public void addElementToFeature(Object element, Object feature) {
126
                ((Feature)feature).addElement(element);                
127
        }
128

    
129
        public void addFeatureToLayer(Object feature, Object layer) {
130
                ((Layer)layer).addFeature(feature);
131

    
132
        }
133

    
134
        public void addGeometryToFeature(Object geometry, Object feature) {
135
                ((Feature)feature).setGeometry(geometry);
136

    
137
        }
138

    
139
        public void addInnerPolygonToPolygon(Object innerPolygon, Object polygon) {
140
                ((Polygon)polygon).addInnerBoundary(innerPolygon);
141

    
142
        }
143

    
144
        public void addNameToFeature(String name, Object feature) {
145
                ((Feature)feature).setName(name);
146

    
147
        }
148

    
149
        public void addNameToLayer(String name, Object layer) {
150
                System.out.print(tab + "Layer name changed: " + name + "\n");
151
                ((Layer)layer).setName(name);                
152
        }
153

    
154
        public void addParentElementToElement(Object parent, Object element) {
155
                ((Element)element).setParentElement(parent);
156

    
157
        }
158

    
159
        public void addParentLayerToLayer(Object parent, Object layer) {
160
                ((Layer)layer).setParentLayer(parent);
161

    
162
        }
163

    
164
        public void addSrsToLayer(String srs, Object layer) {
165
                ((Layer)layer).setSrs(srs);
166

    
167
        }
168

    
169

    
170
        public Object startBbox(String id, double[] x, double[] y, double[] z, String srs) {
171
                Bbox bbox = new Bbox();
172
                bbox.setX(x);
173
                bbox.setY(y);
174
                bbox.setZ(z);
175
                bbox.setId(id);
176
                bbox.setSrs(srs);
177
                return bbox;
178
        }
179

    
180
        public void endBbox(Object bbox) {
181
                // TODO Ap?ndice de m?todo generado autom?ticamente
182
        }
183

    
184
        public Object startElement(String name, Object value, Object type, Object parentElement) {
185
                Element element = new Element();
186
                element.setParentElement(parentElement);
187
                element.setName(name);
188
                element.setValue(value);
189
                element.setType(type);
190
                return element;
191
        }
192

    
193
        public void endElement(Object element) {
194
                // TODO Ap?ndice de m?todo generado autom?ticamente
195

    
196
        }
197

    
198
        public Object startFeature(String id, String name, Object layer) {
199
                // TODO Auto-generated method stub
200
                return null;
201
        }
202

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

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

    
230

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

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

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

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

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

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

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

    
304

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

    
309

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

    
315

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

    
319
        }
320

    
321

    
322
}
323