Lines 16-26
Link Here
|
16 |
|
16 |
|
17 |
package org.eclipse.rse.internal.persistence; |
17 |
package org.eclipse.rse.internal.persistence; |
18 |
|
18 |
|
|
|
19 |
import java.util.ArrayList; |
19 |
import java.util.HashMap; |
20 |
import java.util.HashMap; |
|
|
21 |
import java.util.List; |
20 |
import java.util.Map; |
22 |
import java.util.Map; |
|
|
23 |
import java.util.Set; |
21 |
|
24 |
|
22 |
import org.eclipse.core.resources.IProject; |
25 |
import org.eclipse.core.resources.IProject; |
23 |
import org.eclipse.core.resources.IResource; |
|
|
24 |
import org.eclipse.core.runtime.CoreException; |
26 |
import org.eclipse.core.runtime.CoreException; |
25 |
import org.eclipse.core.runtime.IConfigurationElement; |
27 |
import org.eclipse.core.runtime.IConfigurationElement; |
26 |
import org.eclipse.core.runtime.IExtensionRegistry; |
28 |
import org.eclipse.core.runtime.IExtensionRegistry; |
Lines 29-47
Link Here
|
29 |
import org.eclipse.core.runtime.Platform; |
31 |
import org.eclipse.core.runtime.Platform; |
30 |
import org.eclipse.core.runtime.Preferences; |
32 |
import org.eclipse.core.runtime.Preferences; |
31 |
import org.eclipse.core.runtime.jobs.Job; |
33 |
import org.eclipse.core.runtime.jobs.Job; |
32 |
import org.eclipse.core.runtime.preferences.IPreferencesService; |
|
|
33 |
import org.eclipse.rse.core.IRSEPreferenceNames; |
34 |
import org.eclipse.rse.core.IRSEPreferenceNames; |
34 |
import org.eclipse.rse.core.RSECorePlugin; |
35 |
import org.eclipse.rse.core.RSECorePlugin; |
35 |
import org.eclipse.rse.core.SystemResourceManager; |
36 |
import org.eclipse.rse.core.SystemResourceManager; |
36 |
import org.eclipse.rse.core.filters.ISystemFilterPool; |
37 |
import org.eclipse.rse.core.model.IRSEPersistableContainer; |
37 |
import org.eclipse.rse.core.filters.ISystemFilterPoolManager; |
|
|
38 |
import org.eclipse.rse.core.filters.ISystemFilterPoolManagerProvider; |
39 |
import org.eclipse.rse.core.filters.SystemFilterPoolManager; |
40 |
import org.eclipse.rse.core.model.IHost; |
41 |
import org.eclipse.rse.core.model.ISystemHostPool; |
42 |
import org.eclipse.rse.core.model.ISystemProfile; |
38 |
import org.eclipse.rse.core.model.ISystemProfile; |
43 |
import org.eclipse.rse.core.model.ISystemProfileManager; |
|
|
44 |
import org.eclipse.rse.core.model.ISystemRegistry; |
39 |
import org.eclipse.rse.core.model.ISystemRegistry; |
|
|
40 |
import org.eclipse.rse.internal.core.model.SystemProfileManager; |
45 |
import org.eclipse.rse.internal.persistence.dom.RSEDOMExporter; |
41 |
import org.eclipse.rse.internal.persistence.dom.RSEDOMExporter; |
46 |
import org.eclipse.rse.internal.persistence.dom.RSEDOMImporter; |
42 |
import org.eclipse.rse.internal.persistence.dom.RSEDOMImporter; |
47 |
import org.eclipse.rse.logging.Logger; |
43 |
import org.eclipse.rse.logging.Logger; |
Lines 58-404
Link Here
|
58 |
public class RSEPersistenceManager implements IRSEPersistenceManager { |
54 |
public class RSEPersistenceManager implements IRSEPersistenceManager { |
59 |
|
55 |
|
60 |
private static final int STATE_NONE = 0; |
56 |
private static final int STATE_NONE = 0; |
61 |
private static final int STATE_IMPORTING = 1; |
57 |
private static final int STATE_LOADING = 1; |
62 |
private static final int STATE_EXPORTING = 2; |
58 |
private static final int STATE_SAVING = 2; |
63 |
|
59 |
|
64 |
private static IProject remoteSystemsProject = null; |
60 |
private static IProject remoteSystemsProject = null; |
65 |
public static final String RESOURCE_PROJECT_NAME = "RemoteSystemsConnections"; //$NON-NLS-1$ |
61 |
|
66 |
/** |
62 |
/** |
67 |
* Get the default remote systems project. |
63 |
* Get the default remote systems project. |
68 |
* @return IProject handle of the project. Use exists() to test existence. |
64 |
* @return IProject handle of the project. |
69 |
*/ |
65 |
*/ |
70 |
public static IProject getRemoteSystemsProject() { |
66 |
public static IProject getRemoteSystemsProject() { |
71 |
if (remoteSystemsProject == null) |
67 |
if (remoteSystemsProject == null) |
72 |
{ |
68 |
{ |
73 |
remoteSystemsProject = SystemResourceManager.getRemoteSystemsProject(); |
69 |
remoteSystemsProject = SystemResourceManager.getRemoteSystemsProject(); |
74 |
} |
70 |
} |
75 |
|
|
|
76 |
return remoteSystemsProject; |
71 |
return remoteSystemsProject; |
77 |
} |
72 |
} |
78 |
private Map loadedProviders = new HashMap(10); |
|
|
79 |
|
73 |
|
|
|
74 |
private Map knownProviders = new HashMap(10); |
80 |
private int _currentState = STATE_NONE; |
75 |
private int _currentState = STATE_NONE; |
81 |
private RSEDOMExporter _exporter; |
76 |
private RSEDOMExporter _exporter; |
82 |
|
|
|
83 |
private RSEDOMImporter _importer; |
77 |
private RSEDOMImporter _importer; |
84 |
|
78 |
|
85 |
public RSEPersistenceManager(ISystemRegistry registry) { |
79 |
public RSEPersistenceManager(ISystemRegistry registry) { |
86 |
// _registry = registry; |
|
|
87 |
_exporter = RSEDOMExporter.getInstance(); |
80 |
_exporter = RSEDOMExporter.getInstance(); |
88 |
_exporter.setSystemRegistry(registry); |
|
|
89 |
_importer = RSEDOMImporter.getInstance(); |
81 |
_importer = RSEDOMImporter.getInstance(); |
90 |
_importer.setSystemRegistry(registry); |
82 |
_importer.setSystemRegistry(registry); |
|
|
83 |
getProviderExtensions(); |
91 |
} |
84 |
} |
92 |
|
85 |
|
93 |
public boolean commit(ISystemFilterPoolManager filterPoolManager) { |
86 |
public boolean isExporting() { |
94 |
if (filterPoolManager.isDirty()) { |
87 |
return _currentState == STATE_SAVING; |
95 |
commit(filterPoolManager.getSystemProfile()); |
88 |
} |
96 |
filterPoolManager.setDirty(false); |
89 |
|
97 |
} |
90 |
public boolean isImporting() { |
98 |
return false; |
91 |
return _currentState == STATE_LOADING; |
99 |
} |
92 |
} |
100 |
|
93 |
|
101 |
public boolean commit(ISystemHostPool connectionPool) { |
94 |
public void registerPersistenceProvider(String id, IRSEPersistenceProvider provider) { |
102 |
if (connectionPool.isDirty()) { |
95 |
knownProviders.put(id, provider); |
103 |
commit(connectionPool.getSystemProfile()); |
|
|
104 |
connectionPool.setDirty(false); |
105 |
} |
106 |
/* |
107 |
Host[] connections = connectionPool.getHosts(); |
108 |
for (int idx = 0; idx < connections.length; idx++) |
109 |
{ |
110 |
if (!saveHost(connectionPool, connections[idx])) |
111 |
{ |
112 |
return false; |
113 |
} |
114 |
} |
115 |
return true; |
116 |
*/ |
117 |
return false; // all persistence should be at profile level |
118 |
} |
96 |
} |
119 |
|
97 |
|
120 |
/** |
98 |
/** |
121 |
* Attempt to save single profile to disk. |
99 |
* Attempt to save single profile to disk. |
122 |
*/ |
100 |
*/ |
123 |
public boolean commit(ISystemProfile profile) { |
101 |
public boolean commitProfile(ISystemProfile profile) { |
|
|
102 |
boolean result = false; |
124 |
if (profile != null) { |
103 |
if (profile != null) { |
125 |
return save(profile, false); |
104 |
result = save(profile, false); |
126 |
} |
105 |
} |
127 |
return false; |
106 |
return result; |
128 |
} |
107 |
} |
129 |
|
108 |
|
130 |
/** |
109 |
public boolean commitProfiles() { |
131 |
* Save all profiles to disk |
110 |
boolean ok = true; |
132 |
*/ |
111 |
ISystemProfile[] profiles = RSECorePlugin.getDefault().getSystemRegistry().getAllSystemProfiles(); |
133 |
public boolean commit(ISystemProfileManager profileManager) { |
112 |
for (int idx = 0; idx < profiles.length && ok; idx++) { |
134 |
|
|
|
135 |
ISystemProfile[] profiles = profileManager.getSystemProfiles(); |
136 |
for (int idx = 0; idx < profiles.length; idx++) { |
137 |
try { |
113 |
try { |
138 |
commit(profiles[idx]); |
114 |
ok = commitProfile(profiles[idx]); |
139 |
} catch (Exception exc) { |
115 |
} catch (Exception exc) { |
140 |
Logger logger = RSECorePlugin.getDefault().getLogger(); |
116 |
Logger logger = RSECorePlugin.getDefault().getLogger(); |
141 |
String profileName = profiles[idx].getName(); |
117 |
String profileName = profiles[idx].getName(); |
142 |
String message = "Error saving profile " + profileName; //$NON-NLS-1$ |
118 |
String message = "Error saving profile " + profileName; //$NON-NLS-1$ |
143 |
logger.logError(message, exc); |
119 |
logger.logError(message, exc); |
144 |
return false; |
120 |
ok = false; |
145 |
} |
121 |
} |
146 |
} |
122 |
} |
147 |
|
123 |
return ok; |
148 |
return true; |
124 |
} |
|
|
125 |
|
126 |
/* (non-Javadoc) |
127 |
* @see org.eclipse.rse.persistence.IRSEPersistenceManager#migrateProfile(org.eclipse.rse.core.model.ISystemProfile, org.eclipse.rse.persistence.IRSEPersistenceProvider) |
128 |
*/ |
129 |
public void migrateProfile(ISystemProfile profile, IRSEPersistenceProvider persistenceProvider) { |
130 |
IRSEPersistenceProvider oldProvider = profile.getPersistenceProvider(); |
131 |
oldProvider = (oldProvider == null) ? getDefaultPersistenceProvider() : oldProvider; |
132 |
IRSEPersistenceProvider newProvider = persistenceProvider; |
133 |
newProvider = (newProvider == null) ? getDefaultPersistenceProvider() : newProvider; |
134 |
if (oldProvider != newProvider) { |
135 |
profile.setPersistenceProvider(newProvider); |
136 |
profile.commit(); |
137 |
deleteProfile(oldProvider, profile.getName()); |
138 |
} |
149 |
} |
139 |
} |
150 |
|
140 |
|
151 |
/* (non-Javadoc) |
141 |
/* (non-Javadoc) |
152 |
* @see org.eclipse.rse.persistence.IRSEPersistenceManager#deleteProfile(java.lang.String) |
142 |
* @see org.eclipse.rse.persistence.IRSEPersistenceManager#deleteProfile(java.lang.String) |
153 |
*/ |
143 |
*/ |
154 |
public void deleteProfile(final String profileName) { |
144 |
public void deleteProfile(final IRSEPersistenceProvider persistenceProvider, final String profileName) { |
155 |
Job job = new Job(Messages.RSEPersistenceManager_DeleteProfileJobName) { |
145 |
Job job = new Job(Messages.RSEPersistenceManager_DeleteProfileJobName) { |
156 |
protected IStatus run(IProgressMonitor monitor) { |
146 |
protected IStatus run(IProgressMonitor monitor) { |
157 |
IRSEPersistenceProvider provider = getRSEPersistenceProvider(); |
147 |
IRSEPersistenceProvider p = persistenceProvider != null ? persistenceProvider : getDefaultPersistenceProvider(); |
158 |
IStatus result = provider.deleteProfile(profileName, monitor); |
148 |
IStatus result = p.deleteProfile(profileName, monitor); |
159 |
return result; |
149 |
return result; |
160 |
} |
150 |
} |
161 |
}; |
151 |
}; |
162 |
job.schedule(); |
152 |
job.schedule(); |
163 |
} |
153 |
} |
164 |
|
154 |
|
165 |
private RSEDOM exportRSEDOM(ISystemProfile profile, boolean force) { |
155 |
/* (non-Javadoc) |
166 |
RSEDOM dom = _exporter.createRSEDOM(profile, force); |
156 |
* @see org.eclipse.rse.persistence.IRSEPersistenceManager#restoreProfiles() |
167 |
return dom; |
157 |
*/ |
|
|
158 |
public ISystemProfile[] restoreProfiles() { |
159 |
List profiles = loadProfiles(); |
160 |
ISystemProfile[] result = new ISystemProfile[profiles.size()]; |
161 |
profiles.toArray(result); |
162 |
return result; |
163 |
} |
164 |
|
165 |
public ISystemProfile restoreProfile(IRSEPersistenceProvider provider, String profileName) { |
166 |
ISystemProfile result = load(provider, profileName); |
167 |
return result; |
168 |
} |
168 |
} |
169 |
|
169 |
|
170 |
/** |
170 |
/** |
|
|
171 |
* Returns the persistence provider denoted by the id. Only one instance of this |
172 |
* persistence provider is created. |
173 |
* @param id The id of the persistence provider, as denoted by the id attribute on its declaration. |
174 |
* @return an IRSEPersistenceProvider which may be null if this id is not found. |
175 |
*/ |
176 |
public IRSEPersistenceProvider getPersistenceProvider(String id) { |
177 |
IRSEPersistenceProvider provider = null; |
178 |
Object providerCandidate = knownProviders.get(id); |
179 |
if (providerCandidate instanceof IConfigurationElement) { |
180 |
IConfigurationElement element = (IConfigurationElement) providerCandidate; |
181 |
try { |
182 |
provider = (IRSEPersistenceProvider) element.createExecutableExtension("class"); //$NON-NLS-1$ |
183 |
} catch (CoreException e) { |
184 |
Logger logger = RSECorePlugin.getDefault().getLogger(); |
185 |
logger.logError("Exception loading persistence provider", e); //$NON-NLS-1$ |
186 |
} |
187 |
if (provider != null) { |
188 |
knownProviders.put(id, provider); |
189 |
} |
190 |
} else if (providerCandidate instanceof IRSEPersistenceProvider) { |
191 |
provider = (IRSEPersistenceProvider) providerCandidate; |
192 |
} |
193 |
return provider; |
194 |
} |
195 |
|
196 |
/* (non-Javadoc) |
197 |
* @see org.eclipse.rse.persistence.IRSEPersistenceManager#getPersistenceProviderIds() |
198 |
*/ |
199 |
public String[] getPersistenceProviderIds() { |
200 |
Set ids = knownProviders.keySet(); |
201 |
String[] result = new String[ids.size()]; |
202 |
ids.toArray(result); |
203 |
return result; |
204 |
} |
205 |
|
206 |
/** |
171 |
* Retrieves the default persistence provider for this workbench configuration. |
207 |
* Retrieves the default persistence provider for this workbench configuration. |
172 |
* Several persistence providers may be registered, but the default one is used for all |
208 |
* Several persistence providers may be registered, but the default one is used for all |
173 |
* profiles that do not have one explicitly specified. |
209 |
* profiles that do not have one explicitly specified. |
174 |
* This persistence provider's identifier is specified in the org.eclipse.rse.core/defaultPersistenceProvider |
210 |
* This persistence provider's identifier is specified in the org.eclipse.rse.core/DEFAULT_PERSISTENCE_PROVIDER |
175 |
* preference and can be specified a product's plugin_customization.ini file. |
211 |
* preference and can be specified a product's plugin_customization.ini file. |
176 |
* @see IRSEPreferenceNames |
212 |
* @see IRSEPreferenceNames |
177 |
* @return the default IRSEPersistenceProvider for this installation. |
213 |
* @return the default IRSEPersistenceProvider for this installation. |
178 |
*/ |
214 |
*/ |
179 |
public IRSEPersistenceProvider getRSEPersistenceProvider() { |
215 |
private IRSEPersistenceProvider getDefaultPersistenceProvider() { |
180 |
Preferences preferences = RSECorePlugin.getDefault().getPluginPreferences(); |
216 |
Preferences preferences = RSECorePlugin.getDefault().getPluginPreferences(); |
181 |
String providerName = preferences.getString(IRSEPreferenceNames.DEFAULT_PERSISTENCE_PROVIDER); |
217 |
String providerId = preferences.getString(IRSEPreferenceNames.DEFAULT_PERSISTENCE_PROVIDER); |
182 |
IRSEPersistenceProvider provider = getRSEPersistenceProvider(providerName); |
218 |
IRSEPersistenceProvider provider = getPersistenceProvider(providerId); |
183 |
return provider; |
219 |
return provider; |
184 |
} |
220 |
} |
185 |
|
221 |
|
186 |
/** |
222 |
/** |
187 |
* Returns the persistence provider denoted by the id. Only one instance of this |
223 |
* Loads the map of known providers from the extensions made by all the plugins. |
188 |
* persistence provider is created. |
224 |
* This is done once at initialization of the manager. As these ids are resolved to |
189 |
* @param id The id of the persistence provider, as denoted by the id attribute on its declaration. |
225 |
* their providers as needed, the configuration elements are replaced in the map |
190 |
* @return an IRSEPersistenceProvider which may be null if this id is not found. |
226 |
* by the persistence providers they reference. |
191 |
*/ |
227 |
*/ |
192 |
public IRSEPersistenceProvider getRSEPersistenceProvider(String id) { |
228 |
private void getProviderExtensions() { |
193 |
Logger logger = RSECorePlugin.getDefault().getLogger(); |
229 |
Logger logger = RSECorePlugin.getDefault().getLogger(); |
194 |
IRSEPersistenceProvider provider = (IRSEPersistenceProvider) loadedProviders.get(id); |
230 |
IExtensionRegistry registry = Platform.getExtensionRegistry(); |
195 |
if (provider == null) { |
231 |
IConfigurationElement[] providerCandidates = registry.getConfigurationElementsFor("org.eclipse.rse.core", "persistenceProviders"); //$NON-NLS-1$ //$NON-NLS-2$ |
196 |
IExtensionRegistry registry = Platform.getExtensionRegistry(); |
232 |
for (int j = 0; j < providerCandidates.length; j++) { |
197 |
IConfigurationElement[] providerCandidates = registry.getConfigurationElementsFor("org.eclipse.rse.core", "persistenceProviders"); //$NON-NLS-1$ //$NON-NLS-2$ |
233 |
IConfigurationElement configurationElement = providerCandidates[j]; |
198 |
for (int j = 0; j < providerCandidates.length; j++) { |
234 |
if (configurationElement.getName().equals("persistenceProvider")) { //$NON-NLS-1$ |
199 |
IConfigurationElement providerCandidate = providerCandidates[j]; |
235 |
String candidateId = configurationElement.getAttribute("id"); //$NON-NLS-1$ |
200 |
if (providerCandidate.getName().equals("persistenceProvider")) { //$NON-NLS-1$ |
236 |
if (candidateId != null) { |
201 |
String candidateId = providerCandidate.getAttribute("id"); //$NON-NLS-1$ |
237 |
knownProviders.put(candidateId, configurationElement); |
202 |
if (candidateId != null) { |
|
|
203 |
if (candidateId.equals(id)) { |
204 |
try { |
205 |
provider = (IRSEPersistenceProvider) providerCandidate.createExecutableExtension("class"); //$NON-NLS-1$ |
206 |
} catch (CoreException e) { |
207 |
logger.logError("Exception loading persistence provider", e); //$NON-NLS-1$ |
208 |
} |
209 |
} |
210 |
} else { |
211 |
logger.logError("Missing id attribute in persistenceProvider element", null); //$NON-NLS-1$ |
212 |
} |
213 |
} else { |
238 |
} else { |
214 |
logger.logError("Invalid element in persistenceProviders extension point", null); //$NON-NLS-1$ |
239 |
logger.logError("Missing id attribute in persistenceProvider element", null); //$NON-NLS-1$ |
215 |
} |
240 |
} |
|
|
241 |
} else { |
242 |
logger.logError("Invalid element in persistenceProviders extension point", null); //$NON-NLS-1$ |
216 |
} |
243 |
} |
217 |
if (provider == null) { |
|
|
218 |
logger.logError("Persistence provider not found.", null); //$NON-NLS-1$ |
219 |
} |
220 |
loadedProviders.put(id, provider); // even if provider is null |
221 |
} |
244 |
} |
222 |
return provider; |
|
|
223 |
} |
245 |
} |
224 |
|
246 |
|
225 |
private RSEDOM importRSEDOM(String domName) { |
247 |
private List loadProfiles() { |
226 |
RSEDOM dom = null; |
248 |
List profiles = new ArrayList(10); |
227 |
IRSEPersistenceProvider provider = getRSEPersistenceProvider(); |
249 |
String[] ids = getPersistenceProviderIds(); |
228 |
if (provider != null) { |
250 |
for (int i = 0; i < ids.length; i++) { |
229 |
dom = provider.loadRSEDOM(domName, null); |
251 |
String id = ids[i]; |
230 |
} else { |
252 |
IRSEPersistenceProvider provider = getPersistenceProvider(id); |
231 |
Logger logger = RSECorePlugin.getDefault().getLogger(); |
253 |
if (provider != null) { |
232 |
logger.logError("Persistence provider is not available.", null); //$NON-NLS-1$ |
254 |
profiles.addAll(loadProfiles(provider)); |
|
|
255 |
} |
233 |
} |
256 |
} |
234 |
return dom; |
257 |
return profiles; |
235 |
} |
258 |
} |
236 |
|
259 |
|
237 |
public synchronized boolean isExporting() { |
260 |
private List loadProfiles(IRSEPersistenceProvider persistenceProvider) { |
238 |
return _currentState == STATE_EXPORTING; |
261 |
List profiles = new ArrayList(10); |
239 |
} |
262 |
String[] profileNames = persistenceProvider.getSavedProfileNames(); |
240 |
|
263 |
for (int i = 0; i < profileNames.length; i++) { |
241 |
public synchronized boolean isImporting() { |
264 |
String profileName = profileNames[i]; |
242 |
return _currentState == STATE_IMPORTING; |
265 |
ISystemProfile profile = load(persistenceProvider, profileName); |
|
|
266 |
profiles.add(profile); |
267 |
} |
268 |
return profiles; |
243 |
} |
269 |
} |
244 |
|
270 |
|
245 |
/** |
271 |
/** |
246 |
* Loads and restores RSE artifacts from the last session |
272 |
* Loads a profile of the given name using the given persistence provider. If the provider cannot |
247 |
* @param profileManager |
273 |
* find a profile with that name, return null. |
248 |
* @return true if the profiles are loaded |
274 |
* @param provider the persistence provider that understands the name and can produce a profile. |
249 |
*/ |
275 |
* @param profileName the name of the profile to produce |
250 |
private boolean load(ISystemProfileManager profileManager) { |
276 |
* @return the profile or null |
251 |
boolean successful = true; |
277 |
*/ |
252 |
synchronized(this) { |
278 |
private synchronized ISystemProfile load(IRSEPersistenceProvider provider, String profileName) { |
253 |
if (isExporting() || isImporting()) { |
279 |
ISystemProfile profile = null; |
254 |
successful = false; |
280 |
if (_currentState == STATE_NONE) { |
255 |
} else { |
281 |
_currentState = STATE_LOADING; |
256 |
setState(STATE_IMPORTING); |
282 |
RSEDOM dom = provider.loadRSEDOM(profileName, null); |
257 |
} |
283 |
if (dom != null) { |
258 |
} |
284 |
SystemProfileManager.getDefault().setRestoring(true); |
259 |
if(successful) { |
285 |
profile = _importer.restoreProfile(dom); |
260 |
try { |
286 |
SystemProfileManager.getDefault().setRestoring(false); |
261 |
IProject project = getRemoteSystemsProject(); |
287 |
profile.setPersistenceProvider(provider); |
262 |
if (!project.isSynchronized(IResource.DEPTH_ONE)) project.refreshLocal(IResource.DEPTH_ONE, null); |
288 |
cleanTree(profile); |
263 |
IRSEPersistenceProvider persistenceProvider = getRSEPersistenceProvider(); |
|
|
264 |
String[] profileNames = persistenceProvider.getSavedProfileNames(); |
265 |
for (int i = 0; i < profileNames.length; i++) { |
266 |
String profileName = profileNames[i]; |
267 |
RSEDOM dom = importRSEDOM(profileName); |
268 |
if (dom != null) { |
269 |
ISystemProfile restoredProfile = _importer.restoreProfile(profileManager, dom); |
270 |
if (restoredProfile == null) { |
271 |
successful = false; |
272 |
} |
273 |
} else { |
274 |
successful = false; |
275 |
} |
276 |
} |
277 |
} catch (Exception e) { |
278 |
e.printStackTrace(); |
279 |
successful = false; |
280 |
} finally { |
281 |
setState(STATE_NONE); |
282 |
} |
289 |
} |
|
|
290 |
_currentState = STATE_NONE; |
283 |
} |
291 |
} |
284 |
return successful; |
292 |
return profile; |
285 |
} |
|
|
286 |
|
287 |
public void registerRSEPersistenceProvider(String id, IRSEPersistenceProvider provider) { |
288 |
loadedProviders.put(id, provider); |
289 |
} |
290 |
|
291 |
public boolean restore(ISystemFilterPool filterPool) { |
292 |
//System.out.println("restore filterpool"); |
293 |
// DWD function Is this method really needed? |
294 |
return false; |
295 |
} |
293 |
} |
296 |
|
294 |
|
297 |
public boolean restore(ISystemHostPool connectionPool) { |
|
|
298 |
return false; |
299 |
} |
300 |
|
301 |
public boolean restore(ISystemProfileManager profileManager) { |
302 |
return load(profileManager); |
303 |
} |
304 |
|
305 |
public ISystemFilterPool restoreFilterPool(String name) { |
306 |
//System.out.println("restore filter pool "+name); |
307 |
// DWD function is this method really needed? |
308 |
return null; |
309 |
} |
310 |
|
311 |
/** |
312 |
* Creates a filter pool manager for a particular SubSystemConfiguration and SystemProfile. Called |
313 |
* "restore" for historcal reasons. |
314 |
* @param profile the profile that will own this ISystemFilterPoolManager. There is one of these per profile. |
315 |
* @param logger the logging object for logging errors. Each ISystemFilterPoolManager has one of these. |
316 |
* @param caller The creator/owner of this ISystemFilterPoolManager, this ends up being a SubSystemConfiguration. |
317 |
* @param name the name of the manager to restore. File name is derived from it when saving to one file. |
318 |
* @return the "restored" manager. |
319 |
*/ |
320 |
public ISystemFilterPoolManager restoreFilterPoolManager(ISystemProfile profile, Logger logger, ISystemFilterPoolManagerProvider caller, String name) { |
321 |
SystemFilterPoolManager mgr = SystemFilterPoolManager.createManager(profile); |
322 |
mgr.initialize(logger, caller, name); // core data |
323 |
mgr.setWasRestored(false); // managers are not "restored from disk" since they are not persistent of themselves |
324 |
return mgr; |
325 |
} |
326 |
|
327 |
/** |
295 |
/** |
328 |
* Restore a connection of a given name from disk... |
296 |
* Writes a profile to a DOM and schedules writing of that DOM to disk. |
329 |
*/ |
|
|
330 |
protected IHost restoreHost(ISystemHostPool hostPool, String connectionName) throws Exception { |
331 |
/* |
332 |
* FIXME //System.out.println("in SystemConnectionPoolImpl#restore for |
333 |
* connection " + connectionName); String fileName = |
334 |
* getRootSaveFileName(connectionName); |
335 |
* //System.out.println(".......fileName = " + fileName); |
336 |
* //System.out.println(".......folderName = " + |
337 |
* getConnectionFolder(connectionName).getName()); java.util.List ext = |
338 |
* getMOFHelpers().restore(getConnectionFolder(connectionName),fileName); |
339 |
* // should be exactly one profile... Iterator iList = ext.iterator(); |
340 |
* SystemConnection connection = (SystemConnection)iList.next(); if |
341 |
* (connection != null) { if |
342 |
* (!connection.getAliasName().equalsIgnoreCase(connectionName)) { |
343 |
* RSEUIPlugin.logDebugMessage(this.getClass().getName(),"Incorrect |
344 |
* alias name found in connections.xmi file for " + connectionName+". |
345 |
* Name was reset"); connection.setAliasName(connectionName); // just in |
346 |
* case! } internalAddConnection(connection); } return connection; |
347 |
*/ |
348 |
return null; |
349 |
} |
350 |
|
351 |
/** |
352 |
* Restore a profile of a given name from disk... |
353 |
*/ |
354 |
protected ISystemProfile restoreProfile(ISystemProfileManager mgr, String name) throws Exception { |
355 |
/* |
356 |
* FIXME String fileName = mgr.getRootSaveFileName(name); java.util.List |
357 |
* ext = null;//FIXME |
358 |
* getMOFHelpers().restore(SystemResourceManager.getProfileFolder(name),fileName); |
359 |
* // should be exactly one profile... Iterator iList = ext.iterator(); |
360 |
* SystemProfile profile = (SystemProfile)iList.next(); |
361 |
* mgr.initialize(profile, name); return profile; |
362 |
*/ |
363 |
return null; |
364 |
} |
365 |
|
366 |
/** |
367 |
* Writes the RSE model to a DOM and schedules writing of that DOM to disk. |
368 |
* May, in fact, update an existing DOM instead of creating a new one. |
297 |
* May, in fact, update an existing DOM instead of creating a new one. |
369 |
* If in the process of importing, skip writing. |
298 |
* If in the process of importing, skip writing. |
370 |
* @return true if the profile is written to a DOM |
299 |
* @return true if the profile is written to a DOM |
371 |
*/ |
300 |
*/ |
372 |
private boolean save(ISystemProfile profile, boolean force) { |
301 |
private synchronized boolean save(ISystemProfile profile, boolean force) { |
373 |
boolean result = false; |
302 |
if (_currentState == STATE_NONE) { |
374 |
boolean acquiredLock = false; |
303 |
_currentState = STATE_SAVING; |
375 |
synchronized(this) { |
304 |
IRSEPersistenceProvider provider = profile.getPersistenceProvider(); |
376 |
if (!isImporting()) { |
305 |
if (provider == null) { |
377 |
setState(STATE_EXPORTING); |
306 |
provider = getDefaultPersistenceProvider(); |
378 |
acquiredLock = true; |
307 |
profile.setPersistenceProvider(provider); |
379 |
} |
308 |
} |
380 |
} |
309 |
RSEDOM dom = null; // DWD should do merge, but does not handle deletes properly yet |
381 |
if (acquiredLock) { |
310 |
dom = _exporter.createRSEDOM(profile, force); |
382 |
try { |
311 |
cleanTree(profile); |
383 |
RSEDOM dom = exportRSEDOM(profile, true); // DWD should do merge, but does not handle deletes properly yet |
312 |
if (dom.needsSave()) { |
384 |
result = true; |
313 |
Job job = dom.getSaveJob(); |
385 |
if (dom.needsSave()) { |
314 |
if (job == null) { |
386 |
Job job = dom.getSaveJob(); |
315 |
job = new SaveRSEDOMJob(dom, getDefaultPersistenceProvider()); |
387 |
if (job == null) { |
316 |
dom.setSaveJob(job); |
388 |
job = new SaveRSEDOMJob(dom, getRSEPersistenceProvider()); |
|
|
389 |
dom.setSaveJob(job); |
390 |
} |
391 |
job.schedule(3000); // three second delay |
392 |
} |
317 |
} |
393 |
} finally { |
318 |
job.schedule(3000); // three second delay |
394 |
setState(STATE_NONE); |
|
|
395 |
} |
319 |
} |
|
|
320 |
_currentState = STATE_NONE; |
396 |
} |
321 |
} |
397 |
return result; |
322 |
return true; |
398 |
} |
323 |
} |
399 |
|
324 |
|
400 |
private synchronized void setState(int state) { |
325 |
private void cleanTree(IRSEPersistableContainer node) { |
401 |
_currentState = state; |
326 |
node.setWasRestored(true); |
|
|
327 |
node.setTainted(false); |
328 |
node.setDirty(false); |
329 |
IRSEPersistableContainer[] children = node.getPersistableChildren(); |
330 |
for (int i = 0; i < children.length; i++) { |
331 |
IRSEPersistableContainer child = children[i]; |
332 |
cleanTree(child); |
333 |
} |
402 |
} |
334 |
} |
403 |
|
335 |
|
404 |
} |
336 |
} |