Revision 5293

View differences:

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
import java.awt.geom.Rectangle2D;
3 4
import java.io.IOException;
4 5
import java.net.ConnectException;
5 6
import java.net.URL;
7
import java.util.ArrayList;
6 8
import java.util.Hashtable;
7 9
import java.util.Iterator;
8
import java.util.Set;
9
import java.util.Vector;
10 10

  
11
import org.geotools.feature.AttributeType;
11 12
import org.gvsig.remoteClient.wfs.WFSClient;
12 13
import org.gvsig.remoteClient.wfs.WFSFeature;
14
import org.gvsig.remoteClient.wfs.WFSStatus;
13 15
import org.gvsig.remoteClient.wfs.WFSProtocolHandler.ServiceInformation;
14 16

  
17
import com.hardcode.gdbms.engine.data.DataSourceFactory;
18
import com.hardcode.gdbms.engine.data.driver.ObjectDriver;
19
import com.hardcode.gdbms.engine.data.edition.DataWare;
20
import com.hardcode.gdbms.engine.values.Value;
15 21
import com.iver.cit.gvsig.fmap.DriverException;
22
import com.iver.cit.gvsig.fmap.core.FShape;
23
import com.iver.cit.gvsig.fmap.core.IFeature;
24
import com.iver.cit.gvsig.fmap.core.IGeometry;
25
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes;
26
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator;
16 27
import com.iver.cit.gvsig.fmap.drivers.UnsupportedVersionException;
17 28
import com.iver.cit.gvsig.fmap.drivers.WFSDriver;
18 29
import com.iver.cit.gvsig.fmap.drivers.WFSException;
30
import com.iver.cit.gvsig.fmap.drivers.geotools.WFSFeaturesIterator;
31
import com.iver.cit.gvsig.fmap.drivers.geotools.WFSGeotoolsDriver;
19 32
import com.iver.cit.gvsig.fmap.layers.WFSLayerNode;
20 33

  
21 34
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
......
62 75
 *
63 76
 * $Id$
64 77
 * $Log$
65
 * Revision 1.2  2006-04-20 16:38:24  jorpiell
78
 * Revision 1.3  2006-05-19 12:53:54  jorpiell
79
 * Se le ha a?adido un driver de geottols, por lo que tiene dos drivers. Para hacer el getFeatureInfo y el capablities utilizar? elremoteServices y para hacer el getFeature usar? el de geotools.
80
 *
81
 * Revision 1.2  2006/04/20 16:38:24  jorpiell
66 82
 * Ahora mismo ya se puede hacer un getCapabilities y un getDescribeType de la capa seleccionada para ver los atributos a dibujar. Queda implementar el panel de opciones y hacer el getFeature().
67 83
 *
68 84
 * Revision 1.1  2006/04/19 12:50:16  jorpiell
......
73 89
/**
74 90
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
75 91
 */
76
public class FMapWFSDriver implements WFSDriver{
77
	private WFSClient client;
92
public class FMapWFSDriver implements WFSDriver,ObjectDriver{
93
	private WFSClient remoteServicesClient;
94
	private WFSGeotoolsDriver geotoolsClient;
78 95
    private WFSLayerNode[] featuresList;
79
    private Hashtable features; 
80
	
96
    private Hashtable hashFeatures;  
97
        
98
   private int idFID_FieldName;
99
	private int numField = -1;
100
	//private AttributeType[] attributes;
101
    private String strOriginalSRID;
102

  
103
	public FMapWFSDriver() {
104
		super();
105
	}
106

  
81 107
	/*
82 108
	 *  (non-Javadoc)
83 109
	 * @see com.iver.cit.gvsig.fmap.drivers.WFSDriver#getCapabilities(java.net.URL)
......
90 116
				throw new WFSException(e);
91 117
			}		
92 118
	}	
119
	
120
	 /*
121
     *  (non-Javadoc)
122
     * @see com.iver.cit.gvsig.fmap.drivers.WFSDriver#describeFeatureType(java.lang.String)
123
     */
124
	public void describeFeatureType(String featureType) throws WFSException {
125
		remoteServicesClient.describeFeatureType(new WFSStatus(featureType));				
126
	}
127
	
128
	/*
129
	 *  (non-Javadoc)
130
	 * @see com.iver.cit.gvsig.fmap.drivers.WFSDriver#getFeature(org.gvsig.remoteClient.wfs.WFSStatus)
131
	 */
132
	public void getFeature(WFSStatus wfsStatus) throws WFSException {
133
		//Using remoteServices
134
		//return remoteServicesClient.getFeature(wfsStatus);
135
		//Using geotools
136
		if (geotoolsClient == null){
137
			try {
138
				geotoolsClient = new WFSGeotoolsDriver(remoteServicesClient.getHost());
139
			} catch (ConnectException e) {
140
				// TODO Auto-generated catch block
141
				e.printStackTrace();
142
				throw new WFSException();
143
			}
144
		}
145
		WFSFeaturesIterator iterator = (WFSFeaturesIterator)geotoolsClient.getFeature(wfsStatus);
146
		geotoolsClient.setFeatures(iterator);		
147
	}	
148
	
149
	/*
150
	 *  (non-Javadoc)
151
	 * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getShapeType()
152
	 */
153
	public int getShapeType() {
154
		return FShape.MULTI;
155
	}
156

  
157
	/*
158
	 *  (non-Javadoc)
159
	 * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getShapeCount()
160
	 */
161
	public int getShapeCount() throws IOException {
162
		return getNumReg();
163
	}
164

  
165
	/*
166
	 *  (non-Javadoc)
167
	 * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getDriverAttributes()
168
	 */
169
	public DriverAttributes getDriverAttributes() {
170
		// TODO Auto-generated method stub
171
		return null;
172
	}
173

  
174
	/*
175
	 *  (non-Javadoc)
176
	 * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getFullExtent()
177
	 */
178
	public Rectangle2D getFullExtent() throws IOException {
179
		return geotoolsClient.getFullExtent();
180
	}
181

  
182
	/*
183
	 *  (non-Javadoc)
184
	 * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getShape(int)
185
	 */
186
	public IGeometry getShape(int index) throws IOException {
187
		return ((IFeature) getFeatures().get(index)).getGeometry();
188
	}
189

  
190
	/*
191
	 *  (non-Javadoc)
192
	 * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#reLoad()
193
	 */
194
	public void reLoad() throws IOException {
195
		geotoolsClient.getFeature(null);
196
	}
197

  
198
	/*
199
	 *  (non-Javadoc)
200
	 * @see com.hardcode.driverManager.Driver#getName()
201
	 */
202
	public String getName() {
203
		return "WFS Driver";
204
	}
93 205
    
206
    
207
    
94 208
	/**
95 209
	 * Devuelve WFSClient a partir de su URL.
96 210
	 *
......
104 218
	 * @throws IOException
105 219
	 */
106 220
	public WFSClient getClient(URL url) throws ConnectException, IOException {
107
		if (client == null) {
108
			client = new WFSClient(url.toString());
221
		if (remoteServicesClient == null) {
222
			remoteServicesClient = new WFSClient(url.toString());
109 223
		}
110
		return client;
224
		return remoteServicesClient;
111 225
	}
112 226
	
113 227
	/**
......
118 232
	 * @throws ConnectException 
119 233
     */
120 234
    public void createClient(URL host) throws ConnectException, IOException {
121
        client = new WFSClient(host.toString());
235
        remoteServicesClient = new WFSClient(host.toString());
122 236
    }
123 237
    
124 238
    /**
......
131 245
	 * @throws IOException, DriverException.
132 246
	 */
133 247
	public boolean connect() throws IOException, DriverException {
134
		return client.connect();
248
		return remoteServicesClient.connect();
135 249
	}
136 250
	
137 251
	/**
......
140 254
	 * @return WFSLayerNode[]
141 255
	 */
142 256
	public WFSLayerNode[] getLayerList(){
143
		if (features == null) {
144
			features = new Hashtable();
145
			Hashtable wfsFeatures  = client.getFeatures();
257
		if (hashFeatures == null) {
258
			hashFeatures = new Hashtable();
259
			Hashtable wfsFeatures  = remoteServicesClient.getFeatures();
146 260
				
147 261
			Iterator keys = wfsFeatures.keySet().iterator();
148 262
			featuresList = new WFSLayerNode[wfsFeatures.size()];
......
157 271
				lyr.setFields(feature.getFields());
158 272
				
159 273
				featuresList[i] = lyr;
160
				features.put(lyr.getName(), lyr);
274
				hashFeatures.put(lyr.getName(), lyr);
161 275
			}			
162 276
		}		
163 277
		return featuresList;
......
171 285
	 * @return
172 286
	 */
173 287
	public WFSLayerNode getLayerInfo(String layerName){
174
		WFSLayerNode lyr = (WFSLayerNode)features.get(layerName);
288
		WFSLayerNode lyr = (WFSLayerNode)hashFeatures.get(layerName);
175 289
		if (lyr.getFields().size() == 0){
176 290
			try {
177 291
				describeFeatureType(layerName);
178
				WFSFeature feature = (WFSFeature) client.getFeatures().get(layerName);
292
				WFSFeature feature = (WFSFeature) remoteServicesClient.getFeatures().get(layerName);
179 293
				lyr.setFields(feature.getFields());
180 294
			} catch (WFSException e) {
181 295
				// The feature doesn't has fields
......
190 304
     * @return The title of the service offered by the WMS server.
191 305
     */
192 306
    public String getServiceTitle() {
193
        return client.getServiceInformation().title;
307
        return remoteServicesClient.getServiceInformation().title;
194 308
    }
195 309
    
196 310
    /**
197 311
     * @return The abstract of the service offered by the WMS server.
198 312
     */
199 313
    public String getServiceAbstract() {
200
        return client.getServiceInformation().abstr;
314
        return remoteServicesClient.getServiceInformation().abstr;
201 315
    }
202 316
    
203 317
    /**
......
208 322
     */
209 323
    public Hashtable getOnlineResources() {
210 324
    	Hashtable onlineResources = new Hashtable();
211
    	ServiceInformation si = client.getServiceInformation();
325
    	ServiceInformation si = remoteServicesClient.getServiceInformation();
212 326
    	Iterator it = si.operations.keySet().iterator();
213 327
    	while (it.hasNext()) {
214 328
    		String key = (String) it.next();
......
227 341
     * @return the host
228 342
     */
229 343
    public String getHost(){
230
        return client.getHost();
344
        return remoteServicesClient.getHost();
231 345
    }
232 346
    
233 347
    /**
234 348
     * @return the version of this client.
235 349
     */
236 350
    public String getVersion() {
237
        return client.getVersion();
351
        return remoteServicesClient.getVersion();
238 352
    }
239 353

  
240
    /*
241
     *  (non-Javadoc)
242
     * @see com.iver.cit.gvsig.fmap.drivers.WFSDriver#describeFeatureType(java.lang.String)
243
     */
244
	public void describeFeatureType(String featureType) throws WFSException {
245
		client.describeFeatureType(null,featureType);				
354
	/**
355
	 * @return Returns the features.
356
	 */
357
	public ArrayList getFeatures() {
358
		return geotoolsClient.getFeatures();
246 359
	}
360

  
361
	/**
362
	 * @return Returns the hashRelate.
363
	 */
364
	public Hashtable getHashRelate() {
365
		return geotoolsClient.getHashRelate();
366
	}
247 367
	
368
    
369
 	/**
370
	 * @return Returns the numReg.
371
	 */
372
	public int getNumReg() {
373
		return geotoolsClient.getNumReg();
374
	}
248 375
	
376
 	/**
377
	 * @return Returns the numFiled.
378
	 */
379
	public int getNumField() {
380
		return geotoolsClient.getNumField();
381
	}
382
	
383
	/**
384
	 * @return Returns the attributes.
385
	 */
386
	public AttributeType[] getAttributes() {
387
		return geotoolsClient.getAttributes();
388
	}
389

  
390
	/*
391
	 *  (non-Javadoc)
392
	 * @see com.iver.cit.gvsig.fmap.drivers.WFSDriver#close()
393
	 */
394
	public void close() {
395
		// TODO Auto-generated method stub
396
		
397
	}
398

  
399
	/*
400
	 *  (non-Javadoc)
401
	 * @see com.iver.cit.gvsig.fmap.drivers.WFSDriver#open()
402
	 */	
403
	public void open() throws DriverException {
404
		// TODO Auto-generated method stub
405
		
406
	}
407

  
408
	/*
409
	 *  (non-Javadoc)
410
	 * @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#getPrimaryKeys()
411
	 */
412
	public int[] getPrimaryKeys() throws com.hardcode.gdbms.engine.data.driver.DriverException {
413
		throw new UnsupportedOperationException();
414
	}
415

  
416
	/*
417
	 *  (non-Javadoc)
418
	 * @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#write(com.hardcode.gdbms.engine.data.edition.DataWare)
419
	 */
420
	public void write(DataWare dataWare) throws com.hardcode.gdbms.engine.data.driver.DriverException {
421
		// TODO Auto-generated method stub
422
		
423
	}
424
	
425
	/*
426
	 *  (non-Javadoc)
427
	 * @see com.hardcode.gdbms.engine.data.driver.GDBMSDriver#setDataSourceFactory(com.hardcode.gdbms.engine.data.DataSourceFactory)
428
	 */
429
	public void setDataSourceFactory(DataSourceFactory dsf) {
430
		// TODO Auto-generated method stub
431
		
432
	}
433

  
434
	/*
435
	 *  (non-Javadoc)
436
	 * @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldValue(long, int)
437
	 */
438
	public Value getFieldValue(long rowIndex, int fieldId) throws com.hardcode.gdbms.engine.data.driver.DriverException {
439
		return ((IFeature) getFeatures().get((int) rowIndex)).getAttribute(fieldId);
440
	}
441

  
442
	/*
443
	 *  (non-Javadoc)
444
	 * @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldCount()
445
	 */
446
	public int getFieldCount() throws com.hardcode.gdbms.engine.data.driver.DriverException {
447
		return getNumField();
448
	}
449

  
450
	/*
451
	 *  (non-Javadoc)
452
	 * @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldName(int)
453
	 */
454
	public String getFieldName(int fieldId) throws com.hardcode.gdbms.engine.data.driver.DriverException {
455
		return getAttributes()[fieldId].getName();
456
	}
457

  
458
	/*
459
	 *  (non-Javadoc)
460
	 * @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getRowCount()
461
	 */
462
	public long getRowCount() throws com.hardcode.gdbms.engine.data.driver.DriverException {
463
		return getNumReg();
464
	}
465

  
466
	/*
467
	 *  (non-Javadoc)
468
	 * @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldType(int)
469
	 */
470
	public int getFieldType(int i) throws com.hardcode.gdbms.engine.data.driver.DriverException {
471
		getAttributes()[i].getType();
472

  
473
		return FIELD_TYPE_STRING; 
474
	}
475

  
476
	/*
477
	 *  (non-Javadoc)
478
	 * @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldWidth(int)
479
	 */
480
	public int getFieldWidth(int i) throws com.hardcode.gdbms.engine.data.driver.DriverException {
481
		// TODO Auto-generated method stub
482
		return 0;
483
	}
484

  
485
	/*
486
	 *  (non-Javadoc)
487
	 * @see com.iver.cit.gvsig.fmap.drivers.WFSDriver#getFeatureIterator(java.awt.geom.Rectangle2D, java.lang.String)
488
	 */
489
	public IFeatureIterator getFeatureIterator(Rectangle2D r, String strEPSG) throws DriverException, IOException {
490
		return geotoolsClient.getIterator();
491
	}
492

  
493
	/*
494
	 *  (non-Javadoc)
495
	 * @see com.iver.cit.gvsig.fmap.drivers.WFSDriver#getRowIndexByFID(com.iver.cit.gvsig.fmap.core.IFeature)
496
	 */
497
	public int getRowIndexByFID(IFeature FID) {
498
		int resul;
499
		Integer rowIndex = (Integer) getHashRelate().get(FID.getID());
500
		resul = rowIndex.intValue();
501
		return resul;
502
	}
503
	
249 504
}

Also available in: Unified diff