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