root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / LayerFactory.java @ 10977
History | View | Annotate | Download (24 KB)
1 | 1100 | fjp | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2004 IVER T.I. 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 | * IVER T.I. S.A
|
||
34 | * Salamanca 50
|
||
35 | * 46005 Valencia
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 963163400
|
||
39 | * dac@iver.es
|
||
40 | */
|
||
41 | 214 | fernando | package com.iver.cit.gvsig.fmap.layers; |
42 | |||
43 | 2277 | vcaballero | import java.io.File; |
44 | import java.io.IOException; |
||
45 | import java.sql.SQLException; |
||
46 | import java.sql.Types; |
||
47 | import java.util.TreeMap; |
||
48 | |||
49 | import org.apache.log4j.Logger; |
||
50 | import org.cresques.cts.IProjection; |
||
51 | |||
52 | 408 | fernando | import com.hardcode.driverManager.Driver; |
53 | import com.hardcode.driverManager.DriverLoadException; |
||
54 | import com.hardcode.driverManager.DriverManager; |
||
55 | 4143 | caballero | import com.hardcode.driverManager.WriterManager; |
56 | 10627 | caballero | import com.hardcode.gdbms.driver.exceptions.FileNotFoundDriverException; |
57 | import com.hardcode.gdbms.driver.exceptions.InitializeDriverException; |
||
58 | import com.hardcode.gdbms.driver.exceptions.OpenDriverException; |
||
59 | import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
||
60 | import com.hardcode.gdbms.driver.exceptions.UnsupportedVersionDriverException; |
||
61 | import com.hardcode.gdbms.driver.exceptions.WriteDriverException; |
||
62 | 1828 | fernando | import com.hardcode.gdbms.engine.customQuery.QueryManager; |
63 | 2183 | fernando | import com.hardcode.gdbms.engine.data.DataSource; |
64 | 408 | fernando | import com.hardcode.gdbms.engine.data.DataSourceFactory; |
65 | 2183 | fernando | import com.hardcode.gdbms.engine.data.NoSuchTableException; |
66 | 10627 | caballero | import com.hardcode.gdbms.engine.data.driver.DriverException; |
67 | 2183 | fernando | import com.hardcode.gdbms.engine.data.edition.DataWare; |
68 | import com.hardcode.gdbms.engine.values.Value; |
||
69 | import com.hardcode.gdbms.engine.values.ValueFactory; |
||
70 | 10627 | caballero | import com.iver.cit.gvsig.exceptions.layers.LegendLayerException; |
71 | import com.iver.cit.gvsig.exceptions.layers.LoadLayerException; |
||
72 | 7459 | azabala | import com.iver.cit.gvsig.fmap.DriverNotLoadedExceptionType; |
73 | import com.iver.cit.gvsig.fmap.GenericDriverExceptionType; |
||
74 | import com.iver.cit.gvsig.fmap.LegendDriverExceptionType; |
||
75 | 2183 | fernando | import com.iver.cit.gvsig.fmap.ProgressListener; |
76 | 2850 | nacho | import com.iver.cit.gvsig.fmap.ViewPort; |
77 | 3236 | fjp | import com.iver.cit.gvsig.fmap.drivers.DBLayerDefinition; |
78 | 422 | fjp | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
79 | 303 | fernando | import com.iver.cit.gvsig.fmap.drivers.RasterDriver; |
80 | import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver; |
||
81 | 408 | fernando | import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
82 | 438 | fernando | import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
83 | 2183 | fernando | import com.iver.cit.gvsig.fmap.drivers.VectorialJDBCDriver; |
84 | 714 | fjp | import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend; |
85 | 1828 | fernando | import com.iver.cit.gvsig.fmap.operations.arcview.ArcJoin; |
86 | 458 | fjp | import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
87 | 714 | fjp | import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
88 | 10814 | jaume | import com.iver.cit.gvsig.fmap.rendering.styling.AttrInTableLabeling; |
89 | import com.iver.cit.gvsig.fmap.rendering.styling.ILabelingStrategy; |
||
90 | 7459 | azabala | import com.iver.utiles.ExceptionDescription; |
91 | 303 | fernando | |
92 | 214 | fernando | /**
|
93 | * Crea un adaptador del driver que se le pasa como par?metro en los m?todos
|
||
94 | * createLayer. Si hay memoria suficiente se crea un FLyrMemory que pasa todas
|
||
95 | * las features del driver a memoria
|
||
96 | */
|
||
97 | public class LayerFactory { |
||
98 | 7459 | azabala | private static Logger logger = Logger.getLogger(LayerFactory.class |
99 | .getName()); |
||
100 | |||
101 | 439 | luisw | private static String driversPath = "../FMap 03/drivers"; |
102 | 4781 | fjp | private static String writersPath = "../FMap 03/drivers"; |
103 | 732 | fernando | private static DriverManager driverManager; |
104 | 4143 | caballero | private static WriterManager writerManager; |
105 | 1828 | fernando | private static DataSourceFactory dataSourceFactory; |
106 | 4143 | caballero | |
107 | 732 | fernando | /**
|
108 | * Map en el que se guarda para cada fuente de datos a?adida al sistema, el
|
||
109 | 7459 | azabala | * adaptador que la maneja. Ha de ser un TreeMap ya que esta clase define la
|
110 | * igualdad entre las claves a traves del m?todo equals de las mismas. Los
|
||
111 | * objetos FileSource, DBSource y WFSSource tienen definido el m?todo equals
|
||
112 | * de forma que devuelven true cuando dos objetos apuntan a la misma fuente
|
||
113 | * de datos
|
||
114 | 732 | fernando | */
|
115 | private static TreeMap sourceAdapter; |
||
116 | 214 | fernando | |
117 | 1828 | fernando | /*
|
118 | 7459 | azabala | * Crea un RandomVectorialFile con el driver que se le pasa como par?metro y
|
119 | * guard?ndose el nombre del fichero para realizar los accesos, la capa
|
||
120 | 732 | fernando | * tendr? asociada la proyecci?n que se pasa como parametro tambi?n
|
121 | 9634 | caballero | *
|
122 | 7459 | azabala | * @param layerName Nombre de la capa. @param driverName Nombre del driver.
|
123 | * @param f fichero. @param proj Proyecci?n.
|
||
124 | 9634 | caballero | *
|
125 | 7459 | azabala | * @return FLayer. @throws DriverException
|
126 | 9634 | caballero | *
|
127 | 7459 | azabala | * @throws DriverException @throws DriverIOException
|
128 | 2183 | fernando | */
|
129 | 732 | fernando | public static FLayer createLayer(String layerName, String driverName, |
130 | 10627 | caballero | File f, IProjection proj) throws LoadLayerException { |
131 | 7459 | azabala | // Se obtiene el driver que lee
|
132 | 732 | fernando | DriverManager dm = getDM();
|
133 | 438 | fernando | |
134 | 732 | fernando | try {
|
135 | Driver d = dm.getDriver(driverName);
|
||
136 | 438 | fernando | |
137 | 732 | fernando | if (d instanceof VectorialFileDriver) { |
138 | return createLayer(layerName, (VectorialFileDriver) d, f, proj);
|
||
139 | } else if (d instanceof RasterDriver) { |
||
140 | return createLayer(layerName, (RasterDriver) d, f, proj);
|
||
141 | } |
||
142 | } catch (DriverLoadException e) {
|
||
143 | 7459 | azabala | //hay un poco de lio sobre que excepciones se dejan subir
|
144 | //arriba y que excepciones se quedan en LayerFactory
|
||
145 | //(esto se debe a que queremos intentar recuperar ciertas capas)
|
||
146 | //las excepciones de este metodo se dejan subir todas, puesto
|
||
147 | //que las excepciones de los dos otros metodos createLayer si que
|
||
148 | //se atrapan
|
||
149 | 9634 | caballero | DriverNotLoadedExceptionType exceptionType = |
150 | 7459 | azabala | new DriverNotLoadedExceptionType();
|
151 | exceptionType.setDriverName(driverName); |
||
152 | 10627 | caballero | // DriverException exception =
|
153 | // new DriverException(e, exceptionType);
|
||
154 | throw new LoadLayerException(layerName,e); |
||
155 | 732 | fernando | } |
156 | 438 | fernando | |
157 | 732 | fernando | return null; |
158 | } |
||
159 | 2183 | fernando | |
160 | 1034 | vcaballero | /**
|
161 | 7459 | azabala | * It creates a FLayer (FLyrVect) which reads its data from a file driver,
|
162 | * projected in the specified projection.
|
||
163 | 9634 | caballero | *
|
164 | 7459 | azabala | * @param layerName
|
165 | * name of the layer
|
||
166 | * @param d
|
||
167 | * vectorial file driver to read layer's data
|
||
168 | * @param f
|
||
169 | * file associated to the driver
|
||
170 | * @param proj
|
||
171 | * layer projection
|
||
172 | 9634 | caballero | *
|
173 | 7459 | azabala | * @return FLayer new vectorial layer
|
174 | 10627 | caballero | * @throws LoadLayerException
|
175 | 9634 | caballero | *
|
176 | 1034 | vcaballero | * @throws DriverException
|
177 | */
|
||
178 | public static FLayer createLayer(String layerName, VectorialFileDriver d, |
||
179 | 9634 | caballero | File f, IProjection proj)
|
180 | |||
181 | 7459 | azabala | /*throws DriverException*/ {
|
182 | 10814 | jaume | FLyrVect layer = new FLyrVect();
|
183 | 10627 | caballero | try {
|
184 | 7459 | azabala | // TODO Comprobar si hay un adaptador ya
|
185 | 1034 | vcaballero | VectorialFileAdapter adapter = new VectorialFileAdapter(f);
|
186 | 10627 | caballero | adapter.setDriver(d); |
187 | 214 | fernando | |
188 | 10627 | caballero | |
189 | 10814 | jaume | layer.setName(layerName); |
190 | 7459 | azabala | |
191 | // TODO Meter esto dentro de la comprobaci?n de si hay memoria
|
||
192 | 1034 | vcaballero | if (false) { |
193 | } else {
|
||
194 | 10814 | jaume | layer.setSource(adapter); |
195 | layer.setProjection(proj); |
||
196 | 1034 | vcaballero | } |
197 | 4143 | caballero | |
198 | 10627 | caballero | // try {
|
199 | 470 | fjp | // Le asignamos tambi?n una legenda por defecto acorde con
|
200 | // el tipo de shape que tenga. Tampoco s? si es aqu? el
|
||
201 | // sitio adecuado, pero en fin....
|
||
202 | 1034 | vcaballero | if (d instanceof WithDefaultLegend) { |
203 | WithDefaultLegend aux = (WithDefaultLegend) d; |
||
204 | 10627 | caballero | |
205 | adapter.start(); |
||
206 | 10814 | jaume | layer.setLegend((VectorialLegend) aux.getDefaultLegend()); |
207 | |||
208 | ILabelingStrategy labeler = aux.getDefaultLabelingStrategy(); |
||
209 | if (labeler instanceof AttrInTableLabeling) { |
||
210 | ((AttrInTableLabeling) labeler).setLayer(layer); |
||
211 | } |
||
212 | layer.setLabelingStrategy(labeler);layer.setIsLabeled(true); // TODO: ac? no s'hauria de detectar si t? etiquetes????? |
||
213 | layer.setIsLabeled(true); // TODO: ac? no s'hauria de detectar si t? etiquetes????? |
||
214 | 10627 | caballero | adapter.stop(); |
215 | |||
216 | 1034 | vcaballero | } else {
|
217 | 10814 | jaume | layer.setLegend(LegendFactory.createSingleSymbolLegend(layer |
218 | 7459 | azabala | .getShapeType())); |
219 | 1034 | vcaballero | } |
220 | 9634 | caballero | |
221 | 10627 | caballero | // } catch (LegendLayerException e) {
|
222 | // //this exception is caused in legend creation
|
||
223 | // LegendDriverExceptionType excepType =
|
||
224 | // new LegendDriverExceptionType("Error al construir la leyenda");
|
||
225 | // //TODO Para hacer esto extensible tiene que usarse puntos
|
||
226 | // //de extension, y comparar las clases de leyendas registradas
|
||
227 | // VectorialLegend legend = (VectorialLegend)
|
||
228 | // ((WithDefaultLegend)d).getDefaultLegend();
|
||
229 | //
|
||
230 | // excepType.setLegendLabelField(legend.getLabelField());
|
||
231 | // excepType.setLegendHeightField(legend.getLabelHeightField());
|
||
232 | // excepType.setLegendRotationField(legend.getLabelRotationField());
|
||
233 | // DriverException exception = new DriverException(e, excepType);
|
||
234 | // capa.setAvailable(false);
|
||
235 | // capa.addError(exception);
|
||
236 | //
|
||
237 | // }
|
||
238 | //
|
||
239 | // /*
|
||
240 | // * catch(DriverException e){
|
||
241 | // * ESTO HAY QUE CAPTURARLO,DE FORMA QUE CREATELAYER NO LANCE NINGUNA
|
||
242 | // * EXCEPCION (A NO SER QUE SEA IRRECUPERABLE)
|
||
243 | // * }
|
||
244 | // */
|
||
245 | // catch(Exception e){
|
||
246 | // GenericDriverExceptionType type = new GenericDriverExceptionType();
|
||
247 | // DriverException exception = new DriverException(e, type);
|
||
248 | // capa.setAvailable(false);
|
||
249 | // capa.addError(exception);
|
||
250 | // }
|
||
251 | 9634 | caballero | |
252 | 10627 | caballero | } catch (ReadDriverException e) {
|
253 | 10814 | jaume | layer.setAvailable(false);
|
254 | layer.addError(e); |
||
255 | 10627 | caballero | } catch (LegendLayerException e) {
|
256 | 10814 | jaume | layer.setAvailable(false);
|
257 | layer.addError(e); |
||
258 | 10627 | caballero | } |
259 | 10814 | jaume | return layer;
|
260 | 1034 | vcaballero | } |
261 | 567 | luisw | |
262 | 7459 | azabala | /**
|
263 | * Creates a new vectorial layer from a generic layer (by generic whe mean
|
||
264 | * that we dont know a priory its origin: file, memory, jdbc database, etc.
|
||
265 | 9634 | caballero | *
|
266 | 7459 | azabala | * @param layerName
|
267 | * @param d
|
||
268 | * @param proj
|
||
269 | * @return
|
||
270 | * @throws DriverException
|
||
271 | */
|
||
272 | public static FLayer createLayer(String layerName, VectorialDriver d, |
||
273 | 9634 | caballero | IProjection proj) |
274 | 7459 | azabala | /*
|
275 | 9634 | caballero | throws DriverException
|
276 | 7459 | azabala | */{
|
277 | VectorialAdapter adapter = null;
|
||
278 | if (d instanceof VectorialFileDriver) { |
||
279 | adapter = new VectorialFileAdapter(((VectorialFileDriver) d)
|
||
280 | .getFile()); |
||
281 | } else if (d instanceof VectorialJDBCDriver) { |
||
282 | adapter = new VectorialDBAdapter();
|
||
283 | } else {
|
||
284 | adapter = new VectorialDefaultAdapter();
|
||
285 | } |
||
286 | adapter.setDriver((VectorialDriver) d); |
||
287 | 3301 | fjp | |
288 | 10814 | jaume | FLyrVect layer = new FLyrVect();
|
289 | layer.setName(layerName); |
||
290 | 3301 | fjp | |
291 | 10814 | jaume | layer.setSource(adapter); |
292 | layer.setProjection(proj); |
||
293 | 3301 | fjp | |
294 | 7459 | azabala | try {
|
295 | 4143 | caballero | |
296 | 7459 | azabala | // Le asignamos tambi?n una legenda por defecto acorde con
|
297 | // el tipo de shape que tenga. Tampoco s? si es aqu? el
|
||
298 | // sitio adecuado, pero en fin....
|
||
299 | if (d instanceof WithDefaultLegend) { |
||
300 | WithDefaultLegend aux = (WithDefaultLegend) d; |
||
301 | adapter.start(); |
||
302 | 10814 | jaume | layer.setLegend((VectorialLegend) aux.getDefaultLegend()); |
303 | |||
304 | ILabelingStrategy labeler = aux.getDefaultLabelingStrategy(); |
||
305 | if (labeler instanceof AttrInTableLabeling) { |
||
306 | ((AttrInTableLabeling) labeler).setLayer(layer); |
||
307 | } |
||
308 | layer.setLabelingStrategy(labeler); |
||
309 | |||
310 | layer.setIsLabeled(true); // TODO: ac? no s'hauria de detectar si t? etiquetes????? |
||
311 | |||
312 | 7459 | azabala | adapter.stop(); |
313 | } else {
|
||
314 | 10814 | jaume | layer.setLegend(LegendFactory.createSingleSymbolLegend(layer |
315 | 7459 | azabala | .getShapeType())); |
316 | } |
||
317 | 10627 | caballero | } catch (LegendLayerException e) {
|
318 | 7459 | azabala | // this exception is caused in legend creation
|
319 | 10627 | caballero | // LegendDriverExceptionType excepType =
|
320 | // new LegendDriverExceptionType("error al construir la leyenda, campo no encontrado");
|
||
321 | 3301 | fjp | |
322 | 7459 | azabala | //TODO Para hacer esto extensible tiene que usarse puntos
|
323 | //de extension, y comparar las clases de leyendas registradas
|
||
324 | 10627 | caballero | // VectorialLegend legend = (VectorialLegend)
|
325 | // ((WithDefaultLegend)d).getDefaultLegend();
|
||
326 | // excepType.setDriverName(d.getName());
|
||
327 | // excepType.setLegendLabelField(legend.getLabelField());
|
||
328 | // excepType.setLegendHeightField(legend.getLabelHeightField());
|
||
329 | // excepType.setLegendRotationField(legend.getLabelRotationField());
|
||
330 | 9634 | caballero | |
331 | 10627 | caballero | // DriverException exception = new DriverException(e, excepType);
|
332 | 10814 | jaume | layer.setAvailable(false);
|
333 | layer.addError(e); |
||
334 | 10627 | caballero | // }
|
335 | // catch(Exception e){
|
||
336 | // GenericDriverExceptionType type = new GenericDriverExceptionType();
|
||
337 | // DriverException exception = new DriverException(e, type);
|
||
338 | // capa.setAvailable(false);
|
||
339 | // capa.addError(exception);
|
||
340 | // } catch (UnsupportedVersionDriverException e) {
|
||
341 | // capa.setAvailable(false);
|
||
342 | // capa.addError(e);
|
||
343 | // } catch (InitializeDriverException e) {
|
||
344 | // capa.setAvailable(false);
|
||
345 | // capa.addError(e);
|
||
346 | } catch (ReadDriverException e) {
|
||
347 | 10814 | jaume | layer.setAvailable(false);
|
348 | layer.addError(e); |
||
349 | 7459 | azabala | } |
350 | 1034 | vcaballero | |
351 | 10814 | jaume | return layer;
|
352 | 7459 | azabala | } |
353 | |||
354 | 1034 | vcaballero | /**
|
355 | * Crea una capa Raster a partir del nombre driver, fichero y proyecci?n.
|
||
356 | 9634 | caballero | *
|
357 | 7459 | azabala | * @param layerName
|
358 | * Nombre de la capa.
|
||
359 | * @param d
|
||
360 | * RasterDriver.
|
||
361 | * @param f
|
||
362 | * Fichero.
|
||
363 | * @param proj
|
||
364 | * Proyecci?n.
|
||
365 | 9634 | caballero | *
|
366 | 1034 | vcaballero | * @return Nueva capa de tipo raster.
|
367 | 10627 | caballero | * @throws LoadLayerException
|
368 | 9634 | caballero | *
|
369 | 1034 | vcaballero | * @throws DriverIOException
|
370 | */
|
||
371 | 732 | fernando | public static FLyrRaster createLayer(String layerName, RasterDriver d, |
372 | 10627 | caballero | File f, IProjection proj) throws LoadLayerException { |
373 | 732 | fernando | RasterAdapter adapter = new RasterFileAdapter(f);
|
374 | adapter.setDriver(d); |
||
375 | FLyrRaster capa = new FLyrRaster();
|
||
376 | capa.setName(layerName); |
||
377 | |||
378 | 7459 | azabala | // TODO Meter esto dentro de la comprobaci?n de si hay memoria
|
379 | 732 | fernando | if (false) { |
380 | } else {
|
||
381 | capa.setSource(adapter); |
||
382 | capa.setProjection(proj); |
||
383 | 10627 | caballero | capa.load(); |
384 | 732 | fernando | } |
385 | |||
386 | 567 | luisw | return capa;
|
387 | 732 | fernando | } |
388 | 567 | luisw | |
389 | 732 | fernando | /**
|
390 | 4143 | caballero | * Crea una capa Raster a partir del nombre driver, fichero y proyecci?n y
|
391 | * coordenadas de georeferenciaci?n. Esta funci?n es para georeferenciar
|
||
392 | 7459 | azabala | * capas raster. Para imagenes que no tienen georeferenciaci?n hay que
|
393 | * asignarle una temporal, normalmente a partir de la vista activa.
|
||
394 | 9634 | caballero | *
|
395 | 7459 | azabala | * @param layerName
|
396 | * Nombre de la capa.
|
||
397 | * @param d
|
||
398 | * RasterDriver.
|
||
399 | * @param f
|
||
400 | * Fichero.
|
||
401 | * @param proj
|
||
402 | * Proyecci?n.
|
||
403 | * @param extent
|
||
404 | * Extent de la vista activa
|
||
405 | 9634 | caballero | *
|
406 | 2850 | nacho | * @return Nueva capa de tipo raster.
|
407 | 10627 | caballero | * @throws LoadLayerException
|
408 | 9634 | caballero | *
|
409 | 2850 | nacho | * @throws DriverIOException
|
410 | */
|
||
411 | public static FLyrRaster createLayer(String layerName, RasterDriver d, |
||
412 | 10627 | caballero | File f, IProjection proj, ViewPort vp) throws LoadLayerException { |
413 | 2850 | nacho | RasterAdapter adapter = new RasterFileAdapter(f);
|
414 | adapter.setDriver(d); |
||
415 | 4143 | caballero | |
416 | 2850 | nacho | FLyrRaster capa = new FLyrRaster();
|
417 | capa.setName(layerName); |
||
418 | 4143 | caballero | |
419 | 7459 | azabala | // TODO Meter esto dentro de la comprobaci?n de si hay memoria
|
420 | 2850 | nacho | if (false) { |
421 | } else {
|
||
422 | capa.setSource(adapter); |
||
423 | capa.setProjection(proj); |
||
424 | 7459 | azabala | // capa.setTempExtent(vp);
|
425 | 10627 | caballero | capa.load(); |
426 | 2850 | nacho | } |
427 | |||
428 | return capa;
|
||
429 | } |
||
430 | 4143 | caballero | |
431 | 7459 | azabala | public static FLayer createArcSDELayer(String layerName, |
432 | VectorialDatabaseDriver driver, IProjection proj) { |
||
433 | // throw new UnsupportedOperationException();
|
||
434 | FLyrVect layer = new FLyrVect();
|
||
435 | VectorialAdapter adapter = new VectorialDBAdapter();
|
||
436 | adapter.setDriver(driver); |
||
437 | 4143 | caballero | |
438 | 7459 | azabala | layer.setName(layerName); |
439 | layer.setSource(adapter); |
||
440 | layer.setProjection(proj); |
||
441 | try {
|
||
442 | if (driver instanceof WithDefaultLegend) { |
||
443 | WithDefaultLegend aux = (WithDefaultLegend) driver; |
||
444 | adapter.start(); |
||
445 | layer.setLegend((VectorialLegend) aux.getDefaultLegend()); |
||
446 | 10814 | jaume | |
447 | ILabelingStrategy labeler = aux.getDefaultLabelingStrategy(); |
||
448 | if (labeler instanceof AttrInTableLabeling) { |
||
449 | ((AttrInTableLabeling) labeler).setLayer(layer); |
||
450 | } |
||
451 | layer.setLabelingStrategy(labeler);layer.setIsLabeled(true); // TODO: ac? no s'hauria de detectar si t? etiquetes????? |
||
452 | |||
453 | 7459 | azabala | adapter.stop(); |
454 | } else {
|
||
455 | layer.setLegend(LegendFactory.createSingleSymbolLegend(layer |
||
456 | .getShapeType())); |
||
457 | } |
||
458 | 10627 | caballero | } catch (LegendLayerException e) {
|
459 | 7459 | azabala | throw new UnsupportedOperationException(e.getMessage()); |
460 | 10627 | caballero | } catch (InitializeDriverException e) {
|
461 | 7459 | azabala | throw new UnsupportedOperationException(e.getMessage()); |
462 | 10627 | caballero | } catch (ReadDriverException e) {
|
463 | throw new UnsupportedOperationException(e.getMessage()); |
||
464 | 7459 | azabala | } |
465 | 4143 | caballero | |
466 | 7459 | azabala | try {
|
467 | layer.setLegend(LegendFactory.createSingleSymbolLegend(layer |
||
468 | .getShapeType())); |
||
469 | 10627 | caballero | } catch (LegendLayerException e) {
|
470 | 7459 | azabala | e.printStackTrace(); |
471 | 10627 | caballero | } catch (ReadDriverException e) {
|
472 | 7459 | azabala | e.printStackTrace(); |
473 | } |
||
474 | return layer;
|
||
475 | } |
||
476 | 4143 | caballero | |
477 | 732 | fernando | /**
|
478 | * Crea un RandomVectorialWFS con el driver que se le pasa como par?metro y
|
||
479 | * guard?ndose la URL del servidor que se pasa como par?metro
|
||
480 | 9634 | caballero | *
|
481 | 1034 | vcaballero | * @param driver
|
482 | * @param host
|
||
483 | * @param port
|
||
484 | * @param user
|
||
485 | * @param password
|
||
486 | * @param dbName
|
||
487 | * @param tableName
|
||
488 | * @param proj
|
||
489 | 9634 | caballero | *
|
490 | 1034 | vcaballero | * @return Capa creada.
|
491 | 9634 | caballero | *
|
492 | 1034 | vcaballero | * @throws UnsupportedOperationException
|
493 | 732 | fernando | */
|
494 | public static FLayer createLayer(VectorialDatabaseDriver driver, |
||
495 | 7459 | azabala | String host, int port, String user, String password, String dbName, |
496 | String tableName, IProjection proj) {
|
||
497 | 732 | fernando | throw new UnsupportedOperationException(); |
498 | } |
||
499 | 4143 | caballero | |
500 | 7459 | azabala | public static FLayer createDBLayer(VectorialDatabaseDriver driver, |
501 | String layerName, IProjection proj) {
|
||
502 | 4143 | caballero | |
503 | 10814 | jaume | FLyrVect layer = new FLyrVect();
|
504 | 4143 | caballero | |
505 | 10814 | jaume | layer.setName(layerName); |
506 | 1691 | fjp | VectorialDBAdapter dbAdapter = new VectorialDBAdapter();
|
507 | 4143 | caballero | dbAdapter.setDriver(driver); |
508 | |||
509 | 10814 | jaume | layer.setSource(dbAdapter); |
510 | layer.setProjection(proj); |
||
511 | 1691 | fjp | try {
|
512 | if (driver instanceof WithDefaultLegend) { |
||
513 | WithDefaultLegend aux = (WithDefaultLegend) driver; |
||
514 | dbAdapter.start(); |
||
515 | 10814 | jaume | layer.setLegend((VectorialLegend) aux.getDefaultLegend()); |
516 | |||
517 | ILabelingStrategy labeler = aux.getDefaultLabelingStrategy(); |
||
518 | if (labeler instanceof AttrInTableLabeling) { |
||
519 | ((AttrInTableLabeling) labeler).setLayer(layer); |
||
520 | } |
||
521 | layer.setLabelingStrategy(labeler);layer.setIsLabeled(true); // TODO: ac? no s'hauria de detectar si t? etiquetes????? |
||
522 | |||
523 | layer.setIsLabeled(true); // TODO: ac? no s'hauria de detectar si t? etiquetes????? |
||
524 | |||
525 | 1691 | fjp | dbAdapter.stop(); |
526 | 4143 | caballero | } else {
|
527 | 10814 | jaume | layer.setLegend(LegendFactory.createSingleSymbolLegend(layer |
528 | 7459 | azabala | .getShapeType())); |
529 | 1691 | fjp | } |
530 | 10627 | caballero | } catch (LegendLayerException e) {
|
531 | 9634 | caballero | LegendDriverExceptionType excepType = |
532 | 7459 | azabala | new LegendDriverExceptionType("Error al construir la leyenda, campo no encontrado"); |
533 | //TODO Para hacer esto extensible tiene que usarse puntos
|
||
534 | //de extension, y comparar las clases de leyendas registradas
|
||
535 | 9634 | caballero | VectorialLegend legend = (VectorialLegend) |
536 | 7459 | azabala | ((WithDefaultLegend)driver).getDefaultLegend(); |
537 | 9634 | caballero | |
538 | 7459 | azabala | excepType.setLegendLabelField(legend.getLabelField()); |
539 | excepType.setLegendHeightField(legend.getLabelHeightField()); |
||
540 | excepType.setLegendRotationField(legend.getLabelRotationField()); |
||
541 | 10627 | caballero | // DriverException exception = new DriverException(e, excepType);
|
542 | 10814 | jaume | layer.setAvailable(false);
|
543 | layer.addError(null);
|
||
544 | return layer;
|
||
545 | 7459 | azabala | // throw new UnsupportedOperationException(e.getMessage());
|
546 | } catch (Exception e) { |
||
547 | ExceptionDescription excepType = new GenericDriverExceptionType();
|
||
548 | 10627 | caballero | // DriverException exception = new DriverException(e, excepType);
|
549 | 10814 | jaume | layer.addError(null);
|
550 | layer.setAvailable(false);
|
||
551 | return layer;
|
||
552 | 7459 | azabala | } |
553 | 303 | fernando | |
554 | 10814 | jaume | return layer;
|
555 | 1691 | fjp | |
556 | 7459 | azabala | } |
557 | 1691 | fjp | |
558 | 2183 | fernando | /**
|
559 | * @param driver
|
||
560 | * @param layerName
|
||
561 | * @param object
|
||
562 | * @return
|
||
563 | * @throws SQLException
|
||
564 | * @throws DriverIOException
|
||
565 | * @throws IOException
|
||
566 | * @throws DriverLoadException
|
||
567 | * @throws com.hardcode.gdbms.engine.data.driver.DriverException
|
||
568 | * @throws NoSuchTableException
|
||
569 | * @throws ClassNotFoundException
|
||
570 | 10627 | caballero | * @throws ReadDriverException
|
571 | * @throws IOException
|
||
572 | * @throws WriteDriverException
|
||
573 | 4143 | caballero | * @throws
|
574 | 2183 | fernando | */
|
575 | 7459 | azabala | public static FLayer createDisconnectedDBLayer(VectorialJDBCDriver driver, |
576 | String layerName, IProjection proj, ProgressListener listener)
|
||
577 | 10627 | caballero | throws SQLException, |
578 | 7459 | azabala | DriverLoadException, NoSuchTableException, |
579 | 10627 | caballero | ClassNotFoundException, ReadDriverException, IOException, WriteDriverException { |
580 | 7459 | azabala | VectorialDisconnectedDBAdapter dbAdapter = new VectorialDisconnectedDBAdapter();
|
581 | dbAdapter.setDriver(driver); |
||
582 | DataSource ds = dbAdapter.getRecordset();
|
||
583 | ds.start(); |
||
584 | String database = dataSourceFactory.getTempFile();
|
||
585 | String[] fieldNames = new String[ds.getFieldCount() + 1]; |
||
586 | System.arraycopy(ds.getFieldNames(), 0, fieldNames, 1, ds |
||
587 | .getFieldCount()); |
||
588 | fieldNames[0] = "the_geom"; |
||
589 | int[] types = new int[fieldNames.length]; |
||
590 | types[0] = Types.BINARY; |
||
591 | for (int i = 1; i < types.length; i++) { |
||
592 | types[i] = ds.getFieldType(i - 1);
|
||
593 | } |
||
594 | String dsName = dataSourceFactory.createTable(database,
|
||
595 | ds.getPKNames(), fieldNames, types); |
||
596 | 4143 | caballero | |
597 | 7459 | azabala | DBLayerDefinition lyrDef = new DBLayerDefinition();
|
598 | lyrDef.setTableName(dsName); |
||
599 | lyrDef.setName(layerName); |
||
600 | lyrDef.setFieldNames(ds.getFieldNames()); |
||
601 | lyrDef.setFieldGeometry("the_geom");
|
||
602 | lyrDef.setFieldID(ds.getPKNames()[0]);
|
||
603 | lyrDef.setClassToInstantiate("org.hsqldb.jdbcDriver");
|
||
604 | 4143 | caballero | |
605 | 7459 | azabala | dataSourceFactory.addDBDataSourceByTable(dsName, null, 0, "sa", "", |
606 | database, dsName, "GDBMS HSQLDB Transactional driver");
|
||
607 | DataSource local = dataSourceFactory.createRandomDataSource(dsName,
|
||
608 | DataSourceFactory.MANUAL_OPENING); |
||
609 | local.start(); |
||
610 | DataWare dw = local |
||
611 | .getDataWare(DataSourceFactory.DATA_WARE_COHERENT_ROW_ORDER); |
||
612 | dw.start(); |
||
613 | long t1 = System.currentTimeMillis(); |
||
614 | dw.beginTrans(); |
||
615 | 4143 | caballero | |
616 | 7459 | azabala | if (listener == null) { |
617 | listener = new ProgressListener() {
|
||
618 | /**
|
||
619 | * @see com.iver.cit.gvsig.fmap.ProgressListener#progress(int)
|
||
620 | */
|
||
621 | public void progress(int n) { |
||
622 | // do nothing
|
||
623 | } |
||
624 | }; |
||
625 | } |
||
626 | 4143 | caballero | |
627 | 7459 | azabala | for (int i = 0; i < dbAdapter.getShapeCount(); i++) { |
628 | Value[] row = new Value[ds.getFieldCount() + 1]; |
||
629 | 4143 | caballero | |
630 | 7459 | azabala | byte[] bytes = dbAdapter.getShape(i).toWKB(); |
631 | row[0] = ValueFactory.createValue(bytes);
|
||
632 | 4143 | caballero | |
633 | 7459 | azabala | for (int j = 0; j < ds.getFieldCount(); j++) { |
634 | row[j + 1] = ds.getFieldValue(i, j);
|
||
635 | } |
||
636 | 2183 | fernando | |
637 | 7459 | azabala | dw.insertFilledRow(row); |
638 | listener.progress(100 * i / dbAdapter.getShapeCount());
|
||
639 | } |
||
640 | 4143 | caballero | |
641 | 7459 | azabala | long t2 = System.currentTimeMillis(); |
642 | dw.commitTrans(); |
||
643 | long t3 = System.currentTimeMillis(); |
||
644 | System.out.println((t2 - t1) + " - " + (t3 - t2)); |
||
645 | dw.stop(); |
||
646 | local.stop(); |
||
647 | ds.stop(); |
||
648 | VectorialJDBCDriver cacheDriver = (VectorialJDBCDriver) LayerFactory |
||
649 | .getDM().getDriver("HSQLDB Driver");
|
||
650 | Class.forName("org.hsqldb.jdbcDriver"); |
||
651 | 2183 | fernando | |
652 | 7459 | azabala | cacheDriver.setData(java.sql.DriverManager.getConnection( |
653 | "jdbc:hsqldb:file:" + database, "sa", ""), lyrDef); |
||
654 | cacheDriver.setWorkingArea(driver.getWorkingArea()); |
||
655 | return createDBLayer(cacheDriver, layerName, proj);
|
||
656 | 2183 | fernando | } |
657 | 4143 | caballero | |
658 | 732 | fernando | /**
|
659 | * Crea una FLyrComplexRaster que ataca al driver que se pasa como
|
||
660 | * par?metro.
|
||
661 | 9634 | caballero | *
|
662 | 1034 | vcaballero | * @param driver
|
663 | * @param f
|
||
664 | * @param proj
|
||
665 | 9634 | caballero | *
|
666 | 7459 | azabala | * @throws IllegalArgumentException
|
667 | * Si se pasa un driver que no implementa
|
||
668 | * GeorreferencedRasterDriver o NotGeorreferencedRasterDriver
|
||
669 | 732 | fernando | */
|
670 | public static void createLayer(RasterDriver driver, File f, IProjection proj) |
||
671 | 7459 | azabala | throws IllegalArgumentException { |
672 | 732 | fernando | } |
673 | 408 | fernando | |
674 | 732 | fernando | /**
|
675 | 1034 | vcaballero | * Devuelve el DriverManager.
|
676 | 9634 | caballero | *
|
677 | 1034 | vcaballero | * @return DriverManager.
|
678 | 732 | fernando | */
|
679 | public static DriverManager getDM() { |
||
680 | 1839 | fernando | initializeDriverManager(); |
681 | 732 | fernando | |
682 | return driverManager;
|
||
683 | } |
||
684 | 7459 | azabala | |
685 | 4143 | caballero | /**
|
686 | * Devuelve el WriterManager.
|
||
687 | 9634 | caballero | *
|
688 | 4143 | caballero | * @return WriterManager.
|
689 | */
|
||
690 | public static WriterManager getWM() { |
||
691 | initializeWriterManager(); |
||
692 | 732 | fernando | |
693 | 4143 | caballero | return writerManager;
|
694 | } |
||
695 | 7459 | azabala | |
696 | 732 | fernando | /**
|
697 | 1034 | vcaballero | * Inicializa el DriverManager.
|
698 | 732 | fernando | */
|
699 | private static void initializeDriverManager() { |
||
700 | if (driverManager == null) { |
||
701 | driverManager = new DriverManager(); |
||
702 | driverManager.loadDrivers(new File(LayerFactory.driversPath)); |
||
703 | |||
704 | Throwable[] failures = driverManager.getLoadFailures(); |
||
705 | |||
706 | for (int i = 0; i < failures.length; i++) { |
||
707 | 2183 | fernando | logger.error("", failures[i]);
|
708 | 626 | fernando | } |
709 | |||
710 | 1828 | fernando | getDataSourceFactory().setDriverManager(driverManager); |
711 | 2183 | fernando | getDataSourceFactory().initialize(); |
712 | 1836 | fernando | QueryManager.registerQuery(new ArcJoin());
|
713 | 732 | fernando | } |
714 | } |
||
715 | 7459 | azabala | |
716 | 4143 | caballero | /**
|
717 | * Inicializa el DriverManager.
|
||
718 | */
|
||
719 | private static void initializeWriterManager() { |
||
720 | if (writerManager == null) { |
||
721 | writerManager = new WriterManager();
|
||
722 | writerManager.loadWriters(new File(LayerFactory.writersPath)); |
||
723 | 408 | fernando | |
724 | 4143 | caballero | Throwable[] failures = writerManager.getLoadFailures(); |
725 | |||
726 | for (int i = 0; i < failures.length; i++) { |
||
727 | logger.error("", failures[i]);
|
||
728 | } |
||
729 | |||
730 | getDataSourceFactory().setWriterManager(writerManager); |
||
731 | getDataSourceFactory().initialize(); |
||
732 | 7459 | azabala | // QueryManager.registerQuery(new ArcJoin());
|
733 | 4143 | caballero | } |
734 | } |
||
735 | 7459 | azabala | |
736 | 732 | fernando | /**
|
737 | * sets drivers Directory
|
||
738 | 9634 | caballero | *
|
739 | 732 | fernando | * @param path
|
740 | */
|
||
741 | public static void setDriversPath(String path) { |
||
742 | LayerFactory.driversPath = path; |
||
743 | initializeDriverManager(); |
||
744 | } |
||
745 | 7459 | azabala | |
746 | 1773 | fernando | /**
|
747 | 4143 | caballero | * sets writers Directory
|
748 | 9634 | caballero | *
|
749 | 4143 | caballero | * @param path
|
750 | */
|
||
751 | public static void setWritersPath(String path) { |
||
752 | LayerFactory.writersPath = path; |
||
753 | initializeWriterManager(); |
||
754 | } |
||
755 | |||
756 | /**
|
||
757 | 1773 | fernando | * @return Returns the dataSourceFactory.
|
758 | */
|
||
759 | public static DataSourceFactory getDataSourceFactory() { |
||
760 | 7459 | azabala | if (dataSourceFactory == null) { |
761 | 1828 | fernando | dataSourceFactory = new DataSourceFactory();
|
762 | } |
||
763 | 1773 | fernando | return dataSourceFactory;
|
764 | } |
||
765 | 9634 | caballero | |
766 | public static void initialize() { |
||
767 | initializeDriverManager(); |
||
768 | initializeWriterManager(); |
||
769 | } |
||
770 | 214 | fernando | } |