root / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / vectorial / FLayerFileVectorial.java @ 27723
History | View | Annotate | Download (7.98 KB)
1 |
package org.gvsig.fmap.mapcontext.layers.vectorial; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.io.FileNotFoundException; |
5 |
|
6 |
import org.cresques.cts.IProjection; |
7 |
import org.gvsig.fmap.crs.CRSFactory; |
8 |
import org.gvsig.fmap.dal.DALLocator; |
9 |
import org.gvsig.fmap.dal.exception.ReadException; |
10 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
11 |
import org.gvsig.fmap.mapcontext.exceptions.DriverLayerException; |
12 |
import org.gvsig.fmap.mapcontext.exceptions.FileLayerException; |
13 |
import org.gvsig.fmap.mapcontext.exceptions.LegendLayerException; |
14 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
15 |
import org.gvsig.fmap.mapcontext.exceptions.NameLayerException; |
16 |
import org.gvsig.fmap.mapcontext.exceptions.ProjectionLayerException; |
17 |
import org.gvsig.fmap.mapcontext.exceptions.XMLLayerException; |
18 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
19 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
20 |
import org.gvsig.fmap.mapcontext.rendering.legend.LegendFactory; |
21 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.AttrInTableLabelingStrategy; |
22 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingStrategy; |
23 |
import org.gvsig.tools.dynobject.exception.DynMethodException; |
24 |
import org.gvsig.tools.exception.BaseException; |
25 |
|
26 |
import com.iver.utiles.XMLEntity; |
27 |
import com.iver.utiles.XMLException; |
28 |
|
29 |
public class FLayerFileVectorial extends FLyrVect{ |
30 |
private boolean loaded = false; |
31 |
private File dataFile = null; |
32 |
// private FeatureStore featureStore = null;
|
33 |
|
34 |
public FLayerFileVectorial() {
|
35 |
super();
|
36 |
} |
37 |
|
38 |
public FLayerFileVectorial(String name, String fileName,String driverName,String projectionName) throws Exception { |
39 |
super();
|
40 |
|
41 |
this.setName(name);
|
42 |
|
43 |
this.setFileName(fileName);
|
44 |
|
45 |
// this.setDriverByName(driverName);
|
46 |
|
47 |
this.setProjectionByName(projectionName);
|
48 |
} |
49 |
|
50 |
/* Esto deberia ir en el FLyrDefault */
|
51 |
public void setProjectionByName(String projectionName) throws Exception{ |
52 |
IProjection proj = CRSFactory.getCRS(projectionName); |
53 |
if (proj == null) { |
54 |
throw new Exception("No se ha encontrado la proyeccion: "+ projectionName); |
55 |
} |
56 |
this.setProjection(proj);
|
57 |
|
58 |
} |
59 |
|
60 |
public void setFileName(String filePath) throws FileNotFoundException{ |
61 |
if (dataFile != null) { |
62 |
//TODO: que excepcion lanzar???
|
63 |
return;
|
64 |
} |
65 |
File file = new File(filePath); |
66 |
if (!file.exists()) {
|
67 |
throw new FileNotFoundException(filePath); |
68 |
} |
69 |
this.dataFile = file;
|
70 |
} |
71 |
|
72 |
public void setFile(File file) throws FileNotFoundException { |
73 |
if (dataFile != null) { |
74 |
//TODO: que excepcion lanzar???
|
75 |
return;
|
76 |
} |
77 |
if (!file.exists()) {
|
78 |
throw new FileNotFoundException(file.getAbsolutePath()); |
79 |
} |
80 |
this.dataFile = new File(file.getAbsolutePath()); |
81 |
} |
82 |
|
83 |
public String getFileName() { |
84 |
if (this.dataFile == null) { |
85 |
return null; |
86 |
} |
87 |
return this.dataFile.getAbsolutePath(); |
88 |
} |
89 |
|
90 |
|
91 |
public void setFeatureStore(FeatureStore fs) throws LoadLayerException { |
92 |
this.setDataStore(fs);
|
93 |
} |
94 |
|
95 |
// public void setDriverByName(String driverName) throws DriverLoadException {
|
96 |
// this.setDriver(
|
97 |
// (VectorialFileDriver)LayerFactory.getDM().getDriver(driverName)
|
98 |
// );
|
99 |
// }
|
100 |
|
101 |
// public VectorialFileDriver getDriver() {
|
102 |
// return this.fileDriver;
|
103 |
// }
|
104 |
|
105 |
/* FIXME: esto tendria que tener declarado un throws de algo*/
|
106 |
public void wakeUp() throws LoadLayerException { |
107 |
if (!loaded) {
|
108 |
this.load();
|
109 |
} |
110 |
|
111 |
} |
112 |
|
113 |
|
114 |
public void load() throws LoadLayerException { |
115 |
if (this.dataFile == null) { |
116 |
this.setAvailable(false); |
117 |
throw new FileLayerException(getName(),null); |
118 |
} |
119 |
if (this.getName() == null || this.getName().length() == 0) { |
120 |
this.setAvailable(false); |
121 |
throw new NameLayerException(getName(),null); |
122 |
} |
123 |
try {
|
124 |
if (this.getFeatureStore() == null) { |
125 |
this.setAvailable(false); |
126 |
throw new DriverLayerException(getName(),null); |
127 |
} |
128 |
} catch (ReadException e2) {
|
129 |
throw new LoadLayerException(getName(),e2); |
130 |
} catch (DriverLayerException e2) {
|
131 |
throw new LoadLayerException(getName(),e2); |
132 |
} |
133 |
if (this.getProjection() == null) { |
134 |
this.setAvailable(false); |
135 |
throw new ProjectionLayerException(getName(),null); |
136 |
} |
137 |
try {
|
138 |
this.setDataStore(DALLocator.getDataManager().createStore(getFeatureStore().getParameters()));
|
139 |
} catch (Exception e) { |
140 |
throw new LoadLayerException(getName(),e); |
141 |
} |
142 |
|
143 |
try {
|
144 |
this.putLoadSelection();
|
145 |
this.putLoadLegend();
|
146 |
this.initializeLegendDefault();
|
147 |
} catch (Exception e) { |
148 |
this.setAvailable(false); |
149 |
throw new LegendLayerException(getName(),e); |
150 |
} |
151 |
this.cleanLoadOptions();
|
152 |
this.loaded = true; |
153 |
} |
154 |
|
155 |
/* Esto deberia ir en FLyrVect */
|
156 |
private void initializeLegendDefault() throws LegendLayerException, ReadException { |
157 |
if (this.getLegend() == null) { |
158 |
// this.getFeatureStore().getMetadata().
|
159 |
Object obj=null; |
160 |
try {
|
161 |
// FIXME arreglar esto
|
162 |
obj = this.getFeatureStore().getDynValue(
|
163 |
"WithDefaultLegend");
|
164 |
} catch (BaseException e1) {
|
165 |
throw new ReadException(getName(), e1); |
166 |
} |
167 |
if (obj!=null && ((Boolean)obj).booleanValue()) { |
168 |
ILegend legend = null;
|
169 |
try {
|
170 |
legend = (ILegend) getFeatureStore().invokeDynMethod( |
171 |
"defaultLegend", null); |
172 |
} catch (DynMethodException e) {
|
173 |
throw new LegendLayerException(getName(),e); |
174 |
} |
175 |
|
176 |
// WithDefaultLegend aux = (WithDefaultLegend) this.getRecordset().getDriver();
|
177 |
this.setLegend((IVectorLegend)legend);
|
178 |
|
179 |
|
180 |
|
181 |
} else {
|
182 |
this.setLegend(LegendFactory.createSingleSymbolLegend(
|
183 |
this.getShapeType()));
|
184 |
} |
185 |
obj = null;
|
186 |
// try {
|
187 |
// // FIXME Arregla esto
|
188 |
// obj = this.getFeatureStore().getMetadata().getDynValue(
|
189 |
// "LabelingStrategy");
|
190 |
// } catch (BaseException e) {
|
191 |
// throw new ReadException(getName(),e);
|
192 |
// }
|
193 |
if (obj!=null && ((Boolean)obj).booleanValue()){ |
194 |
ILabelingStrategy labeler=null;
|
195 |
try {
|
196 |
labeler = (ILabelingStrategy) getFeatureStore() |
197 |
.invokeDynMethod("labelingStrategy", null); |
198 |
} catch (DynMethodException e) {
|
199 |
throw new LegendLayerException(getName(),e); |
200 |
} |
201 |
if (labeler instanceof AttrInTableLabelingStrategy) { |
202 |
((AttrInTableLabelingStrategy) labeler).setLayer(this);
|
203 |
} |
204 |
|
205 |
this.setLabelingStrategy(labeler);
|
206 |
} |
207 |
|
208 |
} |
209 |
|
210 |
|
211 |
|
212 |
|
213 |
// if (this.getLegend() == null) {
|
214 |
// if (this.getRecordset().getDriver() instanceof WithDefaultLegend) {
|
215 |
// WithDefaultLegend aux = (WithDefaultLegend) this.getRecordset().getDriver();
|
216 |
// this.setLegend((IVectorLegend) aux.getDefaultLegend());
|
217 |
//
|
218 |
// ILabelingStrategy labeler = aux.getDefaultLabelingStrategy();
|
219 |
// if (labeler instanceof AttrInTableLabelingStrategy) {
|
220 |
// ((AttrInTableLabelingStrategy) labeler).setLayer(this);
|
221 |
// }
|
222 |
//
|
223 |
// this.setLabelingStrategy(labeler);
|
224 |
// } else {
|
225 |
// this.setLegend(LegendFactory.createSingleSymbolLegend(
|
226 |
// this.getShapeType()));
|
227 |
// }
|
228 |
// }
|
229 |
} |
230 |
|
231 |
public void setXMLEntity(XMLEntity xml) throws XMLException { |
232 |
IProjection proj = null;
|
233 |
if (xml.contains("proj")) { |
234 |
proj = CRSFactory.getCRS(xml.getStringProperty("proj"));
|
235 |
} |
236 |
else
|
237 |
{ |
238 |
proj = this.getMapContext().getViewPort().getProjection();
|
239 |
} |
240 |
this.setName(xml.getName());
|
241 |
this.setProjection(proj);
|
242 |
// try {
|
243 |
// this.setDriver(
|
244 |
// (VectorialFileDriver)LayerFactory.getDM().getDriver(
|
245 |
// xml.getStringProperty("driverName")
|
246 |
// )
|
247 |
// );
|
248 |
// } catch (DriverLoadException e) {
|
249 |
// throw new XMLException(e);
|
250 |
// } catch (ClassCastException e) {
|
251 |
// throw new XMLException(e);
|
252 |
// }
|
253 |
try {
|
254 |
this.setFileName(xml.getStringProperty("file")); |
255 |
} catch (FileNotFoundException e) { |
256 |
throw new XMLLayerException(getClassName(),e); |
257 |
} |
258 |
|
259 |
super.setXMLEntityNew(xml);
|
260 |
} |
261 |
} |