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