Revision 44297 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/impl/DefaultMapContextManager.java
DefaultMapContextManager.java | ||
---|---|---|
73 | 73 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager; |
74 | 74 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolPreferences; |
75 | 75 |
import org.gvsig.tools.ToolsLocator; |
76 |
import org.gvsig.tools.dispose.DisposeUtils; |
|
77 | 76 |
import org.gvsig.tools.dynobject.exception.DynMethodException; |
78 | 77 |
import org.gvsig.tools.dynobject.exception.DynMethodNotSupportedException; |
79 | 78 |
import org.gvsig.tools.observer.Notification; |
80 | 79 |
import org.gvsig.tools.observer.ObservableHelper; |
81 | 80 |
import org.gvsig.tools.observer.Observer; |
82 | 81 |
import org.gvsig.tools.persistence.PersistenceManager; |
83 |
import org.gvsig.tools.util.ResourcesStorage.Resource; |
|
82 |
import org.gvsig.tools.resourcesstorage.ResourcesStorage; |
|
83 |
import org.gvsig.tools.resourcesstorage.ResourcesStorage.Resource; |
|
84 | 84 |
import org.slf4j.Logger; |
85 | 85 |
import org.slf4j.LoggerFactory; |
86 | 86 |
|
... | ... | |
91 | 91 |
*/ |
92 | 92 |
public class DefaultMapContextManager implements MapContextManager { |
93 | 93 |
|
94 |
private static final Logger logger = LoggerFactory
|
|
94 |
private static final Logger LOGGER = LoggerFactory
|
|
95 | 95 |
.getLogger(DefaultMapContextManager.class); |
96 | 96 |
|
97 | 97 |
private Class drawerClazz = DefaultMapContextDrawer.class; |
... | ... | |
104 | 104 |
|
105 | 105 |
private String defaultVectorLegend; |
106 | 106 |
|
107 |
private ObservableHelper observableHelper = new ObservableHelper(); |
|
107 |
private final ObservableHelper observableHelper = new ObservableHelper();
|
|
108 | 108 |
|
109 | 109 |
private File colorTableLibraryFolder = null; |
110 | 110 |
|
... | ... | |
256 | 256 |
layer.initialize(projection); |
257 | 257 |
layer.setLegend((IVectorLegend) createLegend(IVectorialUniqueValueLegend.LEGEND_NAME)); |
258 | 258 |
} catch (Exception e) { |
259 |
logger.error("Error initializing the graphics layer", e);
|
|
259 |
LOGGER.error("Error initializing the graphics layer", e);
|
|
260 | 260 |
} |
261 | 261 |
return (GraphicLayer) notifyObservers(CREATE_GRAPHICS_LAYER, layer).getValue(); |
262 | 262 |
} |
... | ... | |
578 | 578 |
return (FLayer) notifyObservers(CREATE_LAYER, layer).getValue(); |
579 | 579 |
} |
580 | 580 |
|
581 |
@Override |
|
581 | 582 |
public ILegend getLegend(DataStore dataStore) { |
582 | 583 |
ILegend legend = null; |
583 |
|
|
584 |
Resource resource = getResource(dataStore, SymbolManager.LEGEND_FILE_EXTENSION.substring(1)); |
|
585 |
try { |
|
586 |
if ((resource != null) && (resource.exists())) { |
|
587 |
PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager(); |
|
588 |
InputStream is = resource.asInputStream(); |
|
589 |
legend = (ILegend) persistenceManager.getObject(is); |
|
590 |
is.close(); |
|
584 |
ResourcesStorage resourcesStorage = dataStore.getResourcesStorage(); |
|
585 |
if( resourcesStorage!=null ) { |
|
586 |
Resource resource = resourcesStorage.getResource(SymbolManager.LEGEND_FILE_EXTENSION.substring(1)); |
|
587 |
try { |
|
588 |
if ((resource != null) && (resource.exists())) { |
|
589 |
PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager(); |
|
590 |
InputStream is = resource.asInputStream(); |
|
591 |
legend = (ILegend) persistenceManager.getObject(is); |
|
592 |
is.close(); |
|
593 |
} |
|
594 |
} catch (Exception e) { |
|
595 |
LOGGER.warn("Can't loasd legend", e); |
|
596 |
} finally { |
|
597 |
IOUtils.closeQuietly(resource); |
|
591 | 598 |
} |
592 |
} catch (Exception e) { |
|
593 |
logger.warn("Can't loasd legend", e); |
|
594 |
} finally { |
|
595 |
IOUtils.closeQuietly(resource); |
|
596 | 599 |
} |
597 |
|
|
598 | 600 |
//If the legend is null, next option is to check if the store has the getLegend method |
599 | 601 |
if (legend == null) { |
600 | 602 |
try { |
601 | 603 |
legend = (IVectorLegend) dataStore.invokeDynMethod("getLegend", null); |
602 | 604 |
} catch (DynMethodNotSupportedException e) { |
603 |
logger.debug("This store {} does not provide a legend.",
|
|
605 |
LOGGER.debug("This store {} does not provide a legend.",
|
|
604 | 606 |
dataStore.getName()); |
605 | 607 |
} catch (DynMethodException e) { |
606 |
logger.error(
|
|
608 |
LOGGER.error(
|
|
607 | 609 |
"Can't load the specific legend provided for the store {}.", |
608 | 610 |
dataStore.getName(), e); |
609 | 611 |
} |
... | ... | |
621 | 623 |
int typeShape = featureType.getAttributeDescriptor(indexGeom).getGeometryType(); |
622 | 624 |
legend = createDefaultVectorLegend(typeShape); |
623 | 625 |
} catch (DataException e) { |
624 |
logger.error("Error getting the default feature type", e);
|
|
626 |
LOGGER.error("Error getting the default feature type", e);
|
|
625 | 627 |
} |
626 | 628 |
} |
627 | 629 |
|
628 | 630 |
return legend; |
629 | 631 |
} |
630 | 632 |
|
633 |
@Override |
|
631 | 634 |
public ILabelingStrategy getLabelingStrategy(DataStore dataStore) { |
632 | 635 |
ILabelingStrategy labelingStrategy = null; |
633 | 636 |
|
634 |
Resource resource = getResource(dataStore, SymbolManager.LABELINGSTRATEGY_FILE_EXTENSION.substring(1)); |
|
635 |
try { |
|
636 |
if ((resource != null) && (resource.exists())) { |
|
637 |
PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager(); |
|
638 |
InputStream is = resource.asInputStream(); |
|
639 |
labelingStrategy = (ILabelingStrategy) persistenceManager.getObject(is); |
|
640 |
is.close(); |
|
637 |
ResourcesStorage resourcesStorage = dataStore.getResourcesStorage(); |
|
638 |
if( resourcesStorage!=null ) { |
|
639 |
Resource resource = resourcesStorage.getResource(SymbolManager.LABELINGSTRATEGY_FILE_EXTENSION.substring(1)); |
|
640 |
try { |
|
641 |
if ((resource != null) && (resource.exists())) { |
|
642 |
PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager(); |
|
643 |
InputStream is = resource.asInputStream(); |
|
644 |
labelingStrategy = (ILabelingStrategy) persistenceManager.getObject(is); |
|
645 |
is.close(); |
|
646 |
} |
|
647 |
} catch (Exception e) { |
|
648 |
LOGGER.warn("Can't load Label strategy", e); |
|
649 |
} finally { |
|
650 |
IOUtils.closeQuietly(resource); |
|
641 | 651 |
} |
642 |
} catch (Exception e) { |
|
643 |
logger.warn("Can't load Label strategy", e); |
|
644 |
} finally { |
|
645 |
IOUtils.closeQuietly(resource); |
|
646 | 652 |
} |
647 | 653 |
|
648 |
//If the legend is null, next option is to check if the store has the getLegend method
|
|
654 |
//If the legend is null, next option is to check if the store has the getLabeling method
|
|
649 | 655 |
if (labelingStrategy == null) { |
650 | 656 |
try { |
651 | 657 |
labelingStrategy |
... | ... | |
654 | 660 |
} catch (DynMethodNotSupportedException e1) { |
655 | 661 |
labelingStrategy = null; |
656 | 662 |
} catch (DynMethodException e1) { |
657 |
logger.error("Can't load the specific lebeling strategy provided for the datastore {}.",
|
|
663 |
LOGGER.error("Can't load the specific labeling strategy provided for the datastore {}.",
|
|
658 | 664 |
dataStore.getName(), |
659 | 665 |
e1); |
660 | 666 |
} |
... | ... | |
684 | 690 |
} |
685 | 691 |
} |
686 | 692 |
|
687 |
|
|
688 |
private Resource getResource(DataStore dataStore, String resource) { |
|
689 |
DataServerExplorer explorer = null; |
|
690 |
try { |
|
691 |
explorer = dataStore.getExplorer(); |
|
692 |
if (explorer == null) { |
|
693 |
return null; |
|
694 |
} |
|
695 |
return explorer.getResource(dataStore, resource); |
|
696 |
} catch (Exception e) { |
|
697 |
logger.warn("Can't locate resource '"+resource+"' for '"+dataStore.getName()+"'.",e); |
|
698 |
return null; |
|
699 |
} finally { |
|
700 |
DisposeUtils.disposeQuietly(explorer); |
|
701 |
} |
|
702 |
} |
|
703 |
|
|
704 | 693 |
private Map iconLayers = new HashMap(); // (Map<String storeProviderName, String iconName>) |
705 | 694 |
|
706 | 695 |
public void registerIconLayer(String storeProviderName, String iconName) { |
707 | 696 |
if (storeProviderName == null || iconName == null) { |
708 |
logger.info("registerIconLayer, storeProviderName or iconName are null");
|
|
697 |
LOGGER.info("registerIconLayer, storeProviderName or iconName are null");
|
|
709 | 698 |
return; |
710 | 699 |
} |
711 | 700 |
String storeName = storeProviderName.trim().toLowerCase(); |
712 | 701 |
if (storeName.length() == 0 || iconName.trim().length() == 0) { |
713 |
logger.info("registerIconLayer, invalid storeProviderName or iconName");
|
|
702 |
LOGGER.info("registerIconLayer, invalid storeProviderName or iconName");
|
|
714 | 703 |
return; |
715 | 704 |
} |
716 | 705 |
iconLayers.put(storeName, iconName); |
Also available in: Unified diff