Revision 10627 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/FLyrVect.java

View differences:

FLyrVect.java
48 48
import java.awt.geom.Rectangle2D;
49 49
import java.awt.image.BufferedImage;
50 50
import java.io.File;
51
import java.io.IOException;
52 51

  
53 52
import javax.print.attribute.PrintRequestAttributeSet;
54 53

  
......
56 55
import org.cresques.cts.ICoordTrans;
57 56

  
58 57
import com.hardcode.driverManager.DriverLoadException;
58
import com.hardcode.gdbms.driver.exceptions.InitializeDriverException;
59
import com.hardcode.gdbms.driver.exceptions.OpenDriverException;
60
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
61
import com.hardcode.gdbms.driver.exceptions.ReloadDriverException;
59 62
import com.hardcode.gdbms.engine.data.DataSourceFactory;
60 63
import com.hardcode.gdbms.engine.data.NoSuchTableException;
64
import com.hardcode.gdbms.engine.data.driver.DriverException;
61 65
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException;
62
import com.iver.cit.gvsig.fmap.DriverException;
63
import com.iver.cit.gvsig.fmap.DriverNotLoadedExceptionType;
66
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException;
67
import com.iver.cit.gvsig.exceptions.layers.LegendLayerException;
68
import com.iver.cit.gvsig.exceptions.layers.ReloadLayerException;
69
import com.iver.cit.gvsig.exceptions.layers.StartEditionLayerException;
70
import com.iver.cit.gvsig.exceptions.visitors.StartWriterVisitorException;
71
import com.iver.cit.gvsig.exceptions.visitors.VisitorException;
64 72
import com.iver.cit.gvsig.fmap.ViewPort;
65 73
import com.iver.cit.gvsig.fmap.core.IGeometry;
66 74
import com.iver.cit.gvsig.fmap.core.IPrintable;
67 75
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
68 76
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
69 77
import com.iver.cit.gvsig.fmap.drivers.BoundedShapes;
70
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
71 78
import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver;
72 79
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver;
73 80
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend;
74 81
import com.iver.cit.gvsig.fmap.drivers.shp.IndexedShpDriver;
75 82
import com.iver.cit.gvsig.fmap.edition.AnnotationEditableAdapter;
76 83
import com.iver.cit.gvsig.fmap.edition.EditionEvent;
77
import com.iver.cit.gvsig.fmap.edition.EditionException;
78 84
import com.iver.cit.gvsig.fmap.edition.ISpatialWriter;
79 85
import com.iver.cit.gvsig.fmap.edition.IWriteable;
80 86
import com.iver.cit.gvsig.fmap.edition.IWriter;
......
92 98
import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor;
93 99
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy;
94 100
import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager;
95
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException;
96 101
import com.iver.cit.gvsig.fmap.rendering.ClassifiedLegendInfo;
97 102
import com.iver.cit.gvsig.fmap.rendering.Legend;
98 103
import com.iver.cit.gvsig.fmap.rendering.LegendChangedEvent;
......
242 247
			spatialIndex = null;
243 248
			e.printStackTrace();
244 249
			return;
245
		} catch (DriverIOException e) {
246
			// TODO Auto-generated catch block
250
		} catch (ReadDriverException e) {
251
			spatialIndex = null;
247 252
			e.printStackTrace();
253
			return;
254
		} catch (ExpansionFileReadException e) {
255
			spatialIndex = null;
256
			e.printStackTrace();
257
			return;
248 258
		}
249 259

  
250 260
	}
......
301 311
	}
302 312

  
303 313
	/**
314
	 * @throws ReadDriverException
315
	 * @throws ExpansionFileReadException
304 316
	 * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#getFullExtent()
305 317
	 */
306
	public Rectangle2D getFullExtent() throws DriverException {
307
		try {
318
	public Rectangle2D getFullExtent() throws ReadDriverException, ExpansionFileReadException {
308 319
			Rectangle2D rAux;
309 320
//			logger.debug(getName() + "_source.start()");
310 321
			source.start();
......
330 341
			}
331 342

  
332 343
			return rAux;
333
		} catch (DriverIOException e) {
334
			throw new DriverException(e);
335
		}
336 344
	}
337 345

  
338 346
	/**
......
340 348
	 *      java.awt.Graphics2D, ISymbol)
341 349
	 */
342 350
	public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
343
			Cancellable cancel, double scale) throws DriverException {
351
			Cancellable cancel, double scale) throws ReadDriverException {
344 352

  
345 353
		if (isWithinScale(scale)) {
346 354
			// Las que solo tienen etiquetado sin pintar el shape,
......
355 363
				try {
356 364
					prepareDrawing(image, g, viewPort);
357 365
					strategy.draw(image, g, viewPort, cancel);
358
				} catch (DriverException e) {
366
				} catch (ReadDriverException e) {
359 367
					this.setVisible(false);
360 368
					this.setActive(false);
361 369
					throw e;
......
388 396
	 *      com.iver.utiles.swing.threads.Cancellable)
389 397
	 */
390 398
	public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
391
			double scale, PrintRequestAttributeSet properties) throws DriverException {
399
			double scale, PrintRequestAttributeSet properties) throws ReadDriverException {
392 400
		if (isVisible() && isWithinScale(scale)) {
393 401
			Strategy strategy = StrategyManager.getStrategy(this);
394 402

  
......
401 409
	}
402 410

  
403 411
	/**
412
	 * @throws ReadDriverException
404 413
	 * @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#createLabelLayer(int)
405 414
	 */
406 415
	// public FLayer createLabelLayer(int fieldId) {
407
	public FLayer createLabelLayer(SelectableDataSource ds) {
416
	public FLayer createLabelLayer(SelectableDataSource ds) throws ReadDriverException {
408 417
		FLyrText layerText = null;
409
		try {
410
			layerText = new FLyrText();
411
			layerText.setLegend((VectorialLegend) getLegend());
412
			layerText.createLabels(this);
413
		} catch (FieldNotFoundException e1) {
414
			// TODO Auto-generated catch block
415
			e1.printStackTrace();
416
		} catch (DriverException e1) {
417
			// TODO Auto-generated catch block
418
			e1.printStackTrace();
419
		}
418
		layerText = new FLyrText();
419
		layerText.setLegend((VectorialLegend) getLegend());
420
		layerText.createLabels(this);
420 421

  
421 422
		setLayerText(layerText);
422 423
		layerText.setCoordTrans(getCoordTrans());
......
489 490
				// if we cant build a file based spatial index, we'll build
490 491
				// a pure memory spatial index
491 492
				localCopy = new QuadtreeJts();
492
			} catch (DriverIOException e) {
493
				// TODO Auto-generated catch block
494
				e.printStackTrace();
493
			} catch (ReadDriverException e) {
494
				localCopy = new QuadtreeJts();
495
			} catch (ExpansionFileReadException e) {
496
				localCopy = new QuadtreeJts();
495 497
			}
496 498

  
497 499
		}catch(Exception e){
......
514 516
            if(localCopy instanceof IPersistentSpatialIndex)
515 517
            	((IPersistentSpatialIndex) localCopy).flush();
516 518
            spatialIndex = localCopy;
517
        } catch (DriverIOException e) {
518
            // TODO Auto-generated catch block
519
            e.printStackTrace();
520
        } catch (IOException e) {
521
            // TODO Auto-generated catch block
522
            e.printStackTrace();
523
        }
519
        } catch (ReadDriverException e) {
520
			// TODO Auto-generated catch block
521
			e.printStackTrace();
522
		} catch (ExpansionFileReadException e) {
523
			// TODO Auto-generated catch block
524
			e.printStackTrace();
525
		}
524 526
    }
525 527

  
526 528
	/**
......
531 533
	}
532 534

  
533 535
	/**
536
	 * @throws ExpansionFileReadException
534 537
	 * @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor,
535 538
	 *      FBitSet)
536 539
	 */
537 540
	public void process(FeatureVisitor visitor, FBitSet subset)
538
			throws DriverException, VisitException {
541
			throws ReadDriverException, ExpansionFileReadException, VisitorException {
539 542
		Strategy s = StrategyManager.getStrategy(this);
540 543
		s.process(visitor, subset);
541 544
	}
......
543 546
	/**
544 547
	 * @see com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor)
545 548
	 */
546
	public void process(FeatureVisitor visitor) throws DriverException,
547
			VisitException {
549
	public void process(FeatureVisitor visitor) throws ReadDriverException, VisitorException {
548 550
		Strategy s = StrategyManager.getStrategy(this);
549 551
		s.process(visitor);
550 552
	}
551 553

  
552 554
	/**
555
	 * @throws ExpansionFileReadException
553 556
	 * @see com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor,
554 557
	 *      Rectangle2D)
555 558
	 */
556 559
	public void process(FeatureVisitor visitor, Rectangle2D rect)
557
			throws DriverException, VisitException {
560
			throws ReadDriverException, ExpansionFileReadException, VisitorException {
558 561
		Strategy s = StrategyManager.getStrategy(this);
559 562
		s.process(visitor, rect);
560 563
	}
......
598 601
	 *
599 602
	 * @see com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData#queryByRect(java.awt.geom.Rectangle2D)
600 603
	 */
601
	public FBitSet queryByRect(Rectangle2D rect) throws DriverException {
604
	public FBitSet queryByRect(Rectangle2D rect) throws ReadDriverException, VisitorException {
602 605
		Strategy s = StrategyManager.getStrategy(this);
603 606

  
604 607
		return s.queryByRect(rect);
605 608
	}
606 609

  
607 610
	public FBitSet queryByPoint(Point2D p, double tolerance)
608
			throws DriverException {
611
			throws ReadDriverException, VisitorException {
609 612
		Strategy s = StrategyManager.getStrategy(this);
610 613
		return s.queryByPoint(p, tolerance);
611 614
	}
612 615

  
613 616
	public FBitSet queryByShape(IGeometry g, int relationship)
614
			throws DriverException, VisitException {
617
			throws ReadDriverException, VisitorException {
615 618
		Strategy s = StrategyManager.getStrategy(this);
616 619
		return s.queryByShape(g, relationship);
617 620
	}
618 621

  
619
	public XMLItem[] getInfo(Point p, double tolerance, Cancellable cancel) throws DriverException {
622
	public XMLItem[] getInfo(Point p, double tolerance, Cancellable cancel) throws ReadDriverException, VisitorException {
620 623
		Point2D pReal = this.getMapContext().getViewPort().toMapPoint(p);
621 624
		FBitSet bs = queryByPoint(pReal, tolerance);
622 625
		VectorialXMLItem[] item = new VectorialXMLItem[1];
......
659 662
	 * logger.debug("Recordset cambiado a " + sds.getName()); }
660 663
	 */
661 664
	/**
665
	 * @throws ReadDriverException
662 666
	 * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#setLegend(int,
663 667
	 *      com.iver.cit.gvsig.fmap.rendering.Legend)
664 668
	 */
665
	public void setLegend(VectorialLegend r) throws DriverException,
666
			FieldNotFoundException {
669
	public void setLegend(VectorialLegend r) throws LegendLayerException {
667 670
		VectorialLegend oldLegend = legend;
668 671
		legend = r;
669

  
670
		try {
671
			legend.setDataSource(getRecordset());
672

  
673
			if (legend.getLabelField() != null) {
672
			try {
673
				legend.setDataSource(getRecordset());
674
				if (legend.getLabelField() != null) {
674 675
				// sds.start();
675 676
				// int idLabelField =
676 677
				// getRecordset().getFieldIndexByName(legend.getLabelField());
......
678 679
				// sds.stop();
679 680
			} else
680 681
				removeLabels();
681
		} catch (DriverException e) {
682
			throw new DriverException(e);
683
		} catch (FieldNotFoundException e) {
684
			// TODO Auto-generated catch block
685
			e.printStackTrace();
686
		} catch (DriverLoadException e) {
687
			// TODO Auto-generated catch block
688
			e.printStackTrace();
689
		}
690

  
682
			} catch (FieldNotFoundException e1) {
683
				throw new LegendLayerException(getName(),e1);
684
			} catch (ReadDriverException e1) {
685
				throw new LegendLayerException(getName(),e1);
686
			}
691 687
		LegendChangedEvent e = LegendChangedEvent.createLegendChangedEvent(
692 688
				oldLegend, legend);
693 689
		callLegendChanged(e);
......
709 705
	 *
710 706
	 * @throws DriverException
711 707
	 */
712
	public int getShapeType() throws DriverException {
708
	public int getShapeType() throws ReadDriverException {
713 709
		if (typeShape == -1) {
714
			try {
710

  
715 711
//				logger.debug("source.start()");
716 712
				getSource().start();
717 713
				typeShape = getSource().getShapeType();
718 714
//				logger.debug("source.stop()");
719 715
				getSource().stop();
720
			} catch (DriverIOException e) {
721
				throw new DriverException(e);
722
			}
723 716
		}
724 717

  
725 718
		return typeShape;
......
738 731
		try {
739 732
			xml.addChild(getRecordset().getSelectionSupport().getXMLEntity());
740 733

  
741
		} catch (DriverException e1) {
734
		} catch (ReadDriverException e1) {
742 735
			e1.printStackTrace();
743 736
			throw new XMLException(e1);
744 737
		}
......
756 749
				xml.putProperty("recordset-name", getSource().getRecordset()
757 750
						.getName());
758 751
			} catch (DriverLoadException e) {
759
				// TODO Auto-generated catch block
760
				e.printStackTrace();
752
				throw new XMLException(e);
753
			} catch (ReadDriverException e) {
754
				throw new XMLException(e);
761 755
			}
762
			// } catch (DriverException e) {
763
			// throw new XMLException(e);
764
			// }
765 756
		} else if (source instanceof VectorialDBAdapter) {
766 757
			xml.putProperty("type", "vectorial");
767 758

  
......
776 767
				xml.putProperty("recordset-name", getSource().getRecordset()
777 768
						.getName());
778 769
			} catch (DriverLoadException e) {
779
				// TODO Auto-generated catch block
780
				e.printStackTrace();
770
				throw new XMLException(e);
771
			} catch (ReadDriverException e) {
772
				throw new XMLException(e);
781 773
			}
782 774
			// } catch (DriverException e) {
783 775
			// throw new XMLException(e);
......
789 781
			// Se supone que hemos hecho algo gen?rico.
790 782
			xml.putProperty("type", "vectorial");
791 783

  
792
			VectorialDriver driver = (VectorialDriver) getSource().getDriver();
784
			VectorialDriver driver = getSource().getDriver();
793 785

  
794 786
			// Guardamos el nombre del driver para poder recuperarlo
795 787
			// con el DriverManager de Fernando.
......
799 791
				xml.putProperty("recordset-name", getSource().getRecordset()
800 792
						.getName());
801 793
			} catch (DriverLoadException e) {
802
				// TODO Auto-generated catch block
803
				e.printStackTrace();
794
				throw new XMLException(e);
795
			} catch (ReadDriverException e) {
796
				throw new XMLException(e);
804 797
			}
805 798
			// } catch (DriverException e) {
806 799
			// throw new XMLException(e);
......
833 826
		try {
834 827
			// legend.setDataSource(getRecordset());
835 828
			setLegend(legend);
836
		} catch (FieldNotFoundException e) {
829
		} catch (LegendLayerException e) {
837 830
			throw new XMLException(e);
838
		} catch (DriverException e) {
839
			throw new XMLException(e);
840 831
		}
841 832

  
842 833
		try {
843 834
			getRecordset().getSelectionSupport()
844 835
					.setXMLEntity03(xml.getChild(1));
845
		} catch (DriverException e) {
836
		} catch (ReadDriverException e) {
846 837
			e.printStackTrace();
847 838
		}
848 839
	}
......
877 868
			} catch (NoSuchTableException e1) {
878 869
				this.setAvailable(false);
879 870
				throw new XMLException(e1);
880
			} catch (com.hardcode.gdbms.engine.data.driver.DriverException e1) {
871
			} catch (ReadDriverException e1) {
881 872
				this.setAvailable(false);
882 873
				throw new XMLException(e1);
883 874
			} catch (DriverLoadException e1) {
884 875
				this.setAvailable(false);
885 876
				throw new XMLException(e1);
886
			} catch (DriverException e1) {
887
				this.setAvailable(false);
888
				throw new XMLException(e1);
889 877
			}
890 878
			// Si tiene una uni?n, lo marcamos para que no se cree la leyenda hasta
891 879
			// el final
......
901 889
				try {
902 890
					// legend.setDataSource(getRecordset());
903 891
					setLegend(leg);
904
				} catch (FieldNotFoundException e) {
892
				} catch (LegendLayerException e) {
905 893
					throw new XMLException(e);
906
				} catch (DriverException e) {
907
					throw new XMLException(e);
908 894
				}
909 895
			}
910 896

  
......
957 943
			} catch (DriverLoadException e1) {
958 944
				this.setAvailable(false);
959 945
				throw new XMLException(e1);
960
			} catch (DriverException e1) {
946
			} catch (ReadDriverException e1) {
961 947
				this.setAvailable(false);
962 948
				throw new XMLException(e1);
963 949
			}
......
1112 1098
	 * @throws DriverException
1113 1099
	 * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getRecordset()
1114 1100
	 */
1115
	public SelectableDataSource getRecordset() throws DriverException {
1101
	public SelectableDataSource getRecordset() throws ReadDriverException {
1116 1102
		if (!this.isAvailable()) return null;
1117 1103
		if (sds == null) {
1118
			try {
1104
//			try {
1119 1105
				SelectableDataSource ds = source.getRecordset();
1120 1106

  
1121 1107
				if (ds == null) {
......
1125 1111
				sds = ds;
1126 1112
				sds.setSelectionSupport(selectionSupport);
1127 1113

  
1128
			} catch (DriverLoadException e) {
1129
				DriverNotLoadedExceptionType exceptionType =
1130
					new DriverNotLoadedExceptionType();
1131
				exceptionType.setDriverName(source.getDriver().getName());
1132
				throw new DriverException(e, exceptionType);
1133
			}
1114
//			} catch (DriverLoadException e) {
1115
////				DriverNotLoadedExceptionType exceptionType =
1116
////					new DriverNotLoadedExceptionType();
1117
////				exceptionType.setDriverName(source.getDriver().getName());
1118
//				throw new ReadDriverException();
1119
//			}
1134 1120
		}
1135 1121
		return sds;
1136 1122
	}
......
1140 1126
	 *
1141 1127
	 * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setEditing(boolean)
1142 1128
	 */
1143
	public void setEditing(boolean b) throws EditionException {
1129
	public void setEditing(boolean b) throws StartEditionLayerException {
1144 1130
		super.setEditing(b);
1145 1131
		try {
1146 1132
			if (b) {
......
1195 1181
				ley.useDefaultSymbol(true);
1196 1182
			}
1197 1183
		} catch (DriverLoadException e) {
1198
			e.printStackTrace();
1199
			throw new EditionException(e);
1200
		} catch (DriverException e) {
1201
			e.printStackTrace();
1202
			throw new EditionException(e);
1184
			throw new StartEditionLayerException(getName(),e);
1185
		} catch (ReadDriverException e) {
1186
			throw new StartEditionLayerException(getName(),e);
1203 1187
		} catch (FieldNotFoundException e) {
1204
			e.printStackTrace();
1205
			throw new EditionException(e);
1188
			throw new StartEditionLayerException(getName(),e);
1189
		} catch (StartWriterVisitorException e) {
1190
			throw new StartEditionLayerException(getName(),e);
1206 1191
		}
1207 1192

  
1208 1193
		setSpatialCacheEnabled(b);
......
1275 1260
		return true;
1276 1261
	}
1277 1262

  
1278
	public void reload() throws DriverIOException {
1263
	public void reload() throws ReloadLayerException {
1264
		this.setAvailable(true);
1279 1265
		super.reload();
1280 1266
		try {
1281 1267
			this.source.getDriver().reload();
......
1290 1276
	            }
1291 1277
			}
1292 1278

  
1293
		} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
1279
		} catch (LegendLayerException e) {
1294 1280
			this.setAvailable(false);
1295
			throw new DriverIOException(e);
1296
		} catch (IOException e) {
1281
			throw new ReloadLayerException(getName(),e);
1282
		} catch (ReadDriverException e) {
1297 1283
			this.setAvailable(false);
1298
			throw new DriverIOException(e);
1299
		} catch (DriverException e) {
1300
			this.setAvailable(false);
1301
			throw new DriverIOException(e);
1302
		} catch (Exception e) {
1303
			this.setAvailable(false);
1304
			throw new DriverIOException(e);
1284
			throw new ReloadLayerException(getName(),e);
1305 1285
		}
1306 1286

  
1307 1287
	}
......
1318 1298
		if (this.loadSelection == null) return;
1319 1299
		try {
1320 1300
			this.getRecordset().getSelectionSupport().setXMLEntity(this.loadSelection);
1321
		} catch (DriverException e) {
1301
		} catch (ReadDriverException e) {
1322 1302
			throw new XMLException(e);
1323 1303
		}
1324 1304
		this.loadSelection = null;
1325 1305

  
1326 1306
	}
1327
	protected void putLoadLegend() throws FieldNotFoundException, DriverException {
1307
	protected void putLoadLegend() throws LegendLayerException {
1328 1308
		if (this.loadLegend == null) return;
1329 1309

  
1330 1310
		this.setLegend(this.loadLegend);
......
1393 1373
		clonedLayer.setISpatialIndex(getISpatialIndex());
1394 1374
		clonedLayer.setName(getName());
1395 1375
		clonedLayer.setCoordTrans(getCoordTrans());
1396
		
1376

  
1397 1377
		if (legend.getLabelField() != null) // Hay etiquetas
1398 1378
		{
1399 1379
			FLyrText lyrText = getLayerText();
......
1403 1383
			clonedLayer.setLegend(clonedLegend);
1404 1384
			clonedLayer.setLayerText(lyrText);
1405 1385
			clonedLegend.setLabelField(antLabelField);
1406
			
1386

  
1407 1387
		}
1408 1388
		else
1409 1389
			clonedLayer.setLegend((VectorialLegend)getLegend());

Also available in: Unified diff