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