Revision 44821 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/impl/DefaultDataManager.java
DefaultDataManager.java | ||
---|---|---|
1 | 1 |
package org.gvsig.fmap.dal.impl; |
2 | 2 |
|
3 |
import java.io.ByteArrayInputStream; |
|
4 | 3 |
import java.io.File; |
5 | 4 |
import java.io.InputStream; |
6 | 5 |
import java.net.URL; |
... | ... | |
35 | 34 |
import org.gvsig.fmap.dal.DataStoreProviderFactory; |
36 | 35 |
import org.gvsig.fmap.dal.DataTypes; |
37 | 36 |
import org.gvsig.fmap.dal.DatabaseWorkspaceManager; |
38 |
import org.gvsig.fmap.dal.DatabaseWorkspaceManager.AddDatabaseWorkspaceListener; |
|
39 | 37 |
|
40 | 38 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
41 | 39 |
import org.gvsig.fmap.dal.OpenErrorHandler; |
... | ... | |
63 | 61 |
import org.gvsig.fmap.dal.feature.impl.DALFile; |
64 | 62 |
import org.gvsig.fmap.dal.feature.impl.DefaultEditableFeatureAttributeDescriptor; |
65 | 63 |
import org.gvsig.fmap.dal.feature.impl.DefaultEditableFeatureType; |
66 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureAttributeDescriptor; |
|
67 | 64 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureIndex; |
68 | 65 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStore; |
69 | 66 |
import org.gvsig.fmap.dal.feature.impl.FeatureStoreFactory; |
... | ... | |
101 | 98 |
import org.gvsig.tools.folders.FoldersManager; |
102 | 99 |
import org.gvsig.tools.identitymanagement.SimpleIdentityManager; |
103 | 100 |
import org.gvsig.tools.identitymanagement.UnauthorizedException; |
104 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
105 | 101 |
import org.gvsig.tools.resourcesstorage.ResourcesStorage; |
106 | 102 |
import org.gvsig.tools.script.Script; |
107 | 103 |
import org.gvsig.tools.script.ScriptManager; |
108 | 104 |
import org.gvsig.tools.service.spi.Services; |
109 | 105 |
import org.slf4j.Logger; |
110 | 106 |
import org.slf4j.LoggerFactory; |
107 |
import org.gvsig.fmap.dal.DatabaseWorkspaceManager.DatabaseWorkspaceListener; |
|
111 | 108 |
|
112 | 109 |
@SuppressWarnings("UseSpecificCatch") |
113 | 110 |
public class DefaultDataManager |
... | ... | |
168 | 165 |
|
169 | 166 |
private final Map<String, DatabaseWorkspaceManager> databaseWorkspaces = new HashMap<>(); |
170 | 167 |
|
171 |
private final Map<String,AddDatabaseWorkspaceListener> addDatabaseWorkspaceListeners = new HashMap<>();
|
|
168 |
private final Map<String,DatabaseWorkspaceListener> addDatabaseWorkspaceListeners = new HashMap<>(); |
|
172 | 169 |
|
173 | 170 |
public DefaultDataManager() { |
174 | 171 |
this.registers = new Registers(); |
... | ... | |
1089 | 1086 |
} |
1090 | 1087 |
|
1091 | 1088 |
@Override |
1089 |
public void removeDatabaseWorkspace(DatabaseWorkspaceManager databaseWorkspace) { |
|
1090 |
this.databaseWorkspaces.remove(databaseWorkspace.getId(),databaseWorkspace); |
|
1091 |
StoresRepository repo = databaseWorkspace.getStoresRepository(); |
|
1092 |
this.getStoresRepository().removeRepository(repo.getID()); |
|
1093 |
for (DatabaseWorkspaceListener listener : this.addDatabaseWorkspaceListeners.values()) { |
|
1094 |
if( listener!=null ) { |
|
1095 |
try { |
|
1096 |
listener.onRemoveDatabaseWorkspace(databaseWorkspace); |
|
1097 |
} catch(Throwable th) { |
|
1098 |
LOGGER.warn("Problems calling databaseworkspace listener '"+listener.getName()+"'.",th); |
|
1099 |
} |
|
1100 |
} |
|
1101 |
} |
|
1102 |
try { |
|
1103 |
ResourcesStorage resources = databaseWorkspace.getResourcesStorage(); |
|
1104 |
ScriptManager scriptManager = ToolsLocator.getScriptManager(); |
|
1105 |
Script script = scriptManager.loadScript(resources, "OnDisconnectToWorkspace.script"); |
|
1106 |
if( script != null ) { |
|
1107 |
script.invokeFunction("main", new Object[] {databaseWorkspace}); |
|
1108 |
} |
|
1109 |
} catch(Throwable th) { |
|
1110 |
LOGGER.warn("Problems executing 'OnDisconnectToWorkspace.script' from workspace '"+databaseWorkspace.getId()+"'.",th); |
|
1111 |
} |
|
1112 |
} |
|
1113 |
|
|
1114 |
@Override |
|
1092 | 1115 |
public void addDatabaseWorkspace(DatabaseWorkspaceManager databaseWorkspace) { |
1093 | 1116 |
this.databaseWorkspaces.put(databaseWorkspace.getId(),databaseWorkspace); |
1094 | 1117 |
StoresRepository repo = databaseWorkspace.getStoresRepository(); |
1095 | 1118 |
this.getStoresRepository().addRepository(repo); |
1096 | 1119 |
|
1097 |
for (AddDatabaseWorkspaceListener listener : this.addDatabaseWorkspaceListeners.values()) {
|
|
1120 |
for (DatabaseWorkspaceListener listener : this.addDatabaseWorkspaceListeners.values()) { |
|
1098 | 1121 |
if( listener!=null ) { |
1099 | 1122 |
try { |
1100 | 1123 |
listener.onAddDatabaseWorkspace(databaseWorkspace); |
... | ... | |
1116 | 1139 |
} |
1117 | 1140 |
|
1118 | 1141 |
@Override |
1119 |
public void addDatabaseWorkspaceListener(AddDatabaseWorkspaceListener listener) {
|
|
1142 |
public void addDatabaseWorkspaceListener(DatabaseWorkspaceListener listener) { |
|
1120 | 1143 |
this.addDatabaseWorkspaceListeners.put(listener.getName(), listener); |
1121 | 1144 |
} |
1122 | 1145 |
|
1123 | 1146 |
@Override |
1124 | 1147 |
public DatabaseWorkspaceManager getDatabaseWorkspace(String name) { |
1148 |
if( StringUtils.isBlank(name) ) { |
|
1149 |
return null; |
|
1150 |
} |
|
1125 | 1151 |
return this.databaseWorkspaces.get(name); |
1126 | 1152 |
} |
1127 | 1153 |
|
Also available in: Unified diff