Revision 11209 trunk/libraries/libGPE/src-test/org/gvsig/gpe/GPEContentHandlerTest.java

View differences:

GPEContentHandlerTest.java
1 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.Layer;
9
import org.gvsig.gpe.containers.LineString;
10
import org.gvsig.gpe.containers.Point;
11
import org.gvsig.gpe.containers.Polygon;
12

  
2 13
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3 14
 *
4 15
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
......
43 54
 *
44 55
 * $Id$
45 56
 * $Log$
46
 * Revision 1.2  2007-04-13 13:14:55  jorpiell
57
 * Revision 1.3  2007-04-14 16:06:35  jorpiell
58
 * Add the container classes
59
 *
60
 * Revision 1.2  2007/04/13 13:14:55  jorpiell
47 61
 * Created the base tests and add some methods to the content handler
48 62
 *
49 63
 * Revision 1.1  2007/04/12 17:06:42  jorpiell
......
56 70
 */
57 71
public class GPEContentHandlerTest extends GPEContentHandler{
58 72
	private String tab = "";
59
	
73
	private Layer currentLayer = null;
74
	private Feature currentFeature = null;
75
	private ArrayList layers = new ArrayList();
76
		
60 77
	public Object startLayer(Object parent, Object bBox, String id,
61 78
			String name, String description,String srs) {
62 79
		System.out.print(tab + "Start Layer: " + name + "\n");
63 80
		tab = tab + "\t";
64
		return null;
81
		Layer layer = new Layer();
82
		layer.setParentLayer(parent);
83
		layer.setBbox(bBox);
84
		layer.setId(id);
85
		layer.setName(name);
86
		layer.setDescription(description);
87
		layer.setSrs(srs);
88
		currentLayer = layer;
89
		return layer;
65 90
	}
66 91

  
67 92
	public void endLayer(Object layer) {
68 93
		tab = tab.substring(0, tab.length()-1);
69 94
		System.out.print(tab + "End Layer\n");
70

  
95
		if (currentLayer != null){
96
			if (currentLayer.getParentLayer() == null){
97
				layers.add(currentLayer);
98
			}
99
			currentLayer = currentLayer.getParentLayer();			
100
		}		
71 101
	}
72 102

  
73 103
	public void addNameToLayer(Object layer,String name){
74 104
		System.out.print(tab + "Layer name changed: " + name + "\n");
105
		((Layer)layer).setName(name);
75 106
	}
76 107
	
77 108
	public void addDescriptionToLayer(Object layer,String description){
78 109
		System.out.print(tab + "Layer description changed: " + description + "\n");
110
		((Layer)layer).setDescription(description);
79 111
	}	
80 112
	
81 113
	public Object startElement(Object parent, String name, Object value,
82 114
			Object type) {
83
		// TODO Ap?ndice de m?todo generado autom?ticamente
84
		return null;
115
		Element element = new Element();
116
		element.setParentElement(parent);
117
		element.setName(name);
118
		element.setValue(value);
119
		element.setType(type);
120
		if (parent == null){
121
			currentFeature.addElement(element);
122
		}
123
		return element;
85 124
	}
86 125

  
87 126
	public void endElement(Object element) {
......
91 130

  
92 131
	public Object startBbox(double[] x, double[] y, double[] z, String id,
93 132
			String srs) {
94
		// TODO Ap?ndice de m?todo generado autom?ticamente
95
		return null;
133
		Bbox bbox = new Bbox();
134
		bbox.setX(x);
135
		bbox.setY(y);
136
		bbox.setZ(z);
137
		bbox.setId(id);
138
		bbox.setSrs(srs);
139
		return bbox;
96 140
	}
97 141

  
98 142
	public void endBbox(Object bbox) {
......
105 149
		tab = tab + "\t";
106 150
		System.out.print(tab + x + "," + y + "," + z + "\n");
107 151
		tab = tab.substring(0, tab.length()-1);
108
		return null;
152
		Point point = new Point();
153
		point.setX(x);
154
		point.setY(y);
155
		point.setZ(z);
156
		point.setId(id);
157
		point.setSrs(srs);
158
		currentFeature.setGeometry(point);
159
		return point;
109 160
	}
110 161

  
111 162
	public void endPoint(Object point) {
......
120 171
			System.out.print(tab + x[i] + "," + y[i] + "," + z[i] + "\n");
121 172
		}
122 173
		tab = tab.substring(0, tab.length()-1);
123
		return null;
174
		LineString lineString = new LineString();
175
		lineString.setX(x);
176
		lineString.setY(y);
177
		lineString.setZ(z);
178
		lineString.setId(id);
179
		lineString.setSrs(srs);
180
		currentFeature.setGeometry(lineString);
181
		return lineString;
124 182
	}
125 183

  
126 184
	public void endLineString(Object line) {
127 185
		System.out.print(tab + "End LineString:\n");
128
	}
186
	}	
129 187

  
130
	public Object startLinearRing(double[] x, double[] y, double[] z, String id,
131
			String srs) {
132
		// TODO Ap?ndice de m?todo generado autom?ticamente
133
		return null;
134
	}
135

  
136
	public void endLinearRing(Object linearRing) {
137
		// TODO Ap?ndice de m?todo generado autom?ticamente
138

  
139
	}
140

  
141 188
	public Object startPolygon(double[] x, double[] y, double[] z, String id,
142 189
			String srs) {
143
		// TODO Ap?ndice de m?todo generado autom?ticamente
144
		return null;
190
		System.out.print(tab + "Start Polygon, SRS:" + srs + "\n");
191
		tab = tab + "\t";
192
		for (int i=0 ; i<x.length ; i++){
193
			System.out.print(tab + x[i] + "," + y[i] + "," + z[i] + "\n");
194
		}
195
		tab = tab.substring(0, tab.length()-1);
196
		Polygon polygon = new Polygon();
197
		polygon.setX(x);
198
		polygon.setY(y);
199
		polygon.setZ(z);
200
		polygon.setId(id);
201
		polygon.setSrs(srs);
202
		currentFeature.setGeometry(polygon);
203
		return polygon;
145 204
	}
146 205

  
147 206
	public void endPolygon(Object polygon) {
148
		// TODO Ap?ndice de m?todo generado autom?ticamente
149

  
207
		System.out.print(tab + "End Polygon\n");
150 208
	}
151 209

  
152
	public void addInnerBoundary(Object polygon, Object linearRing) {
153
		// TODO Ap?ndice de m?todo generado autom?ticamente
154

  
210
	/*
211
	 * (non-Javadoc)
212
	 * @see org.gvsig.gpe.IGPEContentHandler#startInnerPolygon(java.lang.Object, double[], double[], double[], java.lang.String, java.lang.String)
213
	 */
214
	public Object startInnerPolygon(Object polygon, double[] x, double[] y, double[] z, String id, String srs){
215
		tab = tab + "\t";
216
		System.out.print(tab + "Start InnerPolygon, SRS:" + srs + "\n");
217
		tab = tab + "\t";
218
		for (int i=0 ; i<x.length ; i++){
219
			System.out.print(tab + x[i] + "," + y[i] + "," + z[i] + "\n");
220
		}
221
		tab = tab.substring(0, tab.length()-2);
222
		Polygon inner = new Polygon();
223
		inner.setX(x);
224
		inner.setY(y);
225
		inner.setZ(z);
226
		inner.setId(id);
227
		inner.setSrs(srs);
228
		((Polygon)polygon).addInnerBoundary(inner);
229
		return polygon;
155 230
	}
231
	
232
	/*
233
	 * (non-Javadoc)
234
	 * @see org.gvsig.gpe.IGPEContentHandler#endInnerPolygon(java.lang.Object)
235
	 */
236
	public void endInnerPolygon(Object polygon){
237
		tab = tab + "\t";
238
		System.out.print(tab + "End InnerPolygon\n");
239
		tab = tab.substring(0, tab.length()-1);
240
	}
156 241

  
157
	public void addOuterBoundary(Object polygon, Object linearRing) {
158
		// TODO Ap?ndice de m?todo generado autom?ticamente
159 242

  
160
	}
161

  
162 243
	public boolean isViewInBox(Object bbox, Object view) {
163 244
		// TODO Ap?ndice de m?todo generado autom?ticamente
164 245
		return false;
......
167 248
	public boolean isGeometryInBox(Object bbox, Object geometry) {
168 249
		// TODO Ap?ndice de m?todo generado autom?ticamente
169 250
		return false;
170
	}
251
	}	
171 252

  
172
	public void addFeature(Object layer, Object feature) {
173
		// TODO Ap?ndice de m?todo generado autom?ticamente
174

  
175
	}
176

  
177
	public void addBbox(Object item, Object bbox) {
178
		// TODO Ap?ndice de m?todo generado autom?ticamente
179

  
180
	}
181

  
182
	public void addElement(Object feature, Object element) {
183
		// TODO Ap?ndice de m?todo generado autom?ticamente
184

  
185
	}
186

  
187
	public void addGeometry(Object feature, Object geometry) {
188
		// TODO Ap?ndice de m?todo generado autom?ticamente
189

  
190
	}
191

  
192 253
	public Object startFeature(String name, String id) {
193 254
		System.out.print(tab + "Start Feature: " + name + "\n");
194
		return null;
255
		Feature feature = new Feature();
256
		feature.setName(name);
257
		feature.setId(id);
258
		currentLayer.addFeature(feature);
259
		currentFeature = feature;
260
		return feature;
195 261
	}
196 262
	
197 263
	public void addNameToFeature(Object feature, String name){
198 264
		System.out.print(tab + "Feature name changed: " + name + "\n");
265
		((Feature)feature).setName(name);
199 266
	}
200 267
	
201 268
	public void endFeature(Object feature) {
202 269
		System.out.print(tab + "End Feature\n");		
203 270
	}
271

  
272
	/**
273
	 * @return the layers
274
	 */
275
	public ArrayList getLayers() {
276
		return layers;
277
	}
204 278
	
205 279
}
206 280

  

Also available in: Unified diff