root / tags / v1_1_Build_1003 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLayerVectorialDB.java @ 12271
History | View | Annotate | Download (6.16 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 Prodevelop and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* Prodevelop Integraci?n de Tecnolog?as SL
|
34 |
* Conde Salvatierra de ?lava , 34-10
|
35 |
* 46004 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963 510 612
|
39 |
* +34 963 510 968
|
40 |
* gis@prodevelop.es
|
41 |
* http://www.prodevelop.es
|
42 |
*/
|
43 |
package com.iver.cit.gvsig.fmap.layers; |
44 |
|
45 |
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
46 |
|
47 |
import com.iver.cit.gvsig.fmap.DriverException; |
48 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
49 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
50 |
import com.iver.cit.gvsig.fmap.drivers.IVectorialDatabaseDriver; |
51 |
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend; |
52 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
53 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
54 |
|
55 |
import com.iver.utiles.XMLEntity; |
56 |
|
57 |
import org.cresques.cts.IProjection; |
58 |
|
59 |
|
60 |
public class FLayerVectorialDB extends FLyrVect { |
61 |
private boolean loaded = false; |
62 |
private IVectorialDatabaseDriver dbDriver = null; |
63 |
|
64 |
/* Esto deberia ir en el FLyrDefault */
|
65 |
public void setProjectionByName(String projectionName) |
66 |
throws Exception { |
67 |
IProjection proj = CRSFactory.getCRS(projectionName); |
68 |
|
69 |
if (proj == null) { |
70 |
throw new Exception("No se ha encontrado la proyeccion: " + |
71 |
projectionName); |
72 |
} |
73 |
|
74 |
this.setProjection(proj);
|
75 |
} |
76 |
|
77 |
public void setDriver(IVectorialDatabaseDriver driver) { |
78 |
this.dbDriver = driver;
|
79 |
} |
80 |
|
81 |
public void setDriverByName(String driverName) { |
82 |
this.setDriver((IVectorialDatabaseDriver) LayerFactory.getDM()
|
83 |
.getDriver(driverName)); |
84 |
} |
85 |
|
86 |
public IVectorialDatabaseDriver getDriver() {
|
87 |
return this.dbDriver; |
88 |
} |
89 |
|
90 |
/* FIXME: esto tendria que tener declarado un throws de algo*/
|
91 |
public void wakeUp() { |
92 |
if (!loaded) {
|
93 |
try {
|
94 |
this.load();
|
95 |
} |
96 |
catch (DriverIOException e) {
|
97 |
// TODO Auto-generated catch block
|
98 |
e.printStackTrace(); |
99 |
} |
100 |
} |
101 |
} |
102 |
|
103 |
public void load() throws DriverIOException { |
104 |
if ((this.getName() == null) || (this.getName().length() == 0)) { |
105 |
this.setAvailable(false); |
106 |
|
107 |
//TODO: traducir???
|
108 |
throw new DriverIOException("No se ha especificado nombre de capa"); |
109 |
} |
110 |
|
111 |
if (this.dbDriver == null) { |
112 |
this.setAvailable(false); |
113 |
|
114 |
//TODO: traducir???
|
115 |
throw new DriverIOException("No se ha especificado driver"); |
116 |
} |
117 |
|
118 |
if (this.getProjection() == null) { |
119 |
this.setAvailable(false); |
120 |
|
121 |
//TODO: traducir???
|
122 |
throw new DriverIOException("No se ha especificado proyeccion"); |
123 |
} |
124 |
|
125 |
try {
|
126 |
((IVectorialDatabaseDriver) this.dbDriver).load();
|
127 |
} |
128 |
catch (Exception e) { |
129 |
this.setAvailable(false); |
130 |
throw new DriverIOException(e); |
131 |
} |
132 |
|
133 |
try {
|
134 |
VectorialDBAdapter dbAdapter = new VectorialDBAdapter();
|
135 |
dbAdapter.setDriver(this.dbDriver);
|
136 |
this.setSource(dbAdapter);
|
137 |
} |
138 |
catch (Exception e) { |
139 |
this.setAvailable(false); |
140 |
throw new DriverIOException(e); |
141 |
} |
142 |
|
143 |
try {
|
144 |
this.putLoadSelection();
|
145 |
this.putLoadLegend();
|
146 |
this.initializeLegendDefault();
|
147 |
} |
148 |
catch (Exception e) { |
149 |
this.setAvailable(false); |
150 |
|
151 |
//TODO: traducir???
|
152 |
throw new DriverIOException(e); |
153 |
} |
154 |
|
155 |
this.cleanLoadOptions();
|
156 |
} |
157 |
|
158 |
/* Esto deberia ir en FLyrVect */
|
159 |
private void initializeLegendDefault() |
160 |
throws FieldNotFoundException, DriverException {
|
161 |
if (this.getLegend() == null) { |
162 |
if (this.getRecordset().getDriver() instanceof WithDefaultLegend) { |
163 |
WithDefaultLegend aux = (WithDefaultLegend) this.getRecordset()
|
164 |
.getDriver(); |
165 |
this.setLegend((VectorialLegend) aux.getDefaultLegend());
|
166 |
} |
167 |
else {
|
168 |
this.setLegend(LegendFactory.createSingleSymbolLegend(
|
169 |
this.getShapeType()));
|
170 |
} |
171 |
} |
172 |
} |
173 |
|
174 |
public void setXMLEntity(XMLEntity xml) throws XMLException { |
175 |
IProjection proj = null;
|
176 |
|
177 |
if (xml.contains("proj")) { |
178 |
proj = CRSFactory.getCRS(xml.getStringProperty("proj"));
|
179 |
} |
180 |
else {
|
181 |
proj = this.getMapContext().getViewPort().getProjection();
|
182 |
} |
183 |
|
184 |
this.setName(xml.getName());
|
185 |
this.setProjection(proj);
|
186 |
|
187 |
String driverName = xml.getStringProperty("db"); |
188 |
IVectorialDatabaseDriver driver; |
189 |
|
190 |
try {
|
191 |
driver = (IVectorialDatabaseDriver) LayerFactory.getDM() |
192 |
.getDriver(driverName); |
193 |
|
194 |
//Hay que separar la carga de los datos del XMLEntity del load.
|
195 |
driver.setXMLEntity(xml.getChild(2));
|
196 |
this.setDriver(driver);
|
197 |
} |
198 |
catch (Exception e) { |
199 |
throw new XMLException(e); |
200 |
} |
201 |
|
202 |
super.setXMLEntityNew(xml);
|
203 |
} |
204 |
} |