svn-gvsig-desktop / trunk / extensions / extJDBC / src / com / iver / cit / gvsig / fmap / layers / FLayerJDBCVectorial.java @ 10626
History | View | Annotate | Download (4.83 KB)
1 |
package com.iver.cit.gvsig.fmap.layers; |
---|---|
2 |
|
3 |
import org.cresques.cts.IProjection; |
4 |
|
5 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
6 |
import com.iver.cit.gvsig.exceptions.layers.DriverLayerException; |
7 |
import com.iver.cit.gvsig.exceptions.layers.LegendLayerException; |
8 |
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException; |
9 |
import com.iver.cit.gvsig.exceptions.layers.NameLayerException; |
10 |
import com.iver.cit.gvsig.exceptions.layers.ProjectionLayerException; |
11 |
import com.iver.cit.gvsig.exceptions.layers.XMLLayerException; |
12 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
13 |
import com.iver.cit.gvsig.fmap.drivers.DefaultDBDriver; |
14 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
15 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver; |
16 |
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend; |
17 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
18 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
19 |
import com.iver.utiles.XMLEntity; |
20 |
|
21 |
public class FLayerJDBCVectorial extends FLyrVect { |
22 |
private boolean loaded = false; |
23 |
|
24 |
private VectorialDatabaseDriver dbDriver = null; |
25 |
|
26 |
/* Esto deberia ir en el FLyrDefault */
|
27 |
public void setProjectionByName(String projectionName) throws Exception{ |
28 |
IProjection proj = CRSFactory.getCRS(projectionName); |
29 |
if (proj == null) { |
30 |
throw new Exception("No se ha encontrado la proyeccion: "+ projectionName); |
31 |
} |
32 |
this.setProjection(proj);
|
33 |
|
34 |
} |
35 |
|
36 |
|
37 |
public void setDriver(VectorialDatabaseDriver driver) { |
38 |
this.dbDriver = driver;
|
39 |
} |
40 |
|
41 |
public void setDriverByName(String driverName) { |
42 |
this.setDriver(
|
43 |
(VectorialDatabaseDriver)LayerFactory.getDM().getDriver(driverName) |
44 |
); |
45 |
} |
46 |
|
47 |
|
48 |
public VectorialDatabaseDriver getDriver() {
|
49 |
return this.dbDriver; |
50 |
} |
51 |
/* FIXME: esto tendria que tener declarado un throws de algo*/
|
52 |
public void wakeUp() throws LoadLayerException { |
53 |
if (!loaded) {
|
54 |
this.load();
|
55 |
} |
56 |
|
57 |
} |
58 |
|
59 |
|
60 |
public void load() throws LoadLayerException { |
61 |
if (this.getName() == null || this.getName().length() == 0) { |
62 |
this.setAvailable(false); |
63 |
throw new NameLayerException(this.getName(),null); |
64 |
} |
65 |
if (this.dbDriver == null) { |
66 |
this.setAvailable(false); |
67 |
//TODO: traducir???
|
68 |
throw new DriverLayerException(this.getName(),null); |
69 |
} |
70 |
if (this.getProjection() == null) { |
71 |
this.setAvailable(false); |
72 |
//TODO: traducir???
|
73 |
throw new ProjectionLayerException(this.getName(),null); |
74 |
} |
75 |
|
76 |
// try {
|
77 |
try {
|
78 |
((DefaultDBDriver)this.dbDriver).load();
|
79 |
} catch (ReadDriverException e1) {
|
80 |
throw new LoadLayerException(this.getName(),e1); |
81 |
} |
82 |
// } catch (Exception e) {
|
83 |
// this.setAvailable(false);
|
84 |
// throw new DriverIOException(e);
|
85 |
// }
|
86 |
|
87 |
// try {
|
88 |
VectorialDBAdapter dbAdapter = new VectorialDBAdapter();
|
89 |
dbAdapter.setDriver(this.dbDriver);
|
90 |
this.setSource(dbAdapter);
|
91 |
|
92 |
// } catch (Exception e) {
|
93 |
// this.setAvailable(false);
|
94 |
// throw new DriverIOException(e);
|
95 |
// }
|
96 |
|
97 |
// try {
|
98 |
try {
|
99 |
this.putLoadSelection();
|
100 |
this.putLoadLegend();
|
101 |
this.initializeLegendDefault();
|
102 |
} catch (XMLException e) {
|
103 |
this.setAvailable(false); |
104 |
throw new XMLLayerException(this.getName(),e); |
105 |
} catch (LegendLayerException e) {
|
106 |
this.setAvailable(false); |
107 |
throw new LegendLayerException(this.getName(),e); |
108 |
} catch (ReadDriverException e) {
|
109 |
this.setAvailable(false); |
110 |
throw new LoadLayerException(this.getName(),e); |
111 |
} |
112 |
// } catch (Exception e) {
|
113 |
// this.setAvailable(false);
|
114 |
// //TODO: traducir???
|
115 |
// throw new DriverIOException(e);
|
116 |
// }
|
117 |
this.cleanLoadOptions();
|
118 |
} |
119 |
|
120 |
/* Esto deberia ir en FLyrVect */
|
121 |
private void initializeLegendDefault() throws ReadDriverException, LegendLayerException { |
122 |
if (this.getLegend() == null) { |
123 |
if (this.getRecordset().getDriver() instanceof WithDefaultLegend) { |
124 |
WithDefaultLegend aux = (WithDefaultLegend) this.getRecordset().getDriver();
|
125 |
this.setLegend((VectorialLegend) aux.getDefaultLegend());
|
126 |
} else {
|
127 |
this.setLegend(LegendFactory.createSingleSymbolLegend(
|
128 |
this.getShapeType()));
|
129 |
} |
130 |
} |
131 |
} |
132 |
|
133 |
public void setXMLEntity(XMLEntity xml) throws XMLException { |
134 |
IProjection proj = null;
|
135 |
if (xml.contains("proj")) { |
136 |
proj = CRSFactory.getCRS(xml.getStringProperty("proj"));
|
137 |
} |
138 |
else
|
139 |
{ |
140 |
proj = this.getMapContext().getViewPort().getProjection();
|
141 |
} |
142 |
this.setName(xml.getName());
|
143 |
this.setProjection(proj);
|
144 |
String driverName = xml.getStringProperty("db"); |
145 |
VectorialDatabaseDriver driver; |
146 |
try {
|
147 |
|
148 |
driver = (VectorialDatabaseDriver) LayerFactory.getDM().getDriver(driverName); |
149 |
//Hay que separar la carga de los datos del XMLEntity del load.
|
150 |
driver.setXMLEntity(xml.getChild(2));
|
151 |
this.setDriver(driver);
|
152 |
|
153 |
} catch (Exception e){ |
154 |
throw new XMLException(e); |
155 |
} |
156 |
super.setXMLEntityNew(xml);
|
157 |
|
158 |
|
159 |
} |
160 |
|
161 |
} |