svn-gvsig-desktop / tags / v1_1_Build_1015 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLayerGenericVectorial.java @ 13679
History | View | Annotate | Download (5.57 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.engine.instruction.FieldNotFoundException; |
7 |
import com.iver.cit.gvsig.fmap.DriverException; |
8 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
9 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
10 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
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.IPersistance; |
15 |
import com.iver.utiles.XMLEntity; |
16 |
|
17 |
public class FLayerGenericVectorial extends FLyrVect { |
18 |
private boolean loaded = false; |
19 |
|
20 |
private VectorialDriver vDriver = null; |
21 |
|
22 |
|
23 |
/* Esto deberia ir en el FLyrDefault */
|
24 |
public void setProjectionByName(String projectionName) throws Exception{ |
25 |
IProjection proj = CRSFactory.getCRS(projectionName); |
26 |
if (proj == null) { |
27 |
throw new Exception("No se ha encontrado la proyeccion: "+ projectionName); |
28 |
} |
29 |
this.setProjection(proj);
|
30 |
|
31 |
} |
32 |
|
33 |
|
34 |
public void setDriver(VectorialDriver vDriver) { |
35 |
this.vDriver = vDriver;
|
36 |
} |
37 |
|
38 |
public VectorialDriver getDriver() {
|
39 |
return this.vDriver ; |
40 |
} |
41 |
|
42 |
public void setDriverByName(String driverName) { |
43 |
this.setDriver(
|
44 |
(VectorialDriver)LayerFactory.getDM().getDriver(driverName) |
45 |
); |
46 |
} |
47 |
|
48 |
|
49 |
/* Esto deberia ir en FLyrVect */
|
50 |
private void initializeLegendDefault() throws FieldNotFoundException, DriverException { |
51 |
if (this.getLegend() == null) { |
52 |
if (this.getRecordset().getDriver() instanceof WithDefaultLegend) { |
53 |
WithDefaultLegend aux = (WithDefaultLegend) this.getRecordset().getDriver();
|
54 |
this.setLegend((VectorialLegend) aux.getDefaultLegend());
|
55 |
} else {
|
56 |
this.setLegend(LegendFactory.createSingleSymbolLegend(
|
57 |
this.getShapeType()));
|
58 |
} |
59 |
} |
60 |
} |
61 |
/* FIXME: esto tendria que tener declarado un throws de algo*/
|
62 |
public void wakeUp() { |
63 |
if (!loaded) {
|
64 |
try {
|
65 |
this.load();
|
66 |
} catch (DriverIOException e) {
|
67 |
// TODO Auto-generated catch block
|
68 |
e.printStackTrace(); |
69 |
} |
70 |
} |
71 |
|
72 |
} |
73 |
|
74 |
|
75 |
public void load() throws DriverIOException { |
76 |
if (this.getName() == null || this.getName().length() == 0) { |
77 |
this.setAvailable(false); |
78 |
//TODO: traducir???
|
79 |
throw new DriverIOException("No se ha especificado nombre de capa"); |
80 |
} |
81 |
if (this.vDriver == null) { |
82 |
this.setAvailable(false); |
83 |
//TODO: traducir???
|
84 |
throw new DriverIOException("No se ha especificado driver"); |
85 |
} |
86 |
if (this.getProjection() == null) { |
87 |
this.setAvailable(false); |
88 |
//TODO: traducir???
|
89 |
throw new DriverIOException("No se ha especificado proyeccion"); |
90 |
} |
91 |
|
92 |
VectorialAdapter adapter = null;
|
93 |
try {
|
94 |
adapter = new VectorialDefaultAdapter();
|
95 |
adapter.setDriver((VectorialDriver) this.vDriver);
|
96 |
this.setSource(adapter);
|
97 |
} catch (Exception e) { |
98 |
this.setAvailable(false); |
99 |
throw new DriverIOException(e); |
100 |
} |
101 |
|
102 |
try {
|
103 |
this.putLoadSelection();
|
104 |
this.putLoadLegend();
|
105 |
this.initializeLegendDefault();
|
106 |
|
107 |
} catch (Exception e) { |
108 |
this.setAvailable(false); |
109 |
//TODO: traducir???
|
110 |
throw new DriverIOException(e); |
111 |
} |
112 |
this.cleanLoadOptions();
|
113 |
} |
114 |
|
115 |
public void setXMLEntity(XMLEntity xml) throws XMLException { |
116 |
IProjection proj = null;
|
117 |
if (xml.contains("proj")) { |
118 |
proj = CRSFactory.getCRS(xml.getStringProperty("proj"));
|
119 |
} |
120 |
else
|
121 |
{ |
122 |
proj = this.getMapContext().getViewPort().getProjection();
|
123 |
} |
124 |
this.setName(xml.getName());
|
125 |
this.setProjection(proj);
|
126 |
|
127 |
String driverName = xml.getStringProperty("other"); |
128 |
VectorialDriver driver = null;
|
129 |
try {
|
130 |
driver = (VectorialDriver) LayerFactory.getDM().getDriver(driverName); |
131 |
} catch (DriverLoadException e) {
|
132 |
// Si no existe ese driver, no pasa nada.
|
133 |
// Puede que el desarrollador no quiera que
|
134 |
// aparezca en el cuadro de di?logo y ha metido
|
135 |
// el jar con sus clases en nuestro directorio lib.
|
136 |
// Intentamos cargar esa clase "a pelo".
|
137 |
if (xml.getChild(2).contains("className")) |
138 |
{ |
139 |
String className2 = xml.getChild(2).getStringProperty("className"); |
140 |
try {
|
141 |
driver = (VectorialDriver) Class.forName(className2).newInstance();
|
142 |
} catch (Exception e1) { |
143 |
throw new XMLException(e1); |
144 |
} |
145 |
} |
146 |
} catch (NullPointerException npe) { |
147 |
// Si no existe ese driver, no pasa nada.
|
148 |
// Puede que el desarrollador no quiera que
|
149 |
// aparezca en el cuadro de di?logo y ha metido
|
150 |
// el jar con sus clases en nuestro directorio lib.
|
151 |
// Intentamos cargar esa clase "a pelo".
|
152 |
if (xml.getChild(2).contains("className")) |
153 |
{ |
154 |
String className2 = xml.getChild(2).getStringProperty("className"); |
155 |
try {
|
156 |
driver = (VectorialDriver) Class.forName(className2).newInstance();
|
157 |
} catch (Exception e1) { |
158 |
throw new XMLException(e1); |
159 |
} |
160 |
} |
161 |
} |
162 |
if (driver == null) { |
163 |
throw new XMLException(new Exception("Error al cargar el driver")); |
164 |
} |
165 |
if (driver instanceof IPersistance) |
166 |
{ |
167 |
IPersistance persist = (IPersistance) driver; |
168 |
persist.setXMLEntity(xml.getChild(2));
|
169 |
} |
170 |
this.setDriver(driver);
|
171 |
super.setXMLEntityNew(xml);
|
172 |
} |
173 |
} |