root / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / vectorial / FLayerVectorialDB.java @ 30038
History | View | Annotate | Download (7.52 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 org.gvsig.fmap.mapcontext.layers.vectorial; |
44 |
|
45 |
import org.cresques.cts.IProjection; |
46 |
import org.gvsig.fmap.crs.CRSFactory; |
47 |
import org.gvsig.fmap.dal.DataStore; |
48 |
import org.gvsig.fmap.dal.exception.ReadException; |
49 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
50 |
import org.gvsig.fmap.mapcontext.exceptions.DriverLayerException; |
51 |
import org.gvsig.fmap.mapcontext.exceptions.LegendLayerException; |
52 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
53 |
import org.gvsig.fmap.mapcontext.exceptions.NameLayerException; |
54 |
import org.gvsig.fmap.mapcontext.exceptions.ProjectionLayerException; |
55 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
56 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
57 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingStrategy; |
58 |
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException; |
59 |
import org.gvsig.tools.dynobject.exception.DynMethodException; |
60 |
import org.gvsig.tools.dynobject.exception.DynMethodNotSupportedException; |
61 |
import org.gvsig.utils.XMLEntity; |
62 |
import org.gvsig.utils.XMLException; |
63 |
|
64 |
|
65 |
|
66 |
public class FLayerVectorialDB extends FLyrVect { |
67 |
private boolean loaded = false; |
68 |
|
69 |
/* Esto deberia ir en el FLyrDefault */
|
70 |
public void setProjectionByName(String projectionName) |
71 |
throws Exception { |
72 |
IProjection proj = CRSFactory.getCRS(projectionName); |
73 |
|
74 |
if (proj == null) { |
75 |
throw new Exception("No se ha encontrado la proyeccion: " + |
76 |
projectionName); |
77 |
} |
78 |
|
79 |
this.setProjection(proj);
|
80 |
} |
81 |
|
82 |
/* FIXME: esto tendria que tener declarado un throws de algo*/
|
83 |
public void wakeUp() throws LoadLayerException { |
84 |
if (!loaded) {
|
85 |
this.load();
|
86 |
} |
87 |
|
88 |
} |
89 |
|
90 |
|
91 |
public void load() throws LoadLayerException { |
92 |
if (this.getName() == null || this.getName().length() == 0) { |
93 |
this.setAvailable(false); |
94 |
throw new NameLayerException(this.getName(),null); |
95 |
} |
96 |
if (this.getFeatureStore() == null) { |
97 |
this.setAvailable(false); |
98 |
//TODO: traducir???
|
99 |
throw new DriverLayerException(this.getName(),null); |
100 |
} |
101 |
if (this.getProjection() == null) { |
102 |
this.setAvailable(false); |
103 |
//TODO: traducir???
|
104 |
throw new ProjectionLayerException(this.getName(),null); |
105 |
} |
106 |
|
107 |
// try {
|
108 |
// try {
|
109 |
// getFeatureStore().load();
|
110 |
// } catch (ReadDriverException e1) {
|
111 |
// throw new LoadLayerException(this.getName(),e1);
|
112 |
// }
|
113 |
// } catch (Exception e) {
|
114 |
// this.setAvailable(false);
|
115 |
// throw new DriverIOException(e);
|
116 |
// }
|
117 |
|
118 |
// try {
|
119 |
// VectorialDBAdapter dbAdapter = new VectorialDBAdapter();
|
120 |
// dbAdapter.setDriver(this.dbDriver);
|
121 |
// this.setSource(dbAdapter);
|
122 |
|
123 |
// } catch (Exception e) {
|
124 |
// this.setAvailable(false);
|
125 |
// throw new DriverIOException(e);
|
126 |
// }
|
127 |
|
128 |
// try {
|
129 |
try {
|
130 |
this.putLoadSelection();
|
131 |
this.putLoadLegend();
|
132 |
this.initializeLegendDefault();
|
133 |
} catch (LegendLayerException e) {
|
134 |
this.setAvailable(false); |
135 |
throw new LegendLayerException(this.getName(),e); |
136 |
} catch (ReadException e) {
|
137 |
this.setAvailable(false); |
138 |
throw new LoadLayerException(this.getName(),e); |
139 |
} catch (XMLException e) {
|
140 |
this.setAvailable(false); |
141 |
throw new LoadLayerException(this.getName(),e); |
142 |
} |
143 |
// } catch (Exception e) {
|
144 |
// this.setAvailable(false);
|
145 |
// //TODO: traducir???
|
146 |
// throw new DriverIOException(e);
|
147 |
// }
|
148 |
this.cleanLoadOptions();
|
149 |
} |
150 |
|
151 |
/* Esto deberia ir en FLyrVect */
|
152 |
private void initializeLegendDefault() throws ReadException, LegendLayerException { |
153 |
if (this.getLegend() == null) { |
154 |
// this.getFeatureStore().getMetadata().
|
155 |
Object obj=null; |
156 |
// // FIXME arraglar esto
|
157 |
obj = this.getFeatureStore().getDynValue(
|
158 |
"WithDefaultLegend");
|
159 |
if (obj!=null && ((Boolean)obj).booleanValue()) { |
160 |
ILegend legend = null;
|
161 |
try {
|
162 |
legend = (ILegend) getFeatureStore().invokeDynMethod("defaultLegend", null); |
163 |
} catch (DynFieldNotFoundException e) {
|
164 |
throw new LegendLayerException(getName(),e); |
165 |
} catch (DynMethodException e) {
|
166 |
throw new LegendLayerException(getName(),e); |
167 |
} |
168 |
|
169 |
// WithDefaultLegend aux = (WithDefaultLegend) this.getRecordset().getDriver();
|
170 |
this.setLegend((IVectorLegend)legend);
|
171 |
|
172 |
|
173 |
|
174 |
} else {
|
175 |
IVectorLegend legend = MapContextLocator.getMapContextManager() |
176 |
.createDefaultVectorLegend(getShapeType()); |
177 |
this.setLegend(legend);
|
178 |
} |
179 |
obj = null;
|
180 |
// FIXME Arreglar esto
|
181 |
obj = this.getFeatureStore().getDynValue("LabelingStrategy"); |
182 |
if (obj!=null && ((Boolean)obj).booleanValue()){ |
183 |
ILabelingStrategy labeler=null;
|
184 |
try {
|
185 |
labeler = (ILabelingStrategy) getFeatureStore() |
186 |
.invokeDynMethod("labelingStrategy", null); |
187 |
} catch (DynMethodNotSupportedException e) {
|
188 |
throw new LegendLayerException(getName(),e); |
189 |
} catch (DynMethodException e) {
|
190 |
throw new LegendLayerException(getName(),e); |
191 |
} |
192 |
labeler.setLayer(this);
|
193 |
|
194 |
this.setLabelingStrategy(labeler);
|
195 |
} |
196 |
|
197 |
} |
198 |
} |
199 |
|
200 |
|
201 |
public void setXMLEntity(XMLEntity xml) throws XMLException { |
202 |
// IProjection proj = null;
|
203 |
//
|
204 |
// if (xml.contains("proj")) {
|
205 |
// proj = CRSFactory.getCRS(xml.getStringProperty("proj"));
|
206 |
// }
|
207 |
// else {
|
208 |
// proj = this.getMapContext().getViewPort().getProjection();
|
209 |
// }
|
210 |
//
|
211 |
// this.setName(xml.getName());
|
212 |
// this.setProjection(proj);
|
213 |
//
|
214 |
// String driverName = xml.getStringProperty("db");
|
215 |
// IVectorialDatabaseDriver driver;
|
216 |
//
|
217 |
// try {
|
218 |
// driver = (IVectorialDatabaseDriver) LayerFactory.getDM()
|
219 |
// .getDriver(driverName);
|
220 |
//
|
221 |
// //Hay que separar la carga de los datos del XMLEntity del load.
|
222 |
// driver.setXMLEntity(xml.getChild(2));
|
223 |
// this.setDriver(driver);
|
224 |
// }
|
225 |
// catch (Exception e) {
|
226 |
// throw new XMLException(e);
|
227 |
// }
|
228 |
//
|
229 |
// super.setXMLEntityNew(xml);
|
230 |
} |
231 |
|
232 |
public void setDataStore(DataStore dataStore) throws LoadLayerException { |
233 |
super.setDataStore(dataStore);
|
234 |
} |
235 |
} |