svn-gvsig-desktop / tags / v2_0_0_Build_2057 / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / impl / DefaultMapContextManager.java @ 39172
History | View | Annotate | Download (20.3 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2009 {DiSiD Technologies} {Create Manager to register MapContextDrawer implementation}
|
26 |
*/
|
27 |
package org.gvsig.fmap.mapcontext.impl; |
28 |
|
29 |
import java.awt.Color; |
30 |
import java.awt.Font; |
31 |
import java.io.File; |
32 |
import java.io.FileFilter; |
33 |
import java.io.FileInputStream; |
34 |
import java.io.FileNotFoundException; |
35 |
import java.io.IOException; |
36 |
import java.lang.reflect.Method; |
37 |
import java.util.Collections; |
38 |
import java.util.HashMap; |
39 |
import java.util.Map; |
40 |
|
41 |
import org.cresques.cts.IProjection; |
42 |
import org.slf4j.Logger; |
43 |
import org.slf4j.LoggerFactory; |
44 |
|
45 |
import org.gvsig.fmap.crs.CRSFactory; |
46 |
import org.gvsig.fmap.dal.DataServerExplorer; |
47 |
import org.gvsig.fmap.dal.DataStore; |
48 |
import org.gvsig.fmap.dal.DataStoreParameters; |
49 |
import org.gvsig.fmap.dal.exception.DataException; |
50 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
51 |
import org.gvsig.fmap.dal.feature.FeatureType; |
52 |
import org.gvsig.fmap.mapcontext.MapContextDrawer; |
53 |
import org.gvsig.fmap.mapcontext.MapContextException; |
54 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
55 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
56 |
import org.gvsig.fmap.mapcontext.MapContextRuntimeException; |
57 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
58 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
59 |
import org.gvsig.fmap.mapcontext.layers.LayerFactory; |
60 |
import org.gvsig.fmap.mapcontext.layers.vectorial.GraphicLayer; |
61 |
import org.gvsig.fmap.mapcontext.layers.vectorial.impl.DefaultGraphicLayer; |
62 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
63 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
64 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorialUniqueValueLegend; |
65 |
import org.gvsig.fmap.mapcontext.rendering.legend.driver.ILegendReader; |
66 |
import org.gvsig.fmap.mapcontext.rendering.legend.driver.ILegendWriter; |
67 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingStrategy; |
68 |
import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol; |
69 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
70 |
import org.gvsig.fmap.mapcontext.rendering.symbols.IWarningSymbol; |
71 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolException; |
72 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager; |
73 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolPreferences; |
74 |
import org.gvsig.tools.ToolsLocator; |
75 |
import org.gvsig.tools.dynobject.exception.DynMethodException; |
76 |
import org.gvsig.tools.dynobject.exception.DynMethodNotSupportedException; |
77 |
import org.gvsig.tools.persistence.PersistenceManager; |
78 |
|
79 |
/**
|
80 |
* Default implementation of the {@link MapContextManager}.
|
81 |
*
|
82 |
* @author <a href="mailto:cordinyana@gvsig.org">C?sar Ordi?ana</a>
|
83 |
*/
|
84 |
public class DefaultMapContextManager implements MapContextManager { |
85 |
|
86 |
private static final Logger logger = LoggerFactory |
87 |
.getLogger(DefaultMapContextManager.class); |
88 |
|
89 |
private Class drawerClazz = DefaultMapContextDrawer.class; |
90 |
|
91 |
private Map legends = Collections.synchronizedMap(new HashMap()); |
92 |
|
93 |
private Map legendReaders = Collections.synchronizedMap(new HashMap()); |
94 |
|
95 |
private Map legendWriters = Collections.synchronizedMap(new HashMap()); |
96 |
|
97 |
private String defaultVectorLegend; |
98 |
|
99 |
public SymbolManager getSymbolManager() {
|
100 |
return MapContextLocator.getSymbolManager();
|
101 |
} |
102 |
|
103 |
private SymbolPreferences getSymbolPreferences() {
|
104 |
return getSymbolManager().getSymbolPreferences();
|
105 |
} |
106 |
|
107 |
public String getSymbolLibraryPath() { |
108 |
return getSymbolPreferences().getSymbolLibraryPath();
|
109 |
} |
110 |
|
111 |
public void setSymbolLibraryPath(String symbolLibraryPath) { |
112 |
getSymbolPreferences().setSymbolLibraryPath(symbolLibraryPath); |
113 |
} |
114 |
|
115 |
public void resetSymbolLibraryPath() { |
116 |
getSymbolPreferences().resetSymbolLibraryPath(); |
117 |
} |
118 |
|
119 |
public Color getDefaultSymbolColor() { |
120 |
return getSymbolPreferences().getDefaultSymbolColor();
|
121 |
} |
122 |
|
123 |
public Color getDefaultSymbolFillColor() { |
124 |
return getSymbolPreferences().getDefaultSymbolFillColor();
|
125 |
} |
126 |
|
127 |
public Font getDefaultSymbolFont() { |
128 |
return getSymbolPreferences().getDefaultSymbolFont();
|
129 |
} |
130 |
|
131 |
public String getSymbolFileExtension() { |
132 |
return getSymbolPreferences().getSymbolFileExtension();
|
133 |
} |
134 |
|
135 |
public boolean isDefaultSymbolFillColorAleatory() { |
136 |
return getSymbolPreferences().isDefaultSymbolFillColorAleatory();
|
137 |
} |
138 |
|
139 |
public void resetDefaultSymbolColor() { |
140 |
getSymbolPreferences().resetDefaultSymbolColor(); |
141 |
} |
142 |
|
143 |
public void resetDefaultSymbolFillColor() { |
144 |
getSymbolPreferences().resetDefaultSymbolFillColor(); |
145 |
} |
146 |
|
147 |
public void resetDefaultSymbolFillColorAleatory() { |
148 |
getSymbolPreferences().resetDefaultSymbolFillColorAleatory(); |
149 |
} |
150 |
|
151 |
public void resetDefaultSymbolFont() { |
152 |
getSymbolPreferences().resetDefaultSymbolFont(); |
153 |
} |
154 |
|
155 |
public void setDefaultSymbolColor(Color defaultSymbolColor) { |
156 |
getSymbolPreferences().setDefaultSymbolColor(defaultSymbolColor); |
157 |
} |
158 |
|
159 |
public void setDefaultSymbolFillColor(Color defaultSymbolFillColor) { |
160 |
getSymbolPreferences().setDefaultSymbolFillColor(defaultSymbolFillColor); |
161 |
} |
162 |
|
163 |
public void setDefaultSymbolFillColorAleatory( |
164 |
boolean defaultSymbolFillColorAleatory) {
|
165 |
getSymbolPreferences().setDefaultSymbolFillColorAleatory( |
166 |
defaultSymbolFillColorAleatory); |
167 |
} |
168 |
|
169 |
public void setDefaultSymbolFont(Font defaultSymbolFont) { |
170 |
getSymbolPreferences().setDefaultSymbolFont(defaultSymbolFont); |
171 |
} |
172 |
|
173 |
public void setSymbolFileExtension(String extension) { |
174 |
getSymbolPreferences().setSymbolFileExtension(extension); |
175 |
} |
176 |
|
177 |
public int getDefaultCartographicSupportMeasureUnit() { |
178 |
return getSymbolPreferences().getDefaultCartographicSupportMeasureUnit();
|
179 |
} |
180 |
|
181 |
public void setDefaultCartographicSupportMeasureUnit( |
182 |
int defaultCartographicSupportMeasureUnit) {
|
183 |
getSymbolPreferences().setDefaultCartographicSupportMeasureUnit( |
184 |
defaultCartographicSupportMeasureUnit); |
185 |
} |
186 |
|
187 |
public int getDefaultCartographicSupportReferenceSystem() { |
188 |
return getSymbolPreferences().getDefaultCartographicSupportReferenceSystem();
|
189 |
} |
190 |
|
191 |
public void setDefaultCartographicSupportReferenceSystem( |
192 |
int defaultCartographicSupportReferenceSystem) {
|
193 |
getSymbolPreferences().setDefaultCartographicSupportReferenceSystem( |
194 |
defaultCartographicSupportReferenceSystem); |
195 |
} |
196 |
|
197 |
public MapContextDrawer createMapContextDrawerInstance(Class drawerClazz) |
198 |
throws MapContextException {
|
199 |
return createMapContextDrawerInstance(drawerClazz, "NONE"); |
200 |
} |
201 |
|
202 |
public MapContextDrawer createDefaultMapContextDrawerInstance()
|
203 |
throws MapContextException {
|
204 |
|
205 |
return createMapContextDrawerInstance(drawerClazz, "default"); |
206 |
} |
207 |
|
208 |
private MapContextDrawer createMapContextDrawerInstance(Class drawerClazz, |
209 |
String name) throws RegisteredClassInstantiationException { |
210 |
try {
|
211 |
return (MapContextDrawer) drawerClazz.newInstance();
|
212 |
} catch (Exception ex) { |
213 |
throw new RegisteredClassInstantiationException( |
214 |
MapContextDrawer.class, drawerClazz, name, ex); |
215 |
} |
216 |
} |
217 |
|
218 |
public void setDefaultMapContextDrawer(Class drawerClazz) |
219 |
throws MapContextException {
|
220 |
|
221 |
validateMapContextDrawer(drawerClazz); |
222 |
this.drawerClazz = drawerClazz;
|
223 |
} |
224 |
|
225 |
public void validateMapContextDrawer(Class drawerClazz) |
226 |
throws MapContextException {
|
227 |
if (!MapContextDrawer.class.isAssignableFrom(drawerClazz)) {
|
228 |
throw new InvalidRegisteredClassException(MapContextDrawer.class, |
229 |
drawerClazz, "UNKNOWN");
|
230 |
} |
231 |
} |
232 |
|
233 |
public GraphicLayer createGraphicsLayer(IProjection projection) {
|
234 |
DefaultGraphicLayer layer = new DefaultGraphicLayer();
|
235 |
try {
|
236 |
layer.initialize(projection); |
237 |
layer.setLegend((IVectorLegend)createLegend(IVectorialUniqueValueLegend.LEGEND_NAME)); |
238 |
} catch (Exception e) { |
239 |
logger.error("Error initializing the graphics layer", e);
|
240 |
} |
241 |
return layer;
|
242 |
} |
243 |
|
244 |
public String getDefaultVectorLegend() { |
245 |
return defaultVectorLegend;
|
246 |
} |
247 |
|
248 |
public void setDefaultVectorLegend(String defaultVectorLegend) { |
249 |
this.defaultVectorLegend = defaultVectorLegend;
|
250 |
} |
251 |
|
252 |
public void registerLegend(String legendName, Class legendClass) |
253 |
throws MapContextRuntimeException {
|
254 |
|
255 |
if (legendClass == null || !ILegend.class.isAssignableFrom(legendClass)) { |
256 |
throw new InvalidRegisteredClassException(ILegend.class, |
257 |
legendClass, legendName); |
258 |
} |
259 |
|
260 |
legends.put(legendName, legendClass); |
261 |
} |
262 |
|
263 |
public ILegend createLegend(String legendName) |
264 |
throws MapContextRuntimeException {
|
265 |
Class legendClass = (Class) legends.get(legendName); |
266 |
|
267 |
if (legendClass != null) { |
268 |
try {
|
269 |
return (ILegend) legendClass.newInstance();
|
270 |
} catch (InstantiationException e) { |
271 |
throw new RegisteredClassInstantiationException(ILegend.class, |
272 |
legendClass, legendName, e); |
273 |
} catch (IllegalAccessException e) { |
274 |
throw new RegisteredClassInstantiationException(ILegend.class, |
275 |
legendClass, legendName, e); |
276 |
} |
277 |
} |
278 |
return null; |
279 |
} |
280 |
|
281 |
public IVectorLegend createDefaultVectorLegend(int shapeType) |
282 |
throws MapContextRuntimeException {
|
283 |
try {
|
284 |
// Create legend
|
285 |
IVectorLegend legend = |
286 |
(IVectorLegend) createLegend(getDefaultVectorLegend()); |
287 |
if (legend == null) { |
288 |
return null; |
289 |
} |
290 |
// Set legend values
|
291 |
legend.setShapeType(shapeType); |
292 |
legend.setDefaultSymbol(getSymbolManager().createSymbol(shapeType)); |
293 |
return legend;
|
294 |
} catch(Exception e) { |
295 |
throw new MapContextRuntimeException(e); |
296 |
} |
297 |
} |
298 |
|
299 |
public void registerLegendReader(String format, Class readerClass) |
300 |
throws MapContextRuntimeException {
|
301 |
if (readerClass == null |
302 |
|| !ILegendReader.class.isAssignableFrom(readerClass)) { |
303 |
throw new InvalidRegisteredClassException(ILegendReader.class, |
304 |
readerClass, format); |
305 |
} |
306 |
|
307 |
legendReaders.put(format, readerClass); |
308 |
} |
309 |
|
310 |
public ILegendReader createLegendReader(String format) |
311 |
throws MapContextRuntimeException {
|
312 |
Class legendReaderClazz = (Class) legendReaders.get(format); |
313 |
|
314 |
if (legendReaderClazz != null) { |
315 |
try {
|
316 |
return (ILegendReader) legendReaderClazz.newInstance();
|
317 |
} catch (InstantiationException e) { |
318 |
throw new RegisteredClassInstantiationException( |
319 |
ILegendReader.class, legendReaderClazz, format, e); |
320 |
} catch (IllegalAccessException e) { |
321 |
throw new RegisteredClassInstantiationException( |
322 |
ILegendReader.class, legendReaderClazz, format, e); |
323 |
} |
324 |
} |
325 |
return null; |
326 |
} |
327 |
|
328 |
public void registerLegendWriter(String legendName, String format, |
329 |
Class writerClass) throws MapContextRuntimeException { |
330 |
if (writerClass == null |
331 |
|| !ILegendWriter.class.isAssignableFrom(writerClass)) { |
332 |
throw new InvalidRegisteredClassException(ILegendWriter.class, |
333 |
writerClass, format.concat("-").concat(legendName));
|
334 |
} |
335 |
|
336 |
Map legendFormatWriters = (Map) legendWriters.get(format); |
337 |
|
338 |
synchronized (legendWriters) {
|
339 |
if (legendFormatWriters == null) { |
340 |
legendFormatWriters = Collections
|
341 |
.synchronizedMap(new HashMap()); |
342 |
legendWriters.put(format, legendFormatWriters); |
343 |
} |
344 |
} |
345 |
|
346 |
legendFormatWriters.put(legendName, writerClass); |
347 |
} |
348 |
|
349 |
public ILegendWriter createLegendWriter(String legendName, String format) |
350 |
throws MapContextRuntimeException {
|
351 |
Map legendFormatWriters = getLegendWritersForFormat(format);
|
352 |
|
353 |
if (legendFormatWriters != null) { |
354 |
Class legendWriterClazz = (Class) legendFormatWriters |
355 |
.get(legendName); |
356 |
|
357 |
if (legendWriterClazz != null) { |
358 |
try {
|
359 |
return (ILegendWriter) legendWriterClazz.newInstance();
|
360 |
} catch (InstantiationException e) { |
361 |
throw new RegisteredClassInstantiationException( |
362 |
ILegendWriter.class, legendWriterClazz, format |
363 |
.concat("-").concat(legendName), e);
|
364 |
} catch (IllegalAccessException e) { |
365 |
throw new RegisteredClassInstantiationException( |
366 |
ILegendWriter.class, legendWriterClazz, format |
367 |
.concat("-").concat(legendName), e);
|
368 |
} |
369 |
} |
370 |
} |
371 |
return null; |
372 |
} |
373 |
|
374 |
private Map getLegendWritersForFormat(String format) { |
375 |
return (Map) legendWriters.get(format); |
376 |
} |
377 |
|
378 |
public IMultiLayerSymbol createMultiLayerSymbol(int shapeType) |
379 |
throws MapContextRuntimeException {
|
380 |
return getSymbolManager().createMultiLayerSymbol(shapeType);
|
381 |
} |
382 |
|
383 |
public IMultiLayerSymbol createMultiLayerSymbol(String symbolName) |
384 |
throws MapContextRuntimeException {
|
385 |
return getSymbolManager().createMultiLayerSymbol(symbolName);
|
386 |
} |
387 |
|
388 |
public ISymbol createSymbol(int shapeType, Color color) |
389 |
throws MapContextRuntimeException {
|
390 |
return getSymbolManager().createSymbol(shapeType, color);
|
391 |
} |
392 |
|
393 |
public ISymbol createSymbol(int shapeType) |
394 |
throws MapContextRuntimeException {
|
395 |
return getSymbolManager().createSymbol(shapeType);
|
396 |
} |
397 |
|
398 |
public ISymbol createSymbol(String symbolName, Color color) |
399 |
throws MapContextRuntimeException {
|
400 |
return getSymbolManager().createSymbol(symbolName, color);
|
401 |
} |
402 |
|
403 |
public ISymbol createSymbol(String symbolName) |
404 |
throws MapContextRuntimeException {
|
405 |
return getSymbolManager().createSymbol(symbolName);
|
406 |
} |
407 |
|
408 |
public IWarningSymbol getWarningSymbol(String message, String symbolDesc, |
409 |
int symbolDrawExceptionType) throws MapContextRuntimeException { |
410 |
return getSymbolManager().getWarningSymbol(message, symbolDesc,
|
411 |
symbolDrawExceptionType); |
412 |
} |
413 |
|
414 |
public ISymbol[] loadSymbols(File folder, FileFilter filter) |
415 |
throws SymbolException {
|
416 |
return getSymbolManager().loadSymbols(folder, filter);
|
417 |
} |
418 |
|
419 |
public ISymbol[] loadSymbols(File folder) throws SymbolException { |
420 |
return getSymbolManager().loadSymbols(folder);
|
421 |
} |
422 |
|
423 |
public void registerMultiLayerSymbol(String symbolName, Class symbolClass) |
424 |
throws MapContextRuntimeException {
|
425 |
getSymbolManager().registerMultiLayerSymbol(symbolName, symbolClass); |
426 |
} |
427 |
|
428 |
public void registerMultiLayerSymbol(String symbolName, int[] shapeTypes, |
429 |
Class symbolClass) throws MapContextRuntimeException { |
430 |
getSymbolManager().registerMultiLayerSymbol(symbolName, shapeTypes, |
431 |
symbolClass); |
432 |
} |
433 |
|
434 |
public void registerSymbol(String symbolName, Class symbolClass) |
435 |
throws MapContextRuntimeException {
|
436 |
getSymbolManager().registerSymbol(symbolName, symbolClass); |
437 |
} |
438 |
|
439 |
public void registerSymbol(String symbolName, int[] shapeTypes, |
440 |
Class symbolClass) throws MapContextException { |
441 |
getSymbolManager().registerSymbol(symbolName, shapeTypes, symbolClass); |
442 |
} |
443 |
|
444 |
public void saveSymbol(ISymbol symbol, String fileName, File folder, |
445 |
boolean overwrite) throws SymbolException { |
446 |
getSymbolManager().saveSymbol(symbol, fileName, folder, overwrite); |
447 |
} |
448 |
|
449 |
public void saveSymbol(ISymbol symbol, String fileName, File folder) |
450 |
throws SymbolException {
|
451 |
getSymbolManager().saveSymbol(symbol, fileName, folder); |
452 |
} |
453 |
|
454 |
public FLayer createLayer(String layerName, DataStoreParameters parameters) |
455 |
throws LoadLayerException {
|
456 |
return LayerFactory.getInstance().createLayer(layerName, parameters);
|
457 |
} |
458 |
|
459 |
public FLayer createLayer(String layerName, DataStore store) |
460 |
throws LoadLayerException {
|
461 |
return LayerFactory.getInstance().createLayer(layerName, store);
|
462 |
} |
463 |
|
464 |
public ILegend getLegend(DataStore dataStore) {
|
465 |
ILegend legend = null;
|
466 |
|
467 |
File file = getResourcePathByReflection(dataStore, SymbolManager.LEGEND_FILE_EXTENSION.substring(1)); |
468 |
try{
|
469 |
if ((file != null) && (file.exists())){ |
470 |
PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager(); |
471 |
FileInputStream is = new FileInputStream(file); |
472 |
legend = (ILegend) persistenceManager.getObject(is); |
473 |
is.close(); |
474 |
} |
475 |
} catch (FileNotFoundException e){ |
476 |
logger.error("Legend not found", e);
|
477 |
} catch (IOException e) { |
478 |
logger.error("Error reading the legend", e);
|
479 |
} |
480 |
|
481 |
//If the legend is null, next option is to check if the store has the getLegend method
|
482 |
if (legend == null){ |
483 |
try {
|
484 |
legend = (IVectorLegend) dataStore.invokeDynMethod( |
485 |
"getLegend", null); |
486 |
} catch (DynMethodNotSupportedException e) {
|
487 |
logger.debug("This store {} does not provide a legend.",
|
488 |
dataStore.getName()); |
489 |
} catch (DynMethodException e) {
|
490 |
logger.error( |
491 |
"Can't load the specific legend provided for the store {}.",
|
492 |
dataStore.getName(), e); |
493 |
} |
494 |
} |
495 |
|
496 |
//If legend is null, last step is just try to create the legend by default
|
497 |
if( legend == null ) { |
498 |
FeatureType featureType; |
499 |
try {
|
500 |
featureType = (((FeatureStore)dataStore).getDefaultFeatureType()); |
501 |
int indexGeom = featureType.getDefaultGeometryAttributeIndex();
|
502 |
int typeShape = featureType.getAttributeDescriptor(indexGeom).getGeometryType();
|
503 |
legend = createDefaultVectorLegend(typeShape); |
504 |
} catch (DataException e) {
|
505 |
logger.error("Error getting the default feature type", e);
|
506 |
} |
507 |
} |
508 |
|
509 |
return legend;
|
510 |
} |
511 |
|
512 |
public ILabelingStrategy getLabelingStrategy(DataStore dataStore) {
|
513 |
ILabelingStrategy labelingStrategy = null;
|
514 |
|
515 |
File file = getResourcePathByReflection(dataStore, SymbolManager.LABELINGSTRATEGY_FILE_EXTENSION.substring(1)); |
516 |
try{
|
517 |
if ((file != null) && (file.exists())){ |
518 |
PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager(); |
519 |
FileInputStream is = new FileInputStream(file); |
520 |
labelingStrategy = (ILabelingStrategy) persistenceManager.getObject(is); |
521 |
is.close(); |
522 |
} |
523 |
} catch (FileNotFoundException e){ |
524 |
logger.error("Label strategy not found", e);
|
525 |
} catch (IOException e) { |
526 |
logger.error("Error reading the labeling strategy", e);
|
527 |
} |
528 |
|
529 |
//If the legend is null, next option is to check if the store has the getLegend method
|
530 |
if (labelingStrategy == null){ |
531 |
try {
|
532 |
labelingStrategy = |
533 |
(ILabelingStrategy) dataStore.invokeDynMethod("getLabeling",
|
534 |
null);
|
535 |
} catch (DynMethodNotSupportedException e1) {
|
536 |
labelingStrategy = null;
|
537 |
} catch (DynMethodException e1) {
|
538 |
logger.error("Can't load the specific lebeling strategy provided for the datastore {}.",
|
539 |
dataStore.getName(), |
540 |
e1); |
541 |
} |
542 |
} |
543 |
|
544 |
return labelingStrategy;
|
545 |
} |
546 |
|
547 |
private File getResourcePathByReflection(DataStore dataStore, String resource){ |
548 |
//Loading the file from a store based on file
|
549 |
DataServerExplorer dataServerExplorer = null;
|
550 |
try {
|
551 |
dataServerExplorer = dataStore.getExplorer(); |
552 |
Class[] args = new Class[2]; |
553 |
args[0] = DataStore.class;
|
554 |
args[1] = String.class; |
555 |
Method method = dataStore.getExplorer().getClass().getMethod("getResourcePath", args); |
556 |
if (method != null){ |
557 |
Object[] params = new Object[2]; |
558 |
params[0] = dataStore;
|
559 |
params[1] = resource;
|
560 |
return (File)method.invoke(dataServerExplorer, params); |
561 |
} |
562 |
} catch (Exception e) { |
563 |
logger.debug( |
564 |
"Can't load the specific legend provided by the explorer "
|
565 |
+ dataServerExplorer, e); |
566 |
} |
567 |
return null; |
568 |
} |
569 |
|
570 |
private Map iconLayers = new HashMap(); // (Map<String storeProviderName, String iconName>) |
571 |
|
572 |
public void registerIconLayer(String storeProviderName, String iconName) { |
573 |
if( storeProviderName == null || iconName == null ) { |
574 |
logger.info("registerIconLayer, storeProviderName or iconName are null");
|
575 |
return;
|
576 |
} |
577 |
if( storeProviderName.trim().length()==0 || iconName.trim().length()==0 ) { |
578 |
logger.info("registerIconLayer, invalid storeProviderName or iconName");
|
579 |
return;
|
580 |
} |
581 |
iconLayers.put(storeProviderName.trim().toLowerCase(), iconName); |
582 |
} |
583 |
|
584 |
public String getIconLayer(DataStore store) { |
585 |
String name = (String) iconLayers.get(store.getProviderName().trim().toLowerCase()); |
586 |
if( name == null ) { |
587 |
return "layer-icon"; |
588 |
} |
589 |
return name;
|
590 |
} |
591 |
|
592 |
/* (non-Javadoc)
|
593 |
* @see org.gvsig.fmap.mapcontext.MapContextManager#getDefaultCRS()
|
594 |
*/
|
595 |
public IProjection getDefaultCRS() {
|
596 |
return CRSFactory.getCRS("EPSG:4326"); |
597 |
} |
598 |
} |