Revision 5824

View differences:

trunk/extensions/extWFS2/src-test/com/iver/cit/gvsig/fmap/layers/GMLParserTest.java
10 10
import com.hardcode.gdbms.engine.values.Value;
11 11
import com.iver.cit.gvsig.fmap.DriverException;
12 12
import com.iver.cit.gvsig.fmap.core.IFeature;
13
import com.iver.cit.gvsig.fmap.drivers.geotools.WFSGeotoolsDriver;
13
import com.iver.cit.gvsig.fmap.drivers.geotools.WFSFeatureLayer;
14 14
import com.iver.cit.gvsig.fmap.drivers.geotools.WFSFeaturesIterator;
15 15
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
16 16
 *
......
56 56
 *
57 57
 * $Id$
58 58
 * $Log$
59
 * Revision 1.4  2006-05-23 08:10:04  jorpiell
59
 * Revision 1.5  2006-06-14 07:57:19  jorpiell
60
 * Ya no se usa la estrategia ni se usa geotools para hacer el getFeature. Ahora se usa ?nicamente para el parseo de GML
61
 *
62
 * Revision 1.4  2006/05/23 08:10:04  jorpiell
60 63
 * Cambio probocado por el renombramiento de la clase DataStore por WFSDataStore
61 64
 *
62 65
 * Revision 1.3  2006/05/22 10:30:54  jorpiell
......
78 81
	private String feature = "cv:poblacion_pnt_300k";
79 82
	private String fields="tipo,municipio";
80 83
	
84
//	private String sUrl = "http://simon.coput.gva.es:2000/cgi-bin/mapserv483?map=/etc/mapserver/interno/wfs.map&REQUEST=getCapabilities&SERVICE=WFS";
85
//	private String feature = "cit:hidro_lin_300k";
86
//	private String fields="color,codigo";
87
	
81 88
	public void testWFS() throws IOException{	
82
		WFSStatus status = new WFSStatus(sUrl);
83
		status.setFeatureName(feature);
84
		WFSGeotoolsDriver client = new WFSGeotoolsDriver(sUrl,status);
89
//		WFSStatus status = new WFSStatus(sUrl);
90
//		status.setFeatureName(feature);
91
//		WFSFeatureLayer client = new WFSFeatureLayer(sUrl,status);
92
//		
93
//		WFSFeaturesIterator iterator = (WFSFeaturesIterator)client.getFeature(status);
94
//				
95
//		ArrayList features = client.getFeatures();
96
//		
97
//		for (int i=0 ; i<features.size() ; i++){
98
//			IFeature currentFeature = (IFeature)features.get(i);
99
//			Value[] attributes = currentFeature.getAttributes();
100
//			System.out.println("**** NEW FEATURE ****");
101
//			for (int j=0 ; j<attributes.length ; j++){
102
//				if (attributes[j] != null){
103
//					System.out.println(attributes[j].toString());
104
//				}
105
//			}
106
//		}		
85 107
		
86
		WFSFeaturesIterator iterator = (WFSFeaturesIterator)client.getFeature(status);
87
				
88
		ArrayList features = client.getFeatures();
89
		
90
		for (int i=0 ; i<features.size() ; i++){
91
			IFeature currentFeature = (IFeature)features.get(i);
92
			Value[] attributes = currentFeature.getAttributes();
93
			System.out.println("**** NEW FEATURE ****");
94
			for (int j=0 ; j<attributes.length ; j++){
95
				if (attributes[j] != null){
96
					System.out.println(attributes[j].toString());
97
				}
98
			}
99
		}		
100
		
101 108
	}	
102 109
}
trunk/extensions/extWFS2/src/com/iver/cit/gvsig/fmap/drivers/wfs/FMapWFSDriver.java
1 1
package com.iver.cit.gvsig.fmap.drivers.wfs;
2 2

  
3 3
import java.awt.geom.Rectangle2D;
4
import java.io.File;
4 5
import java.io.IOException;
5 6
import java.net.ConnectException;
6 7
import java.net.URL;
......
30 31
import com.iver.cit.gvsig.fmap.drivers.WFSDriver;
31 32
import com.iver.cit.gvsig.fmap.drivers.WFSException;
32 33
import com.iver.cit.gvsig.fmap.drivers.geotools.WFSFeaturesIterator;
33
import com.iver.cit.gvsig.fmap.drivers.geotools.WFSGeotoolsDriver;
34
import com.iver.cit.gvsig.fmap.drivers.geotools.WFSFeatureLayer;
35
import com.iver.cit.gvsig.fmap.drivers.geotools.WFSGetFeatureParser;
34 36
import com.iver.cit.gvsig.fmap.layers.WFSLayerNode;
35 37

  
36 38
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
......
77 79
 *
78 80
 * $Id$
79 81
 * $Log$
80
 * Revision 1.9  2006-06-05 16:49:42  caballero
82
 * Revision 1.10  2006-06-14 07:57:19  jorpiell
83
 * Ya no se usa la estrategia ni se usa geotools para hacer el getFeature. Ahora se usa ?nicamente para el parseo de GML
84
 *
85
 * Revision 1.9  2006/06/05 16:49:42  caballero
81 86
 * poder editar y exportar
82 87
 *
83 88
 * Revision 1.8  2006/05/30 05:26:38  jorpiell
......
111 116
 */
112 117
public class FMapWFSDriver implements WFSDriver, BoundedShapes,ObjectDriver{
113 118
	private WFSClient remoteServicesClient;
114
	private WFSGeotoolsDriver geotoolsClient;
115
    private WFSLayerNode[] featuresList;
119
	private WFSLayerNode[] featuresList;
116 120
    private Hashtable hashFeatures;
117

  
118
   private int idFID_FieldName;
119
	private int numField = -1;
120
	//private AttributeType[] attributes;
121
    private String strOriginalSRID;
121
    private WFSFeatureLayer featureIterator= null;
122 122
    private DriverAttributes attr = new DriverAttributes();
123 123

  
124 124
	public FMapWFSDriver() {
......
151 151
	 * @see com.iver.cit.gvsig.fmap.drivers.WFSDriver#getFeature(org.gvsig.remoteClient.wfs.WFSStatus)
152 152
	 */
153 153
	public void getFeature(WFSStatus wfsStatus) throws WFSException {
154
		//Using remoteServices
155
		//return remoteServicesClient.getFeature(wfsStatus);
156
		//Using geotools
157
		if (geotoolsClient == null){
158
			try {
159
				geotoolsClient = new WFSGeotoolsDriver(remoteServicesClient.getHost(),
160
						wfsStatus);
161
			} catch (ConnectException e) {
162
				// TODO Auto-generated catch block
163
				e.printStackTrace();
164
				throw new WFSException();
165
			}
154
		File file = remoteServicesClient.getFeature(wfsStatus);
155
		try {
156
			featureIterator = new WFSFeatureLayer(file,
157
					featuresList,
158
					wfsStatus);
159
		} catch (Exception e) {
160
			throw new WFSException(e);
166 161
		}
167
		geotoolsClient.getFeature(wfsStatus);
168 162
	}
169 163

  
170 164
	/*
......
196 190
	 * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getFullExtent()
197 191
	 */
198 192
	public Rectangle2D getFullExtent() throws IOException {
199
		return geotoolsClient.getFullExtent();
193
		return featureIterator.getFullExtent();
200 194
	}
201 195

  
202 196
	/*
......
212 206
	 * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#reLoad()
213 207
	 */
214 208
	public void reLoad() throws IOException {
215
		geotoolsClient.getFeature(null);
209
		featureIterator.reload();
216 210
	}
217 211

  
218 212
	/*
......
380 374
	 * @return Returns the features.
381 375
	 */
382 376
	public ArrayList getFeatures() {
383
		return geotoolsClient.getFeatures();
377
		return featureIterator.getFeatures();
384 378
	}
385 379

  
386 380
	/**
387 381
	 * @return Returns the hashRelate.
388 382
	 */
389 383
	public Hashtable getHashRelate() {
390
		return geotoolsClient.getHashRelate();
384
		return featureIterator.getHashRelate();
391 385
	}
392 386

  
393 387

  
......
395 389
	 * @return Returns the numReg.
396 390
	 */
397 391
	public int getNumReg() {
398
		return geotoolsClient.getNumReg();
392
		return featureIterator.getNumReg();
399 393
	}
400 394

  
401 395
 	/**
402 396
	 * @return Returns the numFiled.
403 397
	 */
404 398
	public int getNumField() {
405
		return geotoolsClient.getNumField();
399
		return featureIterator.getNumField();
406 400
	}
407 401

  
408 402
	/**
409 403
	 * @return Returns the attributes.
410 404
	 */
411 405
	public AttributeType[] getAttributes() {
412
		return geotoolsClient.getAttributes();
406
		return featureIterator.getAttributes();
413 407
	}
414 408

  
415 409
	/*
......
512 506
	 * @see com.iver.cit.gvsig.fmap.drivers.WFSDriver#getFeatureIterator(java.awt.geom.Rectangle2D, java.lang.String)
513 507
	 */
514 508
	public IFeatureIterator getFeatureIterator(Rectangle2D r, String strEPSG) throws DriverException, IOException {
515
		return geotoolsClient.getIterator();
509
		return featureIterator.getIterator();
516 510
	}
517 511

  
518 512
	/*
trunk/extensions/extWFS2/src/com/iver/cit/gvsig/fmap/drivers/geotools/WFSDataStore.java
1
package com.iver.cit.gvsig.fmap.drivers.geotools;
2

  
3
import java.io.IOException;
4
import java.net.URL;
5

  
6
import org.xml.sax.SAXException;
7

  
8
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
9
 *
10
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
11
 *
12
 * This program is free software; you can redistribute it and/or
13
 * modify it under the terms of the GNU General Public License
14
 * as published by the Free Software Foundation; either version 2
15
 * of the License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program; if not, write to the Free Software
24
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
25
 *
26
 * For more information, contact:
27
 *
28
 *  Generalitat Valenciana
29
 *   Conselleria d'Infraestructures i Transport
30
 *   Av. Blasco Ib??ez, 50
31
 *   46010 VALENCIA
32
 *   SPAIN
33
 *
34
 *      +34 963862235
35
 *   gvsig@gva.es
36
 *      www.gvsig.gva.es
37
 *
38
 *    or
39
 *
40
 *   IVER T.I. S.A
41
 *   Salamanca 50
42
 *   46005 Valencia
43
 *   Spain
44
 *
45
 *   +34 963163400
46
 *   dac@iver.es
47
 */
48
/* CVS MESSAGES:
49
 *
50
 * $Id$
51
 * $Log$
52
 * Revision 1.2  2006-05-23 13:21:12  jorpiell
53
 * Modificado el datasource para capturar las excepciones de parseo
54
 *
55
 * Revision 1.1  2006/05/23 08:06:40  jorpiell
56
 * Clase que antiguamente se llamaba DataStore
57
 *
58
 * Revision 1.2  2006/05/19 12:47:21  jorpiell
59
 * DataStore que usa geotools. La clase datastore de geotools es abstracta, por lo que tenemos que crear esta clase que hereda de ella
60
 *
61
 * Revision 1.1  2006/05/19 12:45:47  jorpiell
62
 * DataStore que usa geotools. La clase datastore de geotools es abstracta, por lo que tenemos que crear esta clase que hereda de ella
63
 *
64
 *
65
 */
66
/**
67
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
68
 */
69
public class WFSDataStore extends org.geotools.data.wfs.WFSDataStore{
70

  
71
	public WFSDataStore(URL url, Boolean getProtocol, String user, String password, int timeOut, int buffer) throws SAXException, IOException {
72
		super(url, getProtocol, user, password, timeOut, buffer);
73
	}
74
}
trunk/extensions/extWFS2/src/com/iver/cit/gvsig/fmap/drivers/geotools/WFSGeotoolsDriver.java
1
package com.iver.cit.gvsig.fmap.drivers.geotools;
2

  
3
import java.awt.geom.Rectangle2D;
4
import java.io.IOException;
5
import java.net.ConnectException;
6
import java.net.MalformedURLException;
7
import java.net.URL;
8
import java.util.ArrayList;
9
import java.util.HashMap;
10
import java.util.Hashtable;
11
import java.util.Map;
12

  
13
import org.geotools.data.DefaultQuery;
14
import org.geotools.data.FeatureReader;
15
import org.geotools.data.Query;
16
import org.geotools.data.Transaction;
17
import org.geotools.data.wfs.WFSDataStoreFactory;
18
import org.geotools.feature.AttributeType;
19
import org.gvsig.remoteClient.RemoteClient;
20
import org.gvsig.remoteClient.wfs.WFSStatus;
21
import org.gvsig.remoteClient.wms.ICancellable;
22
import org.xml.sax.SAXException;
23

  
24
import com.iver.cit.gvsig.fmap.DriverException;
25
import com.iver.cit.gvsig.fmap.core.IFeature;
26

  
27

  
28
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
29
 *
30
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
31
 *
32
 * This program is free software; you can redistribute it and/or
33
 * modify it under the terms of the GNU General Public License
34
 * as published by the Free Software Foundation; either version 2
35
 * of the License, or (at your option) any later version.
36
 *
37
 * This program is distributed in the hope that it will be useful,
38
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
39
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
40
 * GNU General Public License for more details.
41
 *
42
 * You should have received a copy of the GNU General Public License
43
 * along with this program; if not, write to the Free Software
44
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
45
 *
46
 * For more information, contact:
47
 *
48
 *  Generalitat Valenciana
49
 *   Conselleria d'Infraestructures i Transport
50
 *   Av. Blasco Ib??ez, 50
51
 *   46010 VALENCIA
52
 *   SPAIN
53
 *
54
 *      +34 963862235
55
 *   gvsig@gva.es
56
 *      www.gvsig.gva.es
57
 *
58
 *    or
59
 *
60
 *   IVER T.I. S.A
61
 *   Salamanca 50
62
 *   46005 Valencia
63
 *   Spain
64
 *
65
 *   +34 963163400
66
 *   dac@iver.es
67
 */
68
/* CVS MESSAGES:
69
 *
70
 * $Id$
71
 * $Log$
72
 * Revision 1.6  2006-05-25 10:32:21  jorpiell
73
 * Se ha renombrado la clase WFSFields por WFSAttributes porque era algo confusa
74
 *
75
 * Revision 1.5  2006/05/24 07:21:38  jorpiell
76
 * Si no ha dado tiempo a inicializar el resultset se debe devolver nulo
77
 *
78
 * Revision 1.4  2006/05/23 08:07:37  jorpiell
79
 * Cambio probocado por el renombramiento de la clase DataStore por WFSDataStore
80
 *
81
 * Revision 1.3  2006/05/22 10:32:01  jorpiell
82
 * El connect debe de tener en cuanta los valores del buffer y el timeout
83
 *
84
 * Revision 1.2  2006/05/22 10:10:46  jorpiell
85
 * El driver recorre las features la primera vez e inicializa el vector
86
 *
87
 * Revision 1.1  2006/05/19 12:48:21  jorpiell
88
 * Driver que implementa la accesibilidad a geotools
89
 *
90
 *
91
 */
92
/**
93
 * This class implements the WFS getFetaure method using the
94
 * Geotools library
95
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
96
 */
97
public class WFSGeotoolsDriver extends RemoteClient{
98
	private WFSDataStore dataStore = null;
99
	private ArrayList features = new ArrayList();
100
	private Rectangle2D fullExtent = null;
101
	private Hashtable hashRelate = new Hashtable();
102
	private WFSStatus currentStatus = null;
103
	private int numReg = -1;
104
	private int numField = -1;
105
	private AttributeType[] attributes;
106
	private WFSFeaturesIterator iterator = null;
107
	
108
	public WFSGeotoolsDriver(String host,WFSStatus status) throws ConnectException{
109
		if (status != null){
110
			this.currentStatus = status;
111
		}
112
		this.setHost(host);
113
		if (!connect(null)){
114
			throw new ConnectException();	
115
		}		
116
	}
117
	
118
	/**
119
	 * The GetFeature operation allows retrieval of features from a 
120
	 * web feature service. A GetFeature request is processed by
121
	 * a WFS and when the value of the outputFormat attribute is 
122
	 * set to text/gml a GML instance document, containing the 
123
	 * result set, is returned to the client.
124
	 * @param status
125
	 * WFS client status. Contains all the information to create
126
	 * the query
127
	 * @return Object
128
	 * GML File
129
	 */
130
	public Object getFeature(WFSStatus status){
131
		try { 
132
			DefaultQuery query = new DefaultQuery(currentStatus.getFeatureName());
133
			query.setPropertyNames(status.getFields());
134
			FeatureReader featureReader;
135
			featureReader = dataStore.getFeatureReader(query,Transaction.AUTO_COMMIT);
136
			if (numField == -1) {
137
				numField = featureReader.getFeatureType().getAttributeCount();
138
				attributes = featureReader.getFeatureType().getAttributeTypes();
139
			}
140
			iterator = new WFSFeaturesIterator(featureReader);
141
			initialize();
142
			return iterator;
143
		} catch (IOException e) {
144
			// TODO Auto-generated catch block
145
			e.printStackTrace();			
146
		} 
147
		return null;
148
	}	
149
	
150
	/**
151
	 * Sets the retrieved features
152
	 * @param transformation
153
	 * @throws DriverException 
154
	 * @throws DriverException 
155
	 */
156
	private void initialize() {
157
		int index = 0;
158
		while (iterator.hasNext()){
159
			IFeature feature;
160
			try {
161
				feature = iterator.next();
162
				try{
163
					features.add(feature);
164
					Rectangle2D rect = feature.getGeometry().getBounds2D();
165
					
166
					if (fullExtent == null) {
167
						fullExtent = new Rectangle2D.Double(rect.getMinX(),
168
								rect.getMinY(), rect.getWidth(), rect.getHeight());
169
					} else {
170
						fullExtent.add(new Rectangle2D.Double(rect.getMinX(),
171
								rect.getMinY(), rect.getWidth(), rect.getHeight()));
172
					}
173
					
174
					hashRelate.put(feature.getID(), new Integer(index));
175
				}catch(NullPointerException e){
176
					//
177
				}
178
			} catch (DriverException e) {
179
				// TODO Auto-generated catch block
180
				e.printStackTrace();
181
			}			
182
			index++;
183
		}
184
		numReg = index;
185
	}
186

  
187
	/*
188
	 *  (non-Javadoc)
189
	 * @see org.gvsig.remoteClient.RemoteClient#connect()
190
	 */
191
	public boolean connect(ICancellable cancel) {
192
		URL url;
193
		try {
194
			url = new URL(getCapabilitiesRequest());
195
			dataStore = new WFSDataStore(url, 
196
					new Boolean(true), 
197
					currentStatus.getUserName(), 
198
					currentStatus.getPassword(), 
199
					currentStatus.getTimeout(), 
200
					currentStatus.getBuffer());
201
			return true;
202
		} catch (MalformedURLException e) {
203
			// TODO Auto-generated catch block
204
			e.printStackTrace();
205
		} catch (IOException e) {
206
			// TODO Auto-generated catch block
207
			e.printStackTrace();
208
		} catch (SAXException e) {
209
			// TODO Auto-generated catch block
210
			e.printStackTrace();
211
		} 
212
		return false;         
213
	}
214

  
215
	/**
216
	 * @return the host name
217
	 */
218
    public String getCapabilitiesRequest() {        
219
    	StringBuffer req = new StringBuffer();
220
    	req.append(super.getHost()).append("?").append("REQUEST=GetCapabilities&SERVICE=WFS&");
221
    	req.append("&EXCEPTIONS=XML");
222
    	return req.toString();        
223
    } 
224

  
225
	/*
226
	 *  (non-Javadoc)
227
	 * @see org.gvsig.remoteClient.RemoteClient#close()
228
	 */
229
	public void close() {
230
		// TODO Auto-generated method stub
231
		
232
	}
233

  
234
	/**
235
	 * @return Returns the features.
236
	 */
237
	public ArrayList getFeatures() {
238
		return features;
239
	}
240

  
241
	/**
242
	 * @return Returns the hashRelate.
243
	 */
244
	public Hashtable getHashRelate() {
245
		return hashRelate;
246
	}
247

  
248
	/**
249
	 * @return Returns the fullExtent.
250
	 */
251
	public Rectangle2D getFullExtent() {
252
		return fullExtent;
253
	}
254

  
255
	/**
256
	 * @return Returns the numReg.
257
	 */
258
	public int getNumReg() {
259
		return numReg;
260
	}
261

  
262
	/**
263
	 * @return Returns the attributes.
264
	 */
265
	public AttributeType[] getAttributes() {
266
		return attributes;
267
	}
268

  
269
	/**
270
	 * @return Returns the numField.
271
	 */
272
	public int getNumField() {
273
		return numField;
274
	}
275

  
276
	/**
277
	 * @return Returns the iterator.
278
	 */
279
	public WFSFeaturesIterator getIterator() {
280
			if (iterator == null){
281
				return null;
282
			}
283
			iterator.startIteration();
284
			return iterator;		
285
	}
286
}
trunk/extensions/extWFS2/src/com/iver/cit/gvsig/fmap/drivers/geotools/WFSFilter.java
1 1
package com.iver.cit.gvsig.fmap.drivers.geotools;
2 2

  
3
import java.util.Hashtable;
3 4
import java.util.Vector;
4 5

  
5 6
import org.geotools.filter.CompareFilter;
......
9 10

  
10 11
import com.iver.andami.PluginServices;
11 12
import com.iver.cit.gvsig.fmap.layers.WFSLayerNode;
13
import com.vividsolutions.jts.geom.Geometry;
14
import com.vividsolutions.jts.geom.GeometryCollection;
15
import com.vividsolutions.jts.geom.LineString;
16
import com.vividsolutions.jts.geom.MultiLineString;
17
import com.vividsolutions.jts.geom.MultiPoint;
18
import com.vividsolutions.jts.geom.MultiPolygon;
19
import com.vividsolutions.jts.geom.Point;
20
import com.vividsolutions.jts.geom.Polygon;
12 21

  
13 22
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
14 23
 *
......
54 63
 *
55 64
 * $Id$
56 65
 * $Log$
57
 * Revision 1.3  2006-05-25 15:32:01  jorpiell
66
 * Revision 1.4  2006-06-14 07:57:19  jorpiell
67
 * Ya no se usa la estrategia ni se usa geotools para hacer el getFeature. Ahora se usa ?nicamente para el parseo de GML
68
 *
69
 * Revision 1.3  2006/05/25 15:32:01  jorpiell
58 70
 * Se ha a?adido la funcionalidad para eliminar el namespace de los tipos de atributos
59 71
 *
60 72
 * Revision 1.2  2006/05/25 10:32:21  jorpiell
......
155 167
		return sAttribute;
156 168
	}
157 169
	
170
	public static Class getAttributeJavaType(WFSAttribute attribute){
171
		String sType = getAttributeType(attribute);
172
		Class clazz = GmlToJavaConversion.get(sType);
173
		if (clazz == null){
174
			clazz = String.class;
175
		}
176
		return clazz;
177
	}
158 178
	
179
	public static class GmlToJavaConversion{
180
		private static Hashtable typeMap = new Hashtable();
181

  
182
	    static {
183
	        typeMap.put("STRING", String.class);
184
	        typeMap.put("\"\"", String.class);
185
	        typeMap.put("INTEGER", Integer.class);
186
	        typeMap.put("INT", Integer.class);
187
	        typeMap.put("0", Integer.class);
188
	        typeMap.put("DOUBLE", Double.class);
189
	        typeMap.put("0.0", Double.class);
190
	        typeMap.put("FLOAT", Float.class);
191
	        typeMap.put("0.0F", Float.class);
192
	        typeMap.put("GEOMETRY", Geometry.class);
193
	        typeMap.put("GEOMETRYPROPERTYTYPE", Geometry.class);
194
	        typeMap.put("POINT", Point.class);
195
	        typeMap.put("POINTPROPERTYTYPE", Point.class);
196
	        typeMap.put("LINESTRING", LineString.class);
197
	        typeMap.put("LINESTRINGPROPERTYTYPE", LineString.class);
198
	        typeMap.put("POLYGON", Polygon.class);
199
	        typeMap.put("POLYGONPROPERTYTYPE", Polygon.class);
200
	        typeMap.put("MULTIPOINT", MultiPoint.class);
201
	        typeMap.put("MULTIPOINTPROPERTYTYPE", MultiPoint.class);
202
	        typeMap.put("MULTILINESTRING", MultiLineString.class);
203
	        typeMap.put("MULTILINESTRINGPROPERTYTYPE", MultiLineString.class);
204
	        typeMap.put("MULTIPOLYGON", MultiPolygon.class);
205
	        typeMap.put("MULTIPOLYGONPROPERTYTYPE", MultiPolygon.class);
206
	        typeMap.put("MULTIGEOMETRYPROPERTYTYPE", GeometryCollection.class);
207
	        typeMap.put("GEOMETRYCOLLECTION", GeometryCollection.class);
208
	        typeMap.put("GEOMETRYASSOCIATIONTYPE", Geometry.class);
209
	    }
210
		
211
		public static Class get(String key){
212
			return (Class)typeMap.get(key.toUpperCase());
213
		}
214
	}	
159 215
}
trunk/extensions/extWFS2/src/com/iver/cit/gvsig/fmap/drivers/geotools/WFSFeatureLayer.java
1
package com.iver.cit.gvsig.fmap.drivers.geotools;
2

  
3
import java.awt.geom.Rectangle2D;
4
import java.io.File;
5
import java.io.IOException;
6
import java.net.ConnectException;
7
import java.net.MalformedURLException;
8
import java.net.URL;
9
import java.util.ArrayList;
10
import java.util.HashMap;
11
import java.util.Hashtable;
12
import java.util.Map;
13

  
14
import org.geotools.data.DefaultQuery;
15
import org.geotools.data.FeatureReader;
16
import org.geotools.data.Query;
17
import org.geotools.data.Transaction;
18
import org.geotools.data.wfs.WFSDataStoreFactory;
19
import org.geotools.feature.AttributeType;
20
import org.gvsig.remoteClient.RemoteClient;
21
import org.gvsig.remoteClient.wfs.WFSStatus;
22
import org.gvsig.remoteClient.wms.ICancellable;
23
import org.xml.sax.SAXException;
24

  
25
import com.iver.cit.gvsig.fmap.DriverException;
26
import com.iver.cit.gvsig.fmap.core.IFeature;
27
import com.iver.cit.gvsig.fmap.layers.WFSLayerNode;
28

  
29

  
30
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
31
 *
32
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
33
 *
34
 * This program is free software; you can redistribute it and/or
35
 * modify it under the terms of the GNU General Public License
36
 * as published by the Free Software Foundation; either version 2
37
 * of the License, or (at your option) any later version.
38
 *
39
 * This program is distributed in the hope that it will be useful,
40
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
41
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
42
 * GNU General Public License for more details.
43
 *
44
 * You should have received a copy of the GNU General Public License
45
 * along with this program; if not, write to the Free Software
46
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
47
 *
48
 * For more information, contact:
49
 *
50
 *  Generalitat Valenciana
51
 *   Conselleria d'Infraestructures i Transport
52
 *   Av. Blasco Ib??ez, 50
53
 *   46010 VALENCIA
54
 *   SPAIN
55
 *
56
 *      +34 963862235
57
 *   gvsig@gva.es
58
 *      www.gvsig.gva.es
59
 *
60
 *    or
61
 *
62
 *   IVER T.I. S.A
63
 *   Salamanca 50
64
 *   46005 Valencia
65
 *   Spain
66
 *
67
 *   +34 963163400
68
 *   dac@iver.es
69
 */
70
/* CVS MESSAGES:
71
 *
72
 * $Id$
73
 * $Log$
74
 * Revision 1.1  2006-06-14 07:57:19  jorpiell
75
 * Ya no se usa la estrategia ni se usa geotools para hacer el getFeature. Ahora se usa ?nicamente para el parseo de GML
76
 *
77
 * Revision 1.6  2006/05/25 10:32:21  jorpiell
78
 * Se ha renombrado la clase WFSFields por WFSAttributes porque era algo confusa
79
 *
80
 * Revision 1.5  2006/05/24 07:21:38  jorpiell
81
 * Si no ha dado tiempo a inicializar el resultset se debe devolver nulo
82
 *
83
 * Revision 1.4  2006/05/23 08:07:37  jorpiell
84
 * Cambio probocado por el renombramiento de la clase DataStore por WFSDataStore
85
 *
86
 * Revision 1.3  2006/05/22 10:32:01  jorpiell
87
 * El connect debe de tener en cuanta los valores del buffer y el timeout
88
 *
89
 * Revision 1.2  2006/05/22 10:10:46  jorpiell
90
 * El driver recorre las features la primera vez e inicializa el vector
91
 *
92
 * Revision 1.1  2006/05/19 12:48:21  jorpiell
93
 * Driver que implementa la accesibilidad a geotools
94
 *
95
 *
96
 */
97
/**
98
 *
99
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
100
 */
101
public class WFSFeatureLayer {
102
	private ArrayList features = new ArrayList();
103
	private Rectangle2D fullExtent = null;
104
	private Hashtable hashRelate = new Hashtable();
105
	private WFSStatus currentStatus = null;
106
	private int numReg = -1;
107
	private int numField = -1;
108
	private AttributeType[] attributes;
109
	private WFSFeaturesIterator iterator = null;
110
	
111
	public WFSFeatureLayer(File file,WFSLayerNode[] schema,WFSStatus status) throws Exception{
112
		iterator = WFSGetFeatureParser.getFeatureReader(file,
113
				schema,
114
				status);
115
		initialize();
116
	}
117
	
118
	/**
119
	 * Reloads the layer
120
	 *
121
	 */
122
	public void reload(){
123
		initialize();
124
	}
125
	
126
	/**
127
	 * Sets the retrieved features
128
	 * @param transformation
129
	 * @throws DriverException 
130
	 * @throws DriverException 
131
	 */
132
	private void initialize() {
133
		int index = 0;
134
		while (iterator.hasNext()){
135
			IFeature feature;
136
			try {
137
				feature = iterator.next();
138
				try{
139
					features.add(feature);
140
					Rectangle2D rect = feature.getGeometry().getBounds2D();
141
					
142
					if (fullExtent == null) {
143
						fullExtent = new Rectangle2D.Double(rect.getMinX(),
144
								rect.getMinY(), rect.getWidth(), rect.getHeight());
145
					} else {
146
						fullExtent.add(new Rectangle2D.Double(rect.getMinX(),
147
								rect.getMinY(), rect.getWidth(), rect.getHeight()));
148
					}
149
					
150
					hashRelate.put(feature.getID(), new Integer(index));
151
				}catch(NullPointerException e){
152
					//
153
				}
154
			} catch (DriverException e) {
155
				// TODO Auto-generated catch block
156
				e.printStackTrace();
157
			}			
158
			index++;
159
		}
160
		numReg = index;
161
	}
162

  
163
	/**
164
	 * @return Returns the features.
165
	 */
166
	public ArrayList getFeatures() {
167
		return features;
168
	}
169

  
170
	/**
171
	 * @return Returns the hashRelate.
172
	 */
173
	public Hashtable getHashRelate() {
174
		return hashRelate;
175
	}
176

  
177
	/**
178
	 * @return Returns the fullExtent.
179
	 */
180
	public Rectangle2D getFullExtent() {
181
		return fullExtent;
182
	}
183

  
184
	/**
185
	 * @return Returns the numReg.
186
	 */
187
	public int getNumReg() {
188
		return numReg;
189
	}
190

  
191
	/**
192
	 * @return Returns the attributes.
193
	 */
194
	public AttributeType[] getAttributes() {
195
		return attributes;
196
	}
197

  
198
	/**
199
	 * @return Returns the numField.
200
	 */
201
	public int getNumField() {
202
		return numField;
203
	}
204

  
205
	/**
206
	 * @return Returns the iterator.
207
	 */
208
	public WFSFeaturesIterator getIterator() {
209
			if (iterator == null){
210
				return null;
211
			}
212
			iterator.startIteration();
213
			return iterator;		
214
	}
215
}
0 216

  
trunk/extensions/extWFS2/src/com/iver/cit/gvsig/fmap/drivers/geotools/WFSGetFeatureParser.java
1
package com.iver.cit.gvsig.fmap.drivers.geotools;
2

  
3
import java.io.File;
4
import java.io.FileInputStream;
5
import java.io.FileNotFoundException;
6
import java.io.IOException;
7
import java.io.InputStream;
8
import java.net.Authenticator;
9
import java.net.URI;
10
import java.net.URL;
11
import java.util.HashMap;
12
import java.util.List;
13
import java.util.Map;
14
import java.util.Vector;
15

  
16
import org.geotools.data.AbstractDataStore;
17
import org.geotools.data.DefaultQuery;
18
import org.geotools.data.FeatureReader;
19
import org.geotools.data.ows.FeatureSetDescription;
20
import org.geotools.data.ows.WFSCapabilities;
21
import org.geotools.data.wfs.WFSFeatureReader;
22
import org.geotools.data.wfs.WFSTransactionState;
23
import org.geotools.factory.FactoryConfigurationError;
24
import org.geotools.feature.AttributeType;
25
import org.geotools.feature.AttributeTypeFactory;
26
import org.geotools.feature.FeatureType;
27
import org.geotools.feature.FeatureTypeBuilder;
28
import org.geotools.feature.SchemaException;
29
import org.geotools.xml.gml.GMLComplexTypes;
30
import org.geotools.xml.schema.Element;
31
import org.gvsig.remoteClient.wfs.WFSAttribute;
32
import org.gvsig.remoteClient.wfs.WFSStatus;
33
import org.xml.sax.SAXException;
34

  
35
import com.iver.cit.gvsig.fmap.layers.WFSLayerNode;
36

  
37
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
38
 *
39
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
40
 *
41
 * This program is free software; you can redistribute it and/or
42
 * modify it under the terms of the GNU General Public License
43
 * as published by the Free Software Foundation; either version 2
44
 * of the License, or (at your option) any later version.
45
 *
46
 * This program is distributed in the hope that it will be useful,
47
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
48
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
49
 * GNU General Public License for more details.
50
 *
51
 * You should have received a copy of the GNU General Public License
52
 * along with this program; if not, write to the Free Software
53
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
54
 *
55
 * For more information, contact:
56
 *
57
 *  Generalitat Valenciana
58
 *   Conselleria d'Infraestructures i Transport
59
 *   Av. Blasco Ib??ez, 50
60
 *   46010 VALENCIA
61
 *   SPAIN
62
 *
63
 *      +34 963862235
64
 *   gvsig@gva.es
65
 *      www.gvsig.gva.es
66
 *
67
 *    or
68
 *
69
 *   IVER T.I. S.A
70
 *   Salamanca 50
71
 *   46005 Valencia
72
 *   Spain
73
 *
74
 *   +34 963163400
75
 *   dac@iver.es
76
 */
77
/* CVS MESSAGES:
78
 *
79
 * $Id$
80
 * $Log$
81
 * Revision 1.1  2006-06-14 07:57:19  jorpiell
82
 * Ya no se usa la estrategia ni se usa geotools para hacer el getFeature. Ahora se usa ?nicamente para el parseo de GML
83
 *
84
 * Revision 1.2  2006/05/23 13:21:12  jorpiell
85
 * Modificado el datasource para capturar las excepciones de parseo
86
 *
87
 * Revision 1.1  2006/05/23 08:06:40  jorpiell
88
 * Clase que antiguamente se llamaba DataStore
89
 *
90
 * Revision 1.2  2006/05/19 12:47:21  jorpiell
91
 * DataStore que usa geotools. La clase datastore de geotools es abstracta, por lo que tenemos que crear esta clase que hereda de ella
92
 *
93
 * Revision 1.1  2006/05/19 12:45:47  jorpiell
94
 * DataStore que usa geotools. La clase datastore de geotools es abstracta, por lo que tenemos que crear esta clase que hereda de ella
95
 *
96
 *
97
 */
98
/**
99
 * It parses a getFeature request file
100
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
101
 */
102
public class WFSGetFeatureParser{
103

  
104
	/**
105
	 * Return an iterrator of features
106
	 * @param file
107
	 * File to parse
108
	 * @param schemas
109
	 * Schemas to retrieve
110
	 * @param status
111
	 * Serviced status
112
	 * @return
113
	 * Iterator
114
	 * @throws Exception
115
	 */
116
	public static WFSFeaturesIterator getFeatureReader(File file,WFSLayerNode[] schemas,WFSStatus status) throws Exception{
117
		FileInputStream is = new FileInputStream(file);
118
		WFSLayerNode schema = null;
119
		for (int i=0 ; i<schemas.length ; i++){
120
			if (schemas[i].getName().equals(status.getFeatureName())){
121
				schema = schemas[i];
122
			}
123
		}
124
		return new WFSFeaturesIterator(getFeatureReader(is,
125
				status.getBuffer(),
126
				status.getTimeout(),
127
				null,
128
				featureTypefromGeotoolsToGvSIG(schema)));
129
	}
130
	
131
	/**
132
	 * Gets a feature reader
133
	 * @param is
134
	 * WFS getFeature XML File
135
	 * @param bufferSize
136
	 * buffer size
137
	 * @param timeout
138
	 * Request timeout
139
	 * @param transaction
140
	 * @param ft
141
	 * Feature schema
142
	 * @return
143
	 * @throws SAXException 
144
	 */
145
	private static FeatureReader getFeatureReader(InputStream is,
146
	        int bufferSize, int timeout, WFSTransactionState transaction, FeatureType ft) throws SAXException{
147
    	return WFSFeatureReader.getFeatureReader(is, bufferSize,
148
    			timeout, transaction, ft);
149
    }
150

  
151
	 
152
	 /**
153
	  * Make a conversion between the gvSIG WFSLayerNode and a geotools
154
	  * FeatureType.
155
	  * @param schema
156
	  * gvSIG feature schema that contains a list of attributes
157
	  * @return
158
	  */
159
	 private static FeatureType featureTypefromGeotoolsToGvSIG(WFSLayerNode schema) throws FactoryConfigurationError, SchemaException{
160
		 AttributeType[] types = attributteTypefromGeotoolsToGvSIG(schema);
161
		 String typeName = schema.getName();
162
		 
163
		 FeatureType	featureType = FeatureTypeBuilder.newFeatureType(types,typeName);					
164
		 return featureType;
165
	 }
166
	 
167
	/**
168
	 * Make a conversion between the gvSIG WFSAttribute and a geotools
169
	 * AttributeType.
170
	 * @param schema
171
	 * gvSIG feature schema that contains a list of attributes
172
	 * @return
173
	 */
174
	 private static AttributeType[] attributteTypefromGeotoolsToGvSIG(WFSLayerNode schema){
175
		 Vector attributes = schema.getFields();
176
		 AttributeType[] types = new AttributeType[attributes.size()];
177
		 for (int i=0 ; i<attributes.size() ; i++){
178
			 WFSAttribute attribute = (WFSAttribute)attributes.get(i);
179
			 AttributeType type = AttributeTypeFactory.newAttributeType(attribute.getName(),
180
					 WFSFilter.getAttributeJavaType(attribute));
181
			 types[i] = type;
182
		 }
183
		 return types;
184
	 }
185
	 
186
	
187
}
0 188

  
trunk/extensions/extWFS2/src/com/iver/cit/gvsig/fmap/layers/FLyrWFS.java
2 2

  
3 3
import java.awt.geom.Rectangle2D;
4 4
import java.io.IOException;
5
import java.net.MalformedURLException;
6 5
import java.net.URL;
7 6

  
8 7
import org.gvsig.remoteClient.wfs.WFSAttribute;
......
14 13
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver;
15 14
import com.iver.cit.gvsig.fmap.drivers.WFSException;
16 15
import com.iver.cit.gvsig.fmap.drivers.wfs.FMapWFSDriver;
17
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy;
18
import com.iver.cit.gvsig.fmap.operations.strategies.WFSStrategy;
19 16
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
20 17

  
21 18
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
......
62 59
 *
63 60
 * $Id$
64 61
 * $Log$
65
 * Revision 1.4  2006-06-05 16:49:31  caballero
62
 * Revision 1.5  2006-06-14 07:57:19  jorpiell
63
 * Ya no se usa la estrategia ni se usa geotools para hacer el getFeature. Ahora se usa ?nicamente para el parseo de GML
64
 *
65
 * Revision 1.4  2006/06/05 16:49:31  caballero
66 66
 * poder editar y exportar
67 67
 *
68 68
 * Revision 1.3  2006/05/25 10:31:55  jorpiell
......
93 93
    private int timeout = 10000;
94 94
    private FMapWFSDriver wfsDriver = null;
95 95
    private VectorialAdapter vectorialAdapter = null;
96
    private WFSStrategy wfsStrategy = null;
97

  
98

  
96
    
99 97
    /**
100 98
     * Constructor
101 99
     */
......
280 278
	}
281 279

  
282 280

  
283
//    /**
284
//     * @return wfsStrategy
285
//     */
281
	/*
282
	 *  (non-Javadoc)
283
	 * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#getStrategy()
284
	 */
286 285
//    public Strategy getStrategy() {
287 286
//        if (wfsStrategy == null){
288 287
//        	wfsStrategy = new WFSStrategy(this);

Also available in: Unified diff