Revision 10626 trunk/extensions/extWFS2/src/com/iver/cit/gvsig/fmap/drivers/wfs/FMapWFSDriver.java

View differences:

FMapWFSDriver.java
16 16
import org.gvsig.remoteClient.wfs.WFSProtocolHandler.ServiceInformation;
17 17
import org.gvsig.remoteClient.wms.ICancellable;
18 18

  
19
import com.hardcode.gdbms.driver.exceptions.InitializeDriverException;
20
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
19 21
import com.hardcode.gdbms.engine.data.DataSourceFactory;
20 22
import com.hardcode.gdbms.engine.data.driver.ObjectDriver;
21 23
import com.hardcode.gdbms.engine.data.edition.DataWare;
22 24
import com.hardcode.gdbms.engine.values.Value;
23
import com.iver.cit.gvsig.fmap.DriverException;
25
import com.iver.cit.gvsig.exceptions.layers.ConnectionErrorLayerException;
26
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException;
27
import com.iver.cit.gvsig.exceptions.layers.UnsupportedVersionLayerException;
24 28
import com.iver.cit.gvsig.fmap.core.FShape;
25 29
import com.iver.cit.gvsig.fmap.core.IFeature;
26 30
import com.iver.cit.gvsig.fmap.core.IGeometry;
27 31
import com.iver.cit.gvsig.fmap.drivers.BoundedShapes;
28 32
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes;
29 33
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator;
30
import com.iver.cit.gvsig.fmap.drivers.UnsupportedVersionException;
31 34
import com.iver.cit.gvsig.fmap.drivers.WFSDriver;
32
import com.iver.cit.gvsig.fmap.drivers.WFSException;
35
import com.iver.cit.gvsig.fmap.drivers.WFSLayerException;
33 36
import com.iver.cit.gvsig.fmap.drivers.gml.GMLDriver;
34 37
import com.iver.cit.gvsig.fmap.drivers.gml.FMAPGeometryFactory.FeatureWithAttributes;
35 38
import com.iver.cit.gvsig.fmap.layers.WFSLayerNode;
......
78 81
 *
79 82
 * $Id$
80 83
 * $Log$
81
 * Revision 1.24  2007-02-09 14:12:38  jorpiell
84
 * Revision 1.25  2007-03-06 16:54:14  caballero
85
 * Exceptions
86
 *
87
 * Revision 1.24  2007/02/09 14:12:38  jorpiell
82 88
 * Soporte para WFS 1.1 y WFS-T
83 89
 *
84 90
 * Revision 1.23  2006/12/26 09:18:52  ppiqueras
......
162 168
    private DriverAttributes fields = new DriverAttributes();
163 169
    private GMLDriver driver = null;
164 170
    private boolean hasGeometry = false;
165
          
171

  
166 172
	FMapWFSDriver() {
167 173
		super();
168 174
	}
......
172 178
	 * @see com.iver.cit.gvsig.fmap.drivers.WFSDriver#getCapabilities(java.net.URL)
173 179
	 */
174 180
	public void getCapabilities(URL server)
175
		throws WFSException {
176
			try {
177
				getClient(server).connect(null);
178
			} catch (Exception e) {
179
				throw new WFSException(e);
180
			}
181
		throws LoadLayerException {
182
				try {
183
					getClient(server).connect(null);
184
				} catch (ConnectException e) {
185
					throw new ConnectionErrorLayerException(getName(),e);
186
				} catch (IOException e) {
187
					throw new ConnectionErrorLayerException(getName(),e);
188
				}
181 189
	}
182 190

  
183 191
	 /*
184 192
     *  (non-Javadoc)
185 193
     * @see com.iver.cit.gvsig.fmap.drivers.WFSDriver#describeFeatureType(java.lang.String)
186 194
     */
187
	public void describeFeatureType(String featureType,String nameSpace) throws WFSException {
195
	public void describeFeatureType(String featureType,String nameSpace) {
188 196
		remoteServicesClient.describeFeatureType(new WFSStatus(featureType,nameSpace));
189 197
	}
190 198

  
......
192 200
	 *  (non-Javadoc)
193 201
	 * @see com.iver.cit.gvsig.fmap.drivers.WFSDriver#getFeature(org.gvsig.remoteClient.wfs.WFSStatus)
194 202
	 */
195
	public void getFeature(WFSStatus wfsStatus) throws WFSException {
203
	public void getFeature(WFSStatus wfsStatus) throws WFSLayerException {
196 204
		File file = remoteServicesClient.getFeature(wfsStatus);
205
		driver = new GMLDriver();
206
		driver.open(file);
197 207
		try {
198
			driver = new GMLDriver();
199
			driver.open(file);
200
			driver.initialize();	
201
			hasGeometry = WFSUtils.getHasGeometry(featuresList,wfsStatus);
202
		} catch (Exception e) {
203
			Logger.getLogger(getClass().getName()).error(e.getMessage());
204
			throw new WFSException(e);
208
			driver.initialize();
209
		} catch (InitializeDriverException e) {
210
			throw new WFSLayerException(getName(),e);
205 211
		}
212
		hasGeometry = WFSUtils.getHasGeometry(featuresList,wfsStatus);
206 213
	}
207 214

  
208 215
	/*
......
217 224
	 *  (non-Javadoc)
218 225
	 * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getShapeCount()
219 226
	 */
220
	public int getShapeCount() throws IOException {
227
	public int getShapeCount(){
221 228
		return getNumReg();
222 229
	}
223 230

  
......
233 240
	 *  (non-Javadoc)
234 241
	 * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getFullExtent()
235 242
	 */
236
	public Rectangle2D getFullExtent() throws IOException {
243
	public Rectangle2D getFullExtent() throws ReadDriverException{
237 244
		return driver.getFullExtent();
238 245
	}
239 246

  
......
241 248
	 *  (non-Javadoc)
242 249
	 * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getShape(int)
243 250
	 */
244
	public IGeometry getShape(int index) throws IOException {
251
	public IGeometry getShape(int index) {
245 252
		return ((FeatureWithAttributes) getFeatures().get(index)).getFeature().getGeometry();
246 253
	}
247 254

  
......
264 271
	 * @throws IOException
265 272
	 * @throws ConnectException
266 273
	 *
267
	 * @throws UnsupportedVersionException
274
	 * @throws UnsupportedVersionLayerException
268 275
	 * @throws IOException
269 276
	 */
270 277
	public WFSClient getClient(URL url) throws ConnectException, IOException {
......
294 301
	 * </p>
295 302
	 * @throws IOException, DriverException.
296 303
	 */
297
	public boolean connect(boolean override,ICancellable cancel) throws IOException, DriverException {
304
	public boolean connect(boolean override,ICancellable cancel) {
298 305
		return remoteServicesClient.connect(override,cancel);
299 306
	}
300 307

  
......
347 354
	 */
348 355
	public WFSLayerNode getLayerInfo(String layerName,String nameSpace){
349 356
		WFSLayerNode lyr = (WFSLayerNode)hashFeatures.get(layerName);
350
		try {
351
			describeFeatureType(layerName,nameSpace);
352
			WFSFeature feature = (WFSFeature) remoteServicesClient.getFeatures().get(layerName);
353
			lyr.setFields(feature.getFields());
354
		} catch (WFSException e) {
355
			// The feature doesn't has fields
356
			e.printStackTrace();
357
		}		
357
		describeFeatureType(layerName,nameSpace);
358
		WFSFeature feature = (WFSFeature) remoteServicesClient.getFeatures().get(layerName);
359
		lyr.setFields(feature.getFields());
358 360
		return lyr;
359 361
	}
360 362

  
......
457 459
	 *  (non-Javadoc)
458 460
	 * @see com.iver.cit.gvsig.fmap.drivers.WFSDriver#open()
459 461
	 */
460
	public void open() throws DriverException {
462
	public void open() {
461 463
		fields.setLoadedInMemory(true);
462 464

  
463 465
	}
......
466 468
	 *  (non-Javadoc)
467 469
	 * @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#getPrimaryKeys()
468 470
	 */
469
	public int[] getPrimaryKeys() throws com.hardcode.gdbms.engine.data.driver.DriverException {
471
	public int[] getPrimaryKeys() {
470 472
		throw new UnsupportedOperationException();
471 473
	}
472 474

  
......
474 476
	 *  (non-Javadoc)
475 477
	 * @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#write(com.hardcode.gdbms.engine.data.edition.DataWare)
476 478
	 */
477
	public void write(DataWare dataWare) throws com.hardcode.gdbms.engine.data.driver.DriverException {
479
	public void write(DataWare dataWare) {
478 480
		// TODO Auto-generated method stub
479 481

  
480 482
	}
......
492 494
	 *  (non-Javadoc)
493 495
	 * @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldValue(long, int)
494 496
	 */
495
	public Value getFieldValue(long rowIndex, int fieldId) throws com.hardcode.gdbms.engine.data.driver.DriverException {
497
	public Value getFieldValue(long rowIndex, int fieldId) {
496 498
		FeatureWithAttributes feature = (FeatureWithAttributes)getFeatures().get((int)rowIndex);
497 499
		return feature.getFeature().getAttribute(fieldId);
498 500
	}
......
501 503
	 *  (non-Javadoc)
502 504
	 * @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldCount()
503 505
	 */
504
	public int getFieldCount() throws com.hardcode.gdbms.engine.data.driver.DriverException {
506
	public int getFieldCount(){
505 507
		return getNumField();
506 508
	}
507 509

  
......
509 511
	 *  (non-Javadoc)
510 512
	 * @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldName(int)
511 513
	 */
512
	public String getFieldName(int fieldId) throws com.hardcode.gdbms.engine.data.driver.DriverException {
514
	public String getFieldName(int fieldId) throws ReadDriverException{
513 515
		return driver.getFieldName(fieldId);
514 516
	}
515 517

  
......
517 519
	 *  (non-Javadoc)
518 520
	 * @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getRowCount()
519 521
	 */
520
	public long getRowCount() throws com.hardcode.gdbms.engine.data.driver.DriverException {
522
	public long getRowCount(){
521 523
		return getNumReg();
522 524
	}
523 525

  
......
525 527
	 *  (non-Javadoc)
526 528
	 * @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldType(int)
527 529
	 */
528
	public int getFieldType(int i) throws com.hardcode.gdbms.engine.data.driver.DriverException {
530
	public int getFieldType(int i) {
529 531
		return ((Value)driver.getAttributeValue(i)).getSQLType();
530 532
	}
531 533

  
......
533 535
	 *  (non-Javadoc)
534 536
	 * @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldWidth(int)
535 537
	 */
536
	public int getFieldWidth(int i) throws com.hardcode.gdbms.engine.data.driver.DriverException {
538
	public int getFieldWidth(int i) {
537 539
		// TODO Auto-generated method stub
538 540
		return 100;
539 541
	}
......
542 544
	 *  (non-Javadoc)
543 545
	 * @see com.iver.cit.gvsig.fmap.drivers.WFSDriver#getFeatureIterator(java.awt.geom.Rectangle2D, java.lang.String)
544 546
	 */
545
	public IFeatureIterator getFeatureIterator(Rectangle2D r, String strEPSG) throws DriverException, IOException {
547
	public IFeatureIterator getFeatureIterator(Rectangle2D r, String strEPSG) {
546 548
		return new WFSFeaturesIterator(driver.getIterator(),strEPSG);
547 549
	}
548 550

  
......
570 572
	 *  (non-Javadoc)
571 573
	 * @see com.iver.cit.gvsig.fmap.drivers.BoundedShapes#getShapeBounds(int)
572 574
	 */
573
	public Rectangle2D getShapeBounds(int index) throws IOException {
575
	public Rectangle2D getShapeBounds(int index) throws ReadDriverException {
574 576
		return getShape(index).getBounds2D();
575 577
	}
576 578

  
......
579 581
	 * @see com.iver.cit.gvsig.fmap.drivers.BoundedShapes#getShapeType(int)
580 582
	 */
581 583
	public int getShapeType(int index) {
582
		try {
583
			if (getShapeCount() > 0){
584
				return getShape(0).getGeometryType();
585
			}
586

  
587
		} catch (IOException e) {
588
			e.printStackTrace();
584
		if (getShapeCount() > 0){
585
			return getShape(0).getGeometryType();
589 586
		}
587

  
590 588
		return FShape.MULTI;
591 589
	}
592 590

  
......
594 592
	 *  (non-Javadoc)
595 593
	 * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#reload()
596 594
	 */
597
	public void reload() throws IOException, com.hardcode.gdbms.engine.data.driver.DriverException {
598
		
595
	public void reload(){
596

  
599 597
	}
600 598

  
601 599

  

Also available in: Unified diff