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