svn-gvsig-desktop / trunk / extensions / extSDE / src / com / iver / cit / gvsig / fmap / layers / SDELayerFactory.java @ 11971
History | View | Annotate | Download (3.54 KB)
1 |
package com.iver.cit.gvsig.fmap.layers; |
---|---|
2 |
|
3 |
import org.cresques.cts.IProjection; |
4 |
|
5 |
import com.hardcode.driverManager.IDelayedDriver; |
6 |
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
7 |
import com.iver.cit.gvsig.fmap.DBDriverExceptionType; |
8 |
import com.iver.cit.gvsig.fmap.DriverException; |
9 |
import com.iver.cit.gvsig.fmap.GenericDriverExceptionType; |
10 |
import com.iver.cit.gvsig.fmap.LegendDriverExceptionType; |
11 |
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend; |
12 |
import com.iver.cit.gvsig.fmap.drivers.sde.IVectorialSDEDriver; |
13 |
import com.iver.cit.gvsig.fmap.layers.DefaultDelayedDriverListener; |
14 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
15 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
16 |
import com.iver.utiles.ExceptionDescription; |
17 |
|
18 |
public class SDELayerFactory { |
19 |
public static SDELayer getLayerSDE(IVectorialSDEDriver driver,String layerName,IProjection proj){ |
20 |
SDELayer capa = new SDELayer();
|
21 |
|
22 |
capa.setName(layerName); |
23 |
VectorialSDEAdapter sdeAdapter = new VectorialSDEAdapter();
|
24 |
sdeAdapter.setDriver(driver); |
25 |
|
26 |
capa.setSource(sdeAdapter); |
27 |
capa.setProjection(proj); |
28 |
try {
|
29 |
if (driver instanceof WithDefaultLegend) { |
30 |
WithDefaultLegend aux = (WithDefaultLegend) driver; |
31 |
sdeAdapter.start(); |
32 |
capa.setLegend((VectorialLegend) aux.getDefaultLegend()); |
33 |
sdeAdapter.stop(); |
34 |
} else {
|
35 |
capa.setLegend(LegendFactory.createSingleSymbolLegend(capa |
36 |
.getShapeType())); |
37 |
} |
38 |
if (driver instanceof IDelayedDriver) |
39 |
{ |
40 |
// Por defecto, los drivers est?n listos para entregar
|
41 |
// features al terminar su initialize. Pero con los drivers
|
42 |
// que implementan IDelayedDriver, el driver es responsable
|
43 |
// de avisar cu?ndo est? listo
|
44 |
capa.getFLayerStatus().setDriverLoaded(false);
|
45 |
((IDelayedDriver) driver).addDriverEventListener(new DefaultDelayedDriverListener(capa));
|
46 |
} |
47 |
// PARCHE: Llamamos a getXmlEntity del driver para que se rellenen
|
48 |
// los valores de host, port, etc, necesarios para un posible reload
|
49 |
//FIXME: Se vuelve a dejar como estaba... el problema esta en el DefaultDBDriver.getXMLEntiy()
|
50 |
// y comentarizemos esto o no, si no arreglamos ese metodo da problemas de persistencia
|
51 |
driver.setXMLEntity(driver.getXMLEntity()); |
52 |
|
53 |
} catch (FieldNotFoundException e) {
|
54 |
LegendDriverExceptionType excepType = |
55 |
new LegendDriverExceptionType("Error al construir la leyenda, campo no encontrado"); |
56 |
//TODO Para hacer esto extensible tiene que usarse puntos
|
57 |
//de extension, y comparar las clases de leyendas registradas
|
58 |
VectorialLegend legend = (VectorialLegend) |
59 |
((WithDefaultLegend)driver).getDefaultLegend(); |
60 |
|
61 |
excepType.setLegendLabelField(legend.getLabelField()); |
62 |
excepType.setLegendHeightField(legend.getLabelHeightField()); |
63 |
excepType.setLegendRotationField(legend.getLabelRotationField()); |
64 |
DriverException exception = new DriverException(e, excepType);
|
65 |
capa.setAvailable(false);
|
66 |
capa.addError(exception); |
67 |
return capa;
|
68 |
// throw new UnsupportedOperationException(e.getMessage());
|
69 |
} catch (DriverException e) {
|
70 |
DBDriverExceptionType excepType = |
71 |
new DBDriverExceptionType();
|
72 |
excepType.setDriverName(driver.getName()); |
73 |
excepType.setTableName(driver.getTableName()); |
74 |
DriverException exception = new DriverException(e, excepType);
|
75 |
capa.addError(exception); |
76 |
capa.setAvailable(false);
|
77 |
return capa;
|
78 |
// throw new UnsupportedOperationException(e.getMessage());
|
79 |
} catch (Exception e) { |
80 |
ExceptionDescription excepType = new GenericDriverExceptionType();
|
81 |
DriverException exception = new DriverException(e, excepType);
|
82 |
capa.addError(exception); |
83 |
capa.setAvailable(false);
|
84 |
return capa;
|
85 |
} |
86 |
|
87 |
return capa;
|
88 |
} |
89 |
|
90 |
} |