diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/filters/SystemFilterPoolManager.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/filters/SystemFilterPoolManager.java index 798c9996ffa..7c915f9e12f 100644 --- a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/filters/SystemFilterPoolManager.java +++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/filters/SystemFilterPoolManager.java @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2002, 2006 IBM Corporation. All rights reserved. + * Copyright (c) 2002, 2007 IBM Corporation. All rights reserved. * This program and the accompanying materials are made available under the terms * of the Eclipse Public License v1.0 which accompanies this distribution, and is * available at http://www.eclipse.org/legal/epl-v10.html @@ -11,7 +11,7 @@ * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * * Contributors: - * {Name} (company) - description of contribution. + * David Dykstal (IBM) - 142806: refactoring persistence framework ********************************************************************************/ package org.eclipse.rse.core.filters; @@ -23,8 +23,10 @@ import java.util.Vector; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.rse.core.RSECorePlugin; +import org.eclipse.rse.core.model.IRSEPersistableContainer; import org.eclipse.rse.core.model.ISystemProfile; import org.eclipse.rse.core.model.ISystemRegistry; +import org.eclipse.rse.core.model.RSEPersistableObject; import org.eclipse.rse.core.references.IRSEBaseReferencingObject; import org.eclipse.rse.logging.Logger; import org.eclipse.rse.persistence.IRSEPersistenceManager; @@ -91,7 +93,7 @@ import org.eclipse.rse.persistence.IRSEPersistenceManager; /** * @lastgen class SystemFilterPoolManagerImpl Impl implements SystemFilterPoolManager {} */ -public class SystemFilterPoolManager implements ISystemFilterPoolManager { +public class SystemFilterPoolManager extends RSEPersistableObject implements ISystemFilterPoolManager { private ISystemFilterPool[] poolArray = null; // cache for performance private ISystemFilterPoolManagerProvider caller = null; private Object poolMgrData; @@ -103,10 +105,6 @@ public class SystemFilterPoolManager implements ISystemFilterPoolManager { private Logger logger = null; private ISystemProfile _profile; - // persistence - protected boolean _isDirty = true; - private boolean _wasRestored = false; - public static boolean debug = true; /** @@ -1520,25 +1518,6 @@ public class SystemFilterPoolManager implements ISystemFilterPoolManager { return null; } - /** - * Save all the filter pools to disk. - * Uses the save policy specified in this manager's factory method. - */ - public boolean commit() { - IRSEPersistenceManager mgr = RSECorePlugin.getThePersistenceManager(); - - return mgr.commit(this); - } - - /** - * Save all the filter pools to disk. - * Uses the save policy specified in this manager's factory method. - */ - public boolean commit(ISystemFilterPool pool) { - IRSEPersistenceManager mgr = RSECorePlugin.getThePersistenceManager(); - return mgr.commit(pool); - } - /** * Restore filter pools when all are stored in one file * @param logger The logging object to log errors to @@ -1742,22 +1721,31 @@ public class SystemFilterPoolManager implements ISystemFilterPoolManager { } } - public boolean isDirty() { - return _isDirty; + /** + * Save all the filter pools to disk. + * Uses the save policy specified in this manager's factory method. + */ + public boolean commit() { + IRSEPersistenceManager mgr = RSECorePlugin.getThePersistenceManager(); + return mgr.commit(this); } - public void setDirty(boolean flag) { - if (_isDirty != flag) { - _isDirty = flag; - } + /** + * Save all the filter pools to disk. + * Uses the save policy specified in this manager's factory method. + */ + public boolean commit(ISystemFilterPool pool) { + boolean result = pool.commit(); + return result; } - public boolean wasRestored() { - return _wasRestored; + public IRSEPersistableContainer getPersistableParent() { + return _profile; } - - public void setWasRestored(boolean flag) { - _wasRestored = flag; + + public IRSEPersistableContainer[] getPersistableChildren() { + IRSEPersistableContainer[] result = getSystemFilterPools(); + return result; } } \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/filters/SystemFilterReference.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/filters/SystemFilterReference.java index 14a16df3733..12677e18d9c 100644 --- a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/filters/SystemFilterReference.java +++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/filters/SystemFilterReference.java @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2002, 2006 IBM Corporation. All rights reserved. + * Copyright (c) 2002, 2007 IBM Corporation. All rights reserved. * This program and the accompanying materials are made available under the terms * of the Eclipse Public License v1.0 which accompanies this distribution, and is * available at http://www.eclipse.org/legal/epl-v10.html @@ -11,7 +11,7 @@ * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * * Contributors: - * {Name} (company) - description of contribution. + * David Dykstal (IBM) - 142806: refactoring persistence framework ********************************************************************************/ package org.eclipse.rse.core.filters; @@ -20,6 +20,7 @@ import java.util.Iterator; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.Platform; +import org.eclipse.rse.core.model.IRSEPersistableContainer; import org.eclipse.rse.core.model.ISystemContainer; import org.eclipse.rse.core.model.ISystemContentsType; import org.eclipse.rse.core.references.IRSEBaseReferencedObject; @@ -479,11 +480,18 @@ public class SystemFilterReference extends SystemReferencingObject implements IA cachedContents.clear(); } } - public boolean commit() + + public boolean commit() { - // FIXME return false; } - + + public IRSEPersistableContainer getPersistableParent() { + return null; + } + + public IRSEPersistableContainer[] getPersistableChildren() { + return new IRSEPersistableContainer[0]; + } } \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/DummyHost.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/DummyHost.java index e561ade0954..de7be9c5373 100644 --- a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/DummyHost.java +++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/DummyHost.java @@ -12,6 +12,7 @@ * * Contributors: * Martin Oberhuber (Wind River) - [175262] IHost.getSystemType() should return IRSESystemType + * David Dykstal (IBM) - 142806: refactoring persistence framework ********************************************************************************/ package org.eclipse.rse.core.model; @@ -60,6 +61,8 @@ public class DummyHost extends PlatformObject implements IHost return null; } + + public String getLocalDefaultUserId() { return null; @@ -213,7 +216,6 @@ public class DummyHost extends PlatformObject implements IHost public void setDirty(boolean flag) { - //Auto-generated method stub } public boolean commit() @@ -228,7 +230,27 @@ public class DummyHost extends PlatformObject implements IHost public void setWasRestored(boolean flag) { - //Auto-generated method stub + } + + public IRSEPersistableContainer getPersistableParent() { + return null; + } + + public IRSEPersistableContainer[] getPersistableChildren() { + return new IRSEPersistableContainer[0]; + } + + public boolean isTainted() { + return false; + } + + public void beginRestore() { + } + + public void endRestore() { + } + + public void setTainted(boolean flag) { } } \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/Host.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/Host.java index 4173ecceda3..cd89bb2f90d 100644 --- a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/Host.java +++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/Host.java @@ -16,6 +16,7 @@ * Uwe Stieber (Wind River) - Dynamic system type provider extensions. * - Moved to package org.eclipse.rse.model for being extendable. * Martin Oberhuber (Wind River) - [175262] IHost.getSystemType() should return IRSESystemType + * David Dykstal (IBM) - 142806: refactoring persistence framework ********************************************************************************/ package org.eclipse.rse.core.model; @@ -496,22 +497,22 @@ public class Host extends RSEModelObject implements IHost { defaultUserId = newDefaultUserId; } - /* (non-Javadoc) - * @see org.eclipse.rse.core.model.RSEModelObject#setDirty(boolean) - */ - public void setDirty(boolean flag) { - super.setDirty(flag); - ISystemHostPool myPool = getHostPool(); - if (myPool != null && flag) { - myPool.setDirty(true); - } - } - /* (non-Javadoc) * @see org.eclipse.rse.core.model.IRSEPersistableContainer#commit() */ public boolean commit() { - return RSECorePlugin.getThePersistenceManager().commit(this); + ISystemProfile profile = getSystemProfile(); + boolean result = profile.commit(); + return result; + } + + public IRSEPersistableContainer getPersistableParent() { + return _profile; + } + + public IRSEPersistableContainer[] getPersistableChildren() { + IConnectorService[] result = getConnectorServices(); + return result; } } \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/IRSEPersistableContainer.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/IRSEPersistableContainer.java index 5fef4142294..6a2cd1bca8a 100644 --- a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/IRSEPersistableContainer.java +++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/IRSEPersistableContainer.java @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2006 IBM Corporation. All rights reserved. + * Copyright (c) 2006, 2007 IBM Corporation. All rights reserved. * This program and the accompanying materials are made available under the terms * of the Eclipse Public License v1.0 which accompanies this distribution, and is * available at http://www.eclipse.org/legal/epl-v10.html @@ -11,29 +11,21 @@ * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * * Contributors: - * {Name} (company) - description of contribution. + * David Dykstal (IBM) - adding new persistence support + * David Dykstal (IBM) - 142806: refactoring persistence framework ********************************************************************************/ package org.eclipse.rse.core.model; +/** + * This is the interface for all objects that contain persistent data. + * The objects themselves may not have a persistent form, but can lie in the + * persistence heirarchy and be reconstructed when the persistent form is restored. + * An example of this is the SytemFilterPoolManager, which is itself not persisted, but + * has this interface since it can be reconstructed from its ordering and exists + * in the parent chain from SystemFilterPool to SystemProfile. + */ public interface IRSEPersistableContainer { - /** - * An object is dirty if a change has been made to it that requires - * it to be persisted. - * @return true if the object is dirty - */ - public boolean isDirty(); - - /** - * An object is dirty if a change has been made to it that requires - * it to be persisted. Objects should usually mark themselves dirty - * when a persistable change is made. However, there may be a need - * to mark related objects dirty as well. - * Setting this value to false should be done only in the persistence - * manager after the object has been written to the DOM. - * @param flag true if the object must be persisted. - */ - public void setDirty(boolean flag); /** * Request a persistence manager to persist this object. @@ -49,10 +41,92 @@ public interface IRSEPersistableContainer { public boolean wasRestored(); /** - * The the "restored" state of the object. Only persistence managers - * should do this. + * Sets the restored state of the object. Only persistence managers + * should do this. Persistable objects should be initially created with + * this as false and the persistence manager set this to true. + * This attribute is "sticky" in the face of most property changes. + * It should be set false if the object is renamed or re-parented. * @param flag true if the object was restored. */ public void setWasRestored(boolean flag); + + /** + * Notifies the object that it is being restored. Typically this will + * suppress any marking of the object as dirty and related objects as + * tainted while the restore is taking place. Should be used only by + * persistence providers. + */ + public void beginRestore(); + + /** + * Notifies the object that it is has been restored. This will + * enable the object to be marked as dirty if subsequent changes + * are made to it. Should be used only by persistence providers. + */ + public void endRestore(); + + /** + * An object is dirty if a change has been made to it that requires + * it to be persisted. + * @return true if the object is dirty + */ + public boolean isDirty(); + + /** + *

An object is dirty if a change has been made to it that requires + * it to be persisted. Objects should usually mark themselves dirty + * when a persistable change is made. However, there may be a need + * to mark related objects dirty as well. + *

Persistable changes are: + *

+ *

A rename may also cause a parent to be marked dirty if the + * parent refers to the child by name. + *

Setting this value to false should be done only in the persistence + * manager after the object has been written to the DOM. + *

Marking an object as dirty must cause it and all of its ancestors + * in the persistence hierarchy to be marked as tainted. + * @param flag true if the object must be persisted. + */ + public void setDirty(boolean flag); + + /** + * An object is tainted if it contains an object that is dirty + * somewhere in its containment hierarchy. + * @return true if the object is tainted. + */ + public boolean isTainted(); + + /** + * Sets the tainted attribute for this object. This should set to + * true only by child objects when they have been marked dirty or tainted. + * Setting this to true will cause all parent objects in the containment + * hierarchy to be marked tainted. Setting this to false will cause all + * children to be marked as not tainted. + * It should be set to false only by a persistence manager when the + * object has been committed. + * @param flag the tainted state of the object. + */ + public void setTainted(boolean flag); + + /** + * Retrieve the parent of this object in the persistence containment hierarchy. + * This is related to, but not necessarily the same as, the model hierarchy. + * @return the parent persistable object. This is null if there is no parent. + */ + public IRSEPersistableContainer getPersistableParent(); + + /** + * Retrieves the children of this object in the persistence containment hierarchy. + * This is related to, but not necessarily the same as, the model hierarchy. + * @return the array of persistable children in the order they are to be stored in the + * persistent form. This is an empty array if there are no children. + */ + public IRSEPersistableContainer[] getPersistableChildren(); } \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/ISystemProfile.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/ISystemProfile.java index d1eb5857a0b..12c291b6e88 100644 --- a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/ISystemProfile.java +++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/ISystemProfile.java @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2002, 2006 IBM Corporation. All rights reserved. + * Copyright (c) 2002, 2007 IBM Corporation. All rights reserved. * This program and the accompanying materials are made available under the terms * of the Eclipse Public License v1.0 which accompanies this distribution, and is * available at http://www.eclipse.org/legal/epl-v10.html @@ -11,13 +11,14 @@ * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * * Contributors: - * {Name} (company) - description of contribution. + * David Dykstal (IBM) - 142806: refactoring persistence framework ********************************************************************************/ package org.eclipse.rse.core.model; import org.eclipse.rse.core.filters.ISystemFilterPool; import org.eclipse.rse.core.subsystems.ISubSystemConfiguration; +import org.eclipse.rse.persistence.IRSEPersistenceProvider; // @@ -96,4 +97,21 @@ public interface ISystemProfile extends IRSEModelObject { * Return true if this profile is currently active for this user */ public boolean isActive(); + + /** + * Each profile is persisted by a persistence provider. This returns the instance of the + * persistence provider used for this profile. New profiles will use the default persistence + * provider unless one is set by some other means. + * @return The persistence provider used for saving and restoring this profile. + */ + public IRSEPersistenceProvider getPersistenceProvider(); + + /** + * Sets the persistence provider for the use of this profile. If this is not called then + * this profile will be persisted by the default persistence provider. This will typically + * be set by either a persistence persistence provider when restoring a profile or by a migration + * utility when converting profiles from one form to another. + * @param provider the persistence provider to use when saving this profile. + */ + public void setPersistenceProvider(IRSEPersistenceProvider provider); } \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/PropertySetContainer.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/PropertySetContainer.java index a3639e3e306..bc5d9662eb2 100644 --- a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/PropertySetContainer.java +++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/PropertySetContainer.java @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2006 IBM Corporation. All rights reserved. + * Copyright (c) 2006, 2007 IBM Corporation. All rights reserved. * This program and the accompanying materials are made available under the terms * of the Eclipse Public License v1.0 which accompanies this distribution, and is * available at http://www.eclipse.org/legal/epl-v10.html @@ -11,7 +11,7 @@ * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * * Contributors: - * {Name} (company) - description of contribution. + * David Dykstal (IBM) - 142806: refactoring persistence framework ********************************************************************************/ package org.eclipse.rse.core.model; @@ -22,7 +22,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -public class PropertySetContainer implements IPropertySetContainer { +public abstract class PropertySetContainer extends RSEPersistableObject implements IPropertySetContainer { private Map _propertySets; public PropertySetContainer() { diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/RSEModelObject.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/RSEModelObject.java index 4036815450f..ae2347b2d6d 100644 --- a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/RSEModelObject.java +++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/RSEModelObject.java @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2006 IBM Corporation. All rights reserved. + * Copyright (c) 2006, 2007 IBM Corporation. All rights reserved. * This program and the accompanying materials are made available under the terms * of the Eclipse Public License v1.0 which accompanies this distribution, and is * available at http://www.eclipse.org/legal/epl-v10.html @@ -11,7 +11,7 @@ * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * * Contributors: - * {Name} (company) - description of contribution. + * David Dykstal (IBM) - 142806: refactoring persistence framework ********************************************************************************/ package org.eclipse.rse.core.model; @@ -25,30 +25,6 @@ import org.eclipse.rse.internal.core.model.RSEModelResources; * */ public abstract class RSEModelObject extends PropertySetContainer implements IRSEModelObject { - protected boolean _isDirty = true; - protected boolean _wasRestored = false; - - /* (non-Javadoc) - * @see org.eclipse.rse.core.persistance.IRSEPersistableContainer#isDirty() - */ - public final boolean isDirty() { - return _isDirty; - } - - /* (non-Javadoc) - * @see org.eclipse.rse.core.persistance.IRSEPersistableContainer#setDirty(boolean) - */ - public void setDirty(boolean flag) { - _isDirty = flag; - } - - public final boolean wasRestored() { - return _wasRestored; - } - - public final void setWasRestored(boolean flag) { - _wasRestored = flag; - } public String getDescription() { return RSEModelResources.RESID_MODELOBJECTS_MODELOBJECT_DESCRIPTION; diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/RSEPersistableObject.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/RSEPersistableObject.java new file mode 100644 index 00000000000..cdf575f6471 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/RSEPersistableObject.java @@ -0,0 +1,66 @@ +package org.eclipse.rse.core.model; + +public abstract class RSEPersistableObject implements IRSEPersistableContainer { + + private boolean _isDirty = false; + private boolean _wasRestored = false; + private boolean _isTainted = false; + private boolean _restoring = false; + + public RSEPersistableObject() { + super(); + } + + public final boolean isDirty() { + return _isDirty; + } + + public final void setDirty(boolean flag) { + if (!_restoring) { + _isDirty = flag; + if (flag) { + setTainted(true); + } + } + } + + public final void beginRestore() { + _restoring = true; + } + + public final void endRestore() { + _restoring = false; + setWasRestored(true); + } + + public final boolean wasRestored() { + return _wasRestored; + } + + public final void setWasRestored(boolean flag) { + _wasRestored = flag; + } + + public final boolean isTainted() { + return _isTainted; + } + + public final void setTainted(boolean flag) { + if (!_restoring) { + _isTainted = flag; + if (_isTainted) { + IRSEPersistableContainer parent = getPersistableParent(); + if (parent != null) { + parent.setTainted(true); + } + } else { + IRSEPersistableContainer[] children = getPersistableChildren(); + for (int i = 0; i < children.length; i++) { + IRSEPersistableContainer child = children[i]; + child.setTainted(false); + } + } + } + } + +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/subsystems/AbstractConnectorService.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/subsystems/AbstractConnectorService.java index fd480e2e1fd..64d97abc581 100644 --- a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/subsystems/AbstractConnectorService.java +++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/subsystems/AbstractConnectorService.java @@ -13,6 +13,7 @@ * Contributors: * David Dykstal (IBM) - 168977: refactoring IConnectorService and ServerLauncher hierarchies * Martin Oberhuber (Wind River) - [175262] IHost.getSystemType() should return IRSESystemType + * David Dykstal (IBM) - 142806: refactoring persistence framework ********************************************************************************/ package org.eclipse.rse.core.subsystems; @@ -23,6 +24,7 @@ import java.util.Vector; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.rse.core.RSECorePlugin; import org.eclipse.rse.core.model.IHost; +import org.eclipse.rse.core.model.IRSEPersistableContainer; import org.eclipse.rse.core.model.RSEModelObject; /** @@ -118,10 +120,13 @@ public abstract class AbstractConnectorService extends RSEModelObject implements public void setRemoteServerLauncherProperties(IServerLauncherProperties newRemoteServerLauncher) { } + /* (non-Javadoc) + * @see org.eclipse.rse.core.subsystems.IConnectorService#hasRemoteServerLauncherProperties() + */ public final boolean hasRemoteServerLauncherProperties() { return getRemoteServerLauncherProperties() != null; } - + /* (non-Javadoc) * @see org.eclipse.rse.core.subsystems.IConnectorService#addCommunicationsListener(org.eclipse.rse.core.subsystems.ICommunicationsListener) */ @@ -236,7 +241,23 @@ public abstract class AbstractConnectorService extends RSEModelObject implements * @see org.eclipse.rse.core.model.IRSEPersistableContainer#commit() */ public final boolean commit() { - return RSECorePlugin.getThePersistenceManager().commit(getHost()); + return getHost().commit(); + } + + /* (non-Javadoc) + * @see org.eclipse.rse.core.model.IRSEPersistableContainer#getPersistableParent() + */ + public final IRSEPersistableContainer getPersistableParent() { + return _host; + } + + public IRSEPersistableContainer[] getPersistableChildren() { + List children = new ArrayList(20); + children.add(getRemoteServerLauncherProperties()); + children.addAll(_registeredSubSystems); + IRSEPersistableContainer[] result = new IRSEPersistableContainer[children.size()]; + children.toArray(result); + return result; } /* (non-Javadoc) diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/subsystems/AbstractDelegatingConnectorService.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/subsystems/AbstractDelegatingConnectorService.java index dde761f5595..3be1c4312d7 100644 --- a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/subsystems/AbstractDelegatingConnectorService.java +++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/subsystems/AbstractDelegatingConnectorService.java @@ -10,12 +10,15 @@ * * Contributors: * David Dykstal (IBM) - 168977: refactoring IConnectorService and ServerLauncher hierarchies + * David Dykstal (IBM) - 142806: refactoring persistence framework ********************************************************************************/ package org.eclipse.rse.core.subsystems; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.rse.core.model.IHost; import org.eclipse.rse.core.model.IPropertySet; +import org.eclipse.rse.core.model.IRSEPersistableContainer; +import org.eclipse.rse.core.model.RSEPersistableObject; public abstract class AbstractDelegatingConnectorService implements IDelegatingConnectorService { @@ -748,5 +751,53 @@ public abstract class AbstractDelegatingConnectorService implements IDelegatingC } return false; } + + public boolean isTainted() { + IConnectorService conServ = getRealConnectorService(); + if (conServ != null) + { + return conServ.isTainted(); + } + return false; + } + + public void setTainted(boolean flag) { + IConnectorService conServ = getRealConnectorService(); + if (conServ != null) + { + conServ.setTainted(flag); + } + } + + public IRSEPersistableContainer getPersistableParent() { + return getHost(); + } + + public void beginRestore() { + IConnectorService conServ = getRealConnectorService(); + if (conServ != null) + { + conServ.beginRestore(); + } + } + + public void endRestore() { + IConnectorService conServ = getRealConnectorService(); + if (conServ != null) + { + conServ.endRestore(); + } + } + + public IRSEPersistableContainer[] getPersistableChildren() { + IConnectorService conServ = getRealConnectorService(); + if (conServ != null) + { + return conServ.getPersistableChildren(); + } + return null; + } + + } diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/filters/SystemFilter.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/filters/SystemFilter.java index 2c153124f45..cc80a577db4 100644 --- a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/filters/SystemFilter.java +++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/filters/SystemFilter.java @@ -11,19 +11,19 @@ * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * * Contributors: - * {Name} (company) - description of contribution. + * David Dykstal (IBM) - 142806: refactoring persistence framework ********************************************************************************/ package org.eclipse.rse.internal.core.filters; import java.io.File; import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import java.util.Vector; import org.eclipse.core.resources.IFolder; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.Platform; -import org.eclipse.rse.core.RSECorePlugin; import org.eclipse.rse.core.filters.IRSEFilterNamingPolicy; import org.eclipse.rse.core.filters.ISystemFilter; import org.eclipse.rse.core.filters.ISystemFilterConstants; @@ -33,6 +33,8 @@ import org.eclipse.rse.core.filters.ISystemFilterPoolManager; import org.eclipse.rse.core.filters.ISystemFilterPoolManagerProvider; import org.eclipse.rse.core.filters.ISystemFilterString; import org.eclipse.rse.core.filters.SystemFilterSimple; +import org.eclipse.rse.core.model.IRSEPersistableContainer; +import org.eclipse.rse.core.model.ISystemProfile; import org.eclipse.rse.core.references.IRSEReferencedObject; import org.eclipse.rse.internal.core.model.RSEModelResources; import org.eclipse.rse.internal.references.SystemReferencedObject; @@ -1037,7 +1039,7 @@ public class SystemFilter extends SystemReferencedObject implements ISystemFilte public void setType(String newType) { type = newType; - _isDirty = true; + setDirty(true); } /** @@ -1365,7 +1367,27 @@ public class SystemFilter extends SystemReferencedObject implements ISystemFilte public boolean commit() { - return RSECorePlugin.getThePersistenceManager().commit(this); + ISystemProfile profile = getSystemFilterPoolManager().getSystemProfile(); + boolean result = profile.commit(); + return result; + } + + public IRSEPersistableContainer getPersistableParent() { + IRSEPersistableContainer result = getParentFilterContainer(); + return result; + } + + public IRSEPersistableContainer[] getPersistableChildren() { + List children = new ArrayList(20); + if (nestedFilters != null) { + children.addAll(nestedFilters); + } + if (filterStringVector != null) { + children.addAll(filterStringVector); + } + IRSEPersistableContainer[] result = new IRSEPersistableContainer[children.size()]; + children.toArray(result); + return result; } } \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/filters/SystemFilterPool.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/filters/SystemFilterPool.java index 7a188949bb7..0644ff9d875 100644 --- a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/filters/SystemFilterPool.java +++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/filters/SystemFilterPool.java @@ -12,6 +12,7 @@ * * Contributors: * David Dykstal (IBM) - removing implementation of ISystemFilterSavePolicies, ISystemFilterConstants + * David Dykstal (IBM) - 142806: refactoring persistence framework ********************************************************************************/ package org.eclipse.rse.internal.core.filters; @@ -31,6 +32,8 @@ import org.eclipse.rse.core.filters.ISystemFilterPool; import org.eclipse.rse.core.filters.ISystemFilterPoolManager; import org.eclipse.rse.core.filters.ISystemFilterPoolManagerProvider; import org.eclipse.rse.core.filters.SystemFilterNamingPolicy; +import org.eclipse.rse.core.model.IRSEPersistableContainer; +import org.eclipse.rse.core.model.ISystemProfile; import org.eclipse.rse.internal.core.model.RSEModelResources; import org.eclipse.rse.internal.references.SystemPersistableReferencedObject; @@ -1319,7 +1322,17 @@ public class SystemFilterPool extends SystemPersistableReferencedObject public boolean commit() { - return RSECorePlugin.getThePersistenceManager().commit(this); + ISystemProfile profile = getSystemFilterPoolManager().getSystemProfile(); + boolean result = profile.commit(); + return result; } - + + public IRSEPersistableContainer getPersistableParent() { + return mgr; + } + + public IRSEPersistableContainer[] getPersistableChildren() { + return getSystemFilters(); + } + } \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/filters/SystemFilterPoolReference.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/filters/SystemFilterPoolReference.java index 91b0fcf8feb..5187120038b 100644 --- a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/filters/SystemFilterPoolReference.java +++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/filters/SystemFilterPoolReference.java @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2002, 2006 IBM Corporation. All rights reserved. + * Copyright (c) 2002, 2007 IBM Corporation. All rights reserved. * This program and the accompanying materials are made available under the terms * of the Eclipse Public License v1.0 which accompanies this distribution, and is * available at http://www.eclipse.org/legal/epl-v10.html @@ -11,7 +11,7 @@ * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * * Contributors: - * {Name} (company) - description of contribution. + * David Dykstal (IBM) - 142806: refactoring persistence framework ********************************************************************************/ package org.eclipse.rse.internal.core.filters; @@ -31,6 +31,7 @@ import org.eclipse.rse.core.filters.ISystemFilterPoolReference; import org.eclipse.rse.core.filters.ISystemFilterPoolReferenceManager; import org.eclipse.rse.core.filters.ISystemFilterPoolReferenceManagerProvider; import org.eclipse.rse.core.filters.ISystemFilterReference; +import org.eclipse.rse.core.model.IRSEPersistableContainer; import org.eclipse.rse.core.model.ISystemProfile; import org.eclipse.rse.core.model.ISystemRegistry; import org.eclipse.rse.core.subsystems.ISubSystem; @@ -243,4 +244,23 @@ public class SystemFilterPoolReference extends SystemPersistableReferencingObjec return false; // return RSEUIPlugin.getThePersistenceManager().commit(getProvider().); } + + /* (non-Javadoc) + * @see org.eclipse.rse.core.model.IRSEPersistableContainer#getPersistableParent() + */ + public IRSEPersistableContainer getPersistableParent() { + IRSEPersistableContainer parent = null; + ISystemFilterPoolReferenceManagerProvider provider = getProvider(); + if (provider instanceof IRSEPersistableContainer) { + parent = (IRSEPersistableContainer) provider; + } + return parent; + } + + /* (non-Javadoc) + * @see org.eclipse.rse.core.model.IRSEPersistableContainer#getPersistableChildren() + */ + public IRSEPersistableContainer[] getPersistableChildren() { + return new IRSEPersistableContainer[0]; + } } \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/filters/SystemFilterString.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/filters/SystemFilterString.java index 18d73c41d42..745d06b8af3 100644 --- a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/filters/SystemFilterString.java +++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/filters/SystemFilterString.java @@ -11,7 +11,7 @@ * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * * Contributors: - * {Name} (company) - description of contribution. + * David Dykstal (IBM) - 142806: refactoring persistence framework ********************************************************************************/ package org.eclipse.rse.internal.core.filters; @@ -24,6 +24,7 @@ import org.eclipse.rse.core.filters.ISystemFilterConstants; import org.eclipse.rse.core.filters.ISystemFilterPoolManager; import org.eclipse.rse.core.filters.ISystemFilterPoolManagerProvider; import org.eclipse.rse.core.filters.ISystemFilterString; +import org.eclipse.rse.core.model.IRSEPersistableContainer; import org.eclipse.rse.core.model.RSEModelObject; import org.eclipse.rse.core.references.IRSEBaseReferencingObject; import org.eclipse.rse.internal.core.model.RSEModelResources; @@ -290,7 +291,16 @@ public class SystemFilterString extends RSEModelObject implements ISystemFilterS public boolean commit() { - return RSECorePlugin.getThePersistenceManager().commit(getParentSystemFilter()); + boolean result = getParentSystemFilter().commit(); + return result; + } + + public IRSEPersistableContainer getPersistableParent() { + return parentFilter; + } + + public IRSEPersistableContainer[] getPersistableChildren() { + return new IRSEPersistableContainer[0]; } } \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/subsystems/ServerLauncher.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/subsystems/ServerLauncher.java index 438a84bdc01..a6dd219f05b 100644 --- a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/subsystems/ServerLauncher.java +++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/subsystems/ServerLauncher.java @@ -12,11 +12,13 @@ * * Contributors: * David Dykstal (IBM) - 168977: refactoring IConnectorService and ServerLauncher hierarchies + * David Dykstal (IBM) - 142806: refactoring persistence framework ********************************************************************************/ package org.eclipse.rse.internal.core.subsystems; import org.eclipse.rse.core.RSECorePlugin; import org.eclipse.rse.core.model.IPropertySet; +import org.eclipse.rse.core.model.IRSEPersistableContainer; import org.eclipse.rse.core.model.RSEModelObject; import org.eclipse.rse.core.subsystems.IConnectorService; import org.eclipse.rse.core.subsystems.IServerLauncherProperties; @@ -51,6 +53,14 @@ public abstract class ServerLauncher extends RSEModelObject implements IServerLa { return _connectorService; } + + public IRSEPersistableContainer getPersistableParent() { + return _connectorService; + } + + public IRSEPersistableContainer[] getPersistableChildren() { + return new IRSEPersistableContainer[0]; + } /** * Clone the contents of this server launcher into the given server launcher @@ -101,7 +111,7 @@ public abstract class ServerLauncher extends RSEModelObject implements IServerLa public boolean commit() { - return RSECorePlugin.getThePersistenceManager().commit(getConnectorService().getHost()); + return getConnectorService().getHost().commit(); } diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/persistence/RSEPersistenceManager.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/persistence/RSEPersistenceManager.java index 30a68edc25e..19417360382 100644 --- a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/persistence/RSEPersistenceManager.java +++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/persistence/RSEPersistenceManager.java @@ -11,7 +11,7 @@ * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * * Contributors: - * {Name} (company) - description of contribution. + * David Dykstal (IBM) - 142806: refactoring persistence framework ********************************************************************************/ package org.eclipse.rse.internal.persistence; @@ -31,7 +31,6 @@ import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.preferences.IPreferencesService; import org.eclipse.rse.core.RSECorePlugin; import org.eclipse.rse.core.SystemResourceManager; -import org.eclipse.rse.core.filters.ISystemFilter; import org.eclipse.rse.core.filters.ISystemFilterPool; import org.eclipse.rse.core.filters.ISystemFilterPoolManager; import org.eclipse.rse.core.filters.ISystemFilterPoolManagerProvider; @@ -41,7 +40,6 @@ import org.eclipse.rse.core.model.ISystemHostPool; import org.eclipse.rse.core.model.ISystemProfile; import org.eclipse.rse.core.model.ISystemProfileManager; import org.eclipse.rse.core.model.ISystemRegistry; -import org.eclipse.rse.core.subsystems.ISubSystem; import org.eclipse.rse.internal.persistence.dom.RSEDOMExporter; import org.eclipse.rse.internal.persistence.dom.RSEDOMImporter; import org.eclipse.rse.logging.Logger; @@ -61,26 +59,8 @@ public class RSEPersistenceManager implements IRSEPersistenceManager { private static final int STATE_IMPORTING = 1; private static final int STATE_EXPORTING = 2; - private Map loadedProviders = new HashMap(10); - private int _currentState = STATE_NONE; - private RSEDOMExporter _exporter; - private RSEDOMImporter _importer; - private static IProject remoteSystemsProject = null; public static final String RESOURCE_PROJECT_NAME = "RemoteSystemsConnections"; //$NON-NLS-1$ - - // private ISystemRegistry _registry; - private ISystemProfileManager _profileManager; - - public RSEPersistenceManager(ISystemRegistry registry) { - // _registry = registry; - _profileManager = registry.getSystemProfileManager(); - _exporter = RSEDOMExporter.getInstance(); - _exporter.setSystemRegistry(registry); - _importer = RSEDOMImporter.getInstance(); - _importer.setSystemRegistry(registry); - } - /** * Get the default remote systems project. * @return IProject handle of the project. Use exists() to test existence. @@ -93,9 +73,116 @@ public class RSEPersistenceManager implements IRSEPersistenceManager { return remoteSystemsProject; } + private Map loadedProviders = new HashMap(10); - public void registerRSEPersistenceProvider(String id, IRSEPersistenceProvider provider) { - loadedProviders.put(id, provider); + private int _currentState = STATE_NONE; + private RSEDOMExporter _exporter; + + private RSEDOMImporter _importer; + + public RSEPersistenceManager(ISystemRegistry registry) { + // _registry = registry; + _exporter = RSEDOMExporter.getInstance(); + _exporter.setSystemRegistry(registry); + _importer = RSEDOMImporter.getInstance(); + _importer.setSystemRegistry(registry); + } + + public boolean commit(ISystemFilterPoolManager filterPoolManager) { + if (filterPoolManager.isDirty()) { + commit(filterPoolManager.getSystemProfile()); + filterPoolManager.setDirty(false); + } + return false; + } + + public boolean commit(ISystemHostPool connectionPool) { + if (connectionPool.isDirty()) { + commit(connectionPool.getSystemProfile()); + connectionPool.setDirty(false); + } + /* + Host[] connections = connectionPool.getHosts(); + for (int idx = 0; idx < connections.length; idx++) + { + if (!saveHost(connectionPool, connections[idx])) + { + return false; + } + } + return true; + */ + return false; // all persistence should be at profile level + } + + /** + * Attempt to save single profile to disk. + */ + public boolean commit(ISystemProfile profile) { + if (profile != null) { + return save(profile, false); + } + return false; + } + + /** + * Save all profiles to disk + */ + public boolean commit(ISystemProfileManager profileManager) { + + ISystemProfile[] profiles = profileManager.getSystemProfiles(); + for (int idx = 0; idx < profiles.length; idx++) { + try { + commit(profiles[idx]); + } catch (Exception exc) { + Logger logger = RSECorePlugin.getDefault().getLogger(); + String profileName = profiles[idx].getName(); + String message = "Error saving profile " + profileName; //$NON-NLS-1$ + logger.logError(message, exc); + return false; + } + } + + return true; + } + + /* (non-Javadoc) + * @see org.eclipse.rse.persistence.IRSEPersistenceManager#deleteProfile(java.lang.String) + */ + public void deleteProfile(final String profileName) { + Job job = new Job(Messages.RSEPersistenceManager_DeleteProfileJobName) { + protected IStatus run(IProgressMonitor monitor) { + IRSEPersistenceProvider provider = getRSEPersistenceProvider(); + IStatus result = provider.deleteProfile(profileName, monitor); + return result; + } + }; + job.schedule(); + } + + private RSEDOM exportRSEDOM(ISystemProfile profile, boolean force) { + RSEDOM dom = _exporter.createRSEDOM(profile, force); + return dom; + } + + /** + * Retrieves the persistence provider for this workbench configuration. + * Several persistence providers may be registered, but only one persistence provider can be used. + * This persistence provider's identifier is specified in the org.eclipse.rse.persistenceProvider + * preference and can be specified a product's config.ini file. + * It is retrieved using the platform's preference service. + * If no such preference exists the default "org.eclipse.rse.persistence.PropertyFileProvider" + * is used. + * @return the default IRSEPersistenceProvider for this installation. + */ + public IRSEPersistenceProvider getRSEPersistenceProvider() { + IPreferencesService service = Platform.getPreferencesService(); + String qualifier = "org.eclipse.rse"; //$NON-NLS-1$ + String preferenceName = "persistenceProvider"; //$NON-NLS-1$ + String defaultProviderName = "org.eclipse.rse.persistence.PropertyFileProvider"; //$NON-NLS-1$ + String providerName = service.getString(qualifier, preferenceName, defaultProviderName, null); + IRSEPersistenceProvider provider = getRSEPersistenceProvider(providerName); + return provider; } /** @@ -137,212 +224,24 @@ public class RSEPersistenceManager implements IRSEPersistenceManager { return provider; } - /** - * Retrieves the persistence provider for this workbench configuration. - * Several persistence providers may be registered, but only one persistence provider can be used. - * This persistence provider's identifier is specified in the org.eclipse.rse.persistenceProvider - * preference and can be specified a product's config.ini file. - * It is retrieved using the platform's preference service. - * If no such preference exists the default "org.eclipse.rse.persistence.PropertyFileProvider" - * is used. - * @return the default IRSEPersistenceProvider for this installation. - */ - public IRSEPersistenceProvider getRSEPersistenceProvider() { - IPreferencesService service = Platform.getPreferencesService(); - String qualifier = "org.eclipse.rse"; //$NON-NLS-1$ - String preferenceName = "persistenceProvider"; //$NON-NLS-1$ - String defaultProviderName = "org.eclipse.rse.persistence.PropertyFileProvider"; //$NON-NLS-1$ - String providerName = service.getString(qualifier, preferenceName, defaultProviderName, null); - IRSEPersistenceProvider provider = getRSEPersistenceProvider(providerName); - return provider; - } - - public boolean restore(ISystemProfileManager profileManager) { - return load(profileManager); - } - - /** - * Restore a profile of a given name from disk... - */ - protected ISystemProfile restoreProfile(ISystemProfileManager mgr, String name) throws Exception { - /* - * FIXME String fileName = mgr.getRootSaveFileName(name); java.util.List - * ext = null;//FIXME - * getMOFHelpers().restore(SystemResourceManager.getProfileFolder(name),fileName); - * // should be exactly one profile... Iterator iList = ext.iterator(); - * SystemProfile profile = (SystemProfile)iList.next(); - * mgr.initialize(profile, name); return profile; - */ - return null; - } - - /** - * Save all profiles to disk - */ - public boolean commit(ISystemProfileManager profileManager) { - - ISystemProfile[] profiles = profileManager.getSystemProfiles(); - for (int idx = 0; idx < profiles.length; idx++) { - try { - commit(profiles[idx]); - } catch (Exception exc) { - Logger logger = RSECorePlugin.getDefault().getLogger(); - String profileName = profiles[idx].getName(); - String message = "Error saving profile " + profileName; //$NON-NLS-1$ - logger.logError(message, exc); - return false; - } + private RSEDOM importRSEDOM(String domName) { + RSEDOM dom = null; + IRSEPersistenceProvider provider = getRSEPersistenceProvider(); + if (provider != null) { + dom = provider.loadRSEDOM(domName, null); + } else { + Logger logger = RSECorePlugin.getDefault().getLogger(); + logger.logError("Persistence provider is not available.", null); //$NON-NLS-1$ } - - return true; + return dom; } - public boolean restore(ISystemHostPool connectionPool) { - return false; + public synchronized boolean isExporting() { + return _currentState == STATE_EXPORTING; } - /** - * Restore a connection of a given name from disk... - */ - protected IHost restoreHost(ISystemHostPool hostPool, String connectionName) throws Exception { - /* - * FIXME //System.out.println("in SystemConnectionPoolImpl#restore for - * connection " + connectionName); String fileName = - * getRootSaveFileName(connectionName); - * //System.out.println(".......fileName = " + fileName); - * //System.out.println(".......folderName = " + - * getConnectionFolder(connectionName).getName()); java.util.List ext = - * getMOFHelpers().restore(getConnectionFolder(connectionName),fileName); - * // should be exactly one profile... Iterator iList = ext.iterator(); - * SystemConnection connection = (SystemConnection)iList.next(); if - * (connection != null) { if - * (!connection.getAliasName().equalsIgnoreCase(connectionName)) { - * RSEUIPlugin.logDebugMessage(this.getClass().getName(),"Incorrect - * alias name found in connections.xmi file for " + connectionName+". - * Name was reset"); connection.setAliasName(connectionName); // just in - * case! } internalAddConnection(connection); } return connection; - */ - return null; - } - - public boolean commit(ISystemHostPool connectionPool) { - if (connectionPool.isDirty()) { - commit(connectionPool.getSystemProfile()); - connectionPool.setDirty(false); - } - /* - Host[] connections = connectionPool.getHosts(); - for (int idx = 0; idx < connections.length; idx++) - { - if (!saveHost(connectionPool, connections[idx])) - { - return false; - } - } - return true; - */ - return false; // all persistence should be at profile level - } - - public boolean commit(ISystemFilterPoolManager filterPoolManager) { - if (filterPoolManager.isDirty()) { - commit(filterPoolManager.getSystemProfile()); - filterPoolManager.setDirty(false); - } - return false; - } - - public boolean commit(ISystemFilterPool filterPool) { - if (filterPool.isDirty()) { - commit(filterPool.getSystemFilterPoolManager().getSystemProfile()); - filterPool.setDirty(false); - } - return false; - } - - public boolean restore(ISystemFilterPool filterPool) { - //System.out.println("restore filterpool"); - // DWD function Is this method really needed? - return false; - } - - public boolean commit(ISystemFilter filter) { - // System.out.println("commit filter"); - // DWD function Is this method really needed? - /* - if (filter.isDirty()) - { - System.out.println("saving filter: "+filter.getName()); - filter.setDirty(false); - } - */ - /* FIXME - //initMOF(); assume caller did this! - String fileName = getRootSaveFileName(this); - IFolder folder = getFolder(this); - getMOFHelpers().save(folder,fileName, this); - */ - return false; - } - - public ISystemFilterPool restoreFilterPool(String name) { - //System.out.println("restore filter pool "+name); - // DWD function is this method really needed? - return null; - } - - public boolean commit(ISubSystem subSystem) { - - if (subSystem.isDirty()) { - // System.out.println("updated " + subSystem.getName()); - try { - // commit everything for now - commit(_profileManager); - subSystem.setDirty(false); - } catch (Exception e) { - e.printStackTrace(); - } - return true; - } - - /* - // FIXME - if (subSystem.isDirty()) - { - System.out.println("saving subsystem: "+subSystem.getName()); - } - */ - return false; - } - - /** - * Creates a filter pool manager for a particular SubSystemConfiguration and SystemProfile. Called - * "restore" for historcal reasons. - * @param profile the profile that will own this ISystemFilterPoolManager. There is one of these per profile. - * @param logger the logging object for logging errors. Each ISystemFilterPoolManager has one of these. - * @param caller The creator/owner of this ISystemFilterPoolManager, this ends up being a SubSystemConfiguration. - * @param name the name of the manager to restore. File name is derived from it when saving to one file. - * @return the "restored" manager. - */ - public ISystemFilterPoolManager restoreFilterPoolManager(ISystemProfile profile, Logger logger, ISystemFilterPoolManagerProvider caller, String name) { - SystemFilterPoolManager mgr = SystemFilterPoolManager.createManager(profile); - mgr.initialize(logger, caller, name); // core data - mgr.setWasRestored(false); // managers are not "restored from disk" since they are not persistent of themselves - return mgr; - } - - /** - * Attempt to save single profile to disk. - */ - public boolean commit(ISystemProfile profile) { - if (profile != null) { - return save(profile, false); - } - return false; - } - - public boolean commit(IHost host) { - return commit(host.getSystemProfile()); + public synchronized boolean isImporting() { + return _currentState == STATE_IMPORTING; } /** @@ -387,6 +286,85 @@ public class RSEPersistenceManager implements IRSEPersistenceManager { return successful; } + public void registerRSEPersistenceProvider(String id, IRSEPersistenceProvider provider) { + loadedProviders.put(id, provider); + } + + public boolean restore(ISystemFilterPool filterPool) { + //System.out.println("restore filterpool"); + // DWD function Is this method really needed? + return false; + } + + public boolean restore(ISystemHostPool connectionPool) { + return false; + } + + public boolean restore(ISystemProfileManager profileManager) { + return load(profileManager); + } + + public ISystemFilterPool restoreFilterPool(String name) { + //System.out.println("restore filter pool "+name); + // DWD function is this method really needed? + return null; + } + + /** + * Creates a filter pool manager for a particular SubSystemConfiguration and SystemProfile. Called + * "restore" for historcal reasons. + * @param profile the profile that will own this ISystemFilterPoolManager. There is one of these per profile. + * @param logger the logging object for logging errors. Each ISystemFilterPoolManager has one of these. + * @param caller The creator/owner of this ISystemFilterPoolManager, this ends up being a SubSystemConfiguration. + * @param name the name of the manager to restore. File name is derived from it when saving to one file. + * @return the "restored" manager. + */ + public ISystemFilterPoolManager restoreFilterPoolManager(ISystemProfile profile, Logger logger, ISystemFilterPoolManagerProvider caller, String name) { + SystemFilterPoolManager mgr = SystemFilterPoolManager.createManager(profile); + mgr.initialize(logger, caller, name); // core data + mgr.setWasRestored(false); // managers are not "restored from disk" since they are not persistent of themselves + return mgr; + } + + /** + * Restore a connection of a given name from disk... + */ + protected IHost restoreHost(ISystemHostPool hostPool, String connectionName) throws Exception { + /* + * FIXME //System.out.println("in SystemConnectionPoolImpl#restore for + * connection " + connectionName); String fileName = + * getRootSaveFileName(connectionName); + * //System.out.println(".......fileName = " + fileName); + * //System.out.println(".......folderName = " + + * getConnectionFolder(connectionName).getName()); java.util.List ext = + * getMOFHelpers().restore(getConnectionFolder(connectionName),fileName); + * // should be exactly one profile... Iterator iList = ext.iterator(); + * SystemConnection connection = (SystemConnection)iList.next(); if + * (connection != null) { if + * (!connection.getAliasName().equalsIgnoreCase(connectionName)) { + * RSEUIPlugin.logDebugMessage(this.getClass().getName(),"Incorrect + * alias name found in connections.xmi file for " + connectionName+". + * Name was reset"); connection.setAliasName(connectionName); // just in + * case! } internalAddConnection(connection); } return connection; + */ + return null; + } + + /** + * Restore a profile of a given name from disk... + */ + protected ISystemProfile restoreProfile(ISystemProfileManager mgr, String name) throws Exception { + /* + * FIXME String fileName = mgr.getRootSaveFileName(name); java.util.List + * ext = null;//FIXME + * getMOFHelpers().restore(SystemResourceManager.getProfileFolder(name),fileName); + * // should be exactly one profile... Iterator iList = ext.iterator(); + * SystemProfile profile = (SystemProfile)iList.next(); + * mgr.initialize(profile, name); return profile; + */ + return null; + } + /** * Writes the RSE model to a DOM and schedules writing of that DOM to disk. * May, in fact, update an existing DOM instead of creating a new one. @@ -421,47 +399,8 @@ public class RSEPersistenceManager implements IRSEPersistenceManager { return result; } - /* (non-Javadoc) - * @see org.eclipse.rse.persistence.IRSEPersistenceManager#deleteProfile(java.lang.String) - */ - public void deleteProfile(final String profileName) { - Job job = new Job(Messages.RSEPersistenceManager_DeleteProfileJobName) { - protected IStatus run(IProgressMonitor monitor) { - IRSEPersistenceProvider provider = getRSEPersistenceProvider(); - IStatus result = provider.deleteProfile(profileName, monitor); - return result; - } - }; - job.schedule(); - } - - public synchronized boolean isExporting() { - return _currentState == STATE_EXPORTING; - } - - public synchronized boolean isImporting() { - return _currentState == STATE_IMPORTING; - } - private synchronized void setState(int state) { _currentState = state; } - private RSEDOM exportRSEDOM(ISystemProfile profile, boolean force) { - RSEDOM dom = _exporter.createRSEDOM(profile, force); - return dom; - } - - private RSEDOM importRSEDOM(String domName) { - RSEDOM dom = null; - IRSEPersistenceProvider provider = getRSEPersistenceProvider(); - if (provider != null) { - dom = provider.loadRSEDOM(domName, null); - } else { - Logger logger = RSECorePlugin.getDefault().getLogger(); - logger.logError("Persistence provider is not available.", null); //$NON-NLS-1$ - } - return dom; - } - } \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/persistence/IRSEPersistenceManager.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/persistence/IRSEPersistenceManager.java index bd95c02a364..0a3d107e3e2 100644 --- a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/persistence/IRSEPersistenceManager.java +++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/persistence/IRSEPersistenceManager.java @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2006 IBM Corporation. All rights reserved. + * Copyright (c) 2006, 2007 IBM Corporation. All rights reserved. * This program and the accompanying materials are made available under the terms * of the Eclipse Public License v1.0 which accompanies this distribution, and is * available at http://www.eclipse.org/legal/epl-v10.html @@ -11,23 +11,54 @@ * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * * Contributors: - * {Name} (company) - description of contribution. + * David Dykstal (IBM) - 142806: refactoring persistence framework ********************************************************************************/ package org.eclipse.rse.persistence; -import org.eclipse.rse.core.filters.ISystemFilter; import org.eclipse.rse.core.filters.ISystemFilterPool; import org.eclipse.rse.core.filters.ISystemFilterPoolManager; import org.eclipse.rse.core.filters.ISystemFilterPoolManagerProvider; -import org.eclipse.rse.core.model.IHost; import org.eclipse.rse.core.model.ISystemHostPool; import org.eclipse.rse.core.model.ISystemProfile; import org.eclipse.rse.core.model.ISystemProfileManager; -import org.eclipse.rse.core.subsystems.ISubSystem; import org.eclipse.rse.logging.Logger; public interface IRSEPersistenceManager { + + public boolean commit(ISystemFilterPoolManager filterPoolManager); + + /** + * Save all connections in the connection pool + * @param connectionPool + * @return true if successful + */ + public boolean commit(ISystemHostPool connectionPool); + + /** + * Save this profile + * @param profile + * @return true if successful + */ + public boolean commit(ISystemProfile profile); + + /** + * Save all profiles + * @param profileManager + * @return true if successful + */ + public boolean commit(ISystemProfileManager profileManager); + + /** + * Delete the persistent form of a profile. + * @param profileName The name of the profile to delete + */ + public void deleteProfile(String profileName); + + public boolean isExporting(); + + public boolean isImporting(); + /** * Register the persistence provider to be used when saving and restoring RSE doms. * The provider is registered under the provided id. @@ -37,20 +68,11 @@ public interface IRSEPersistenceManager { public void registerRSEPersistenceProvider(String id, IRSEPersistenceProvider provider); /** - * Restore all profiles - * @param profileManager - * @return true if successful + * Restore all the filters for the filter pool + * @param filterPool + * @return true if sucessful */ - public boolean restore(ISystemProfileManager profileManager); - - /** - * Save all profiles - * @param profileManager - * @return true if successful - */ - public boolean commit(ISystemProfileManager profileManager); - - public boolean commit(IHost host); + public boolean restore(ISystemFilterPool filterPool); /** * Restore all connections in the connection pool @@ -60,34 +82,11 @@ public interface IRSEPersistenceManager { public boolean restore(ISystemHostPool connectionPool); /** - * Save all connections in the connection pool - * @param connectionPool + * Restore all profiles + * @param profileManager * @return true if successful */ - public boolean commit(ISystemHostPool connectionPool); - - public boolean commit(ISystemFilterPoolManager filterPoolManager); - - /** - * Save all the filters in the filter pool - * @param filterPool - * @return true if successful - */ - public boolean commit(ISystemFilterPool filterPool); - - /** - * Save this filter - * @param filter - * @return true if successful - */ - public boolean commit(ISystemFilter filter); - - /** - * Restore all the filters for the filter pool - * @param filterPool - * @return true if sucessful - */ - public boolean restore(ISystemFilterPool filterPool); + public boolean restore(ISystemProfileManager profileManager); /** * Restore the filter pool @@ -96,29 +95,5 @@ public interface IRSEPersistenceManager { */ public ISystemFilterPool restoreFilterPool(String name); - /** - * Save this subsystem - * @param subSystem - * @return true if successful - */ - public boolean commit(ISubSystem subSystem); - - /** - * Save this profile - * @param profile - * @return true if successful - */ - public boolean commit(ISystemProfile profile); - public ISystemFilterPoolManager restoreFilterPoolManager(ISystemProfile profile, Logger logger, ISystemFilterPoolManagerProvider caller, String name); - - public boolean isExporting(); - - public boolean isImporting(); - - /** - * Delete the persistent form of a profile. - * @param profileName The name of the profile to delete - */ - public void deleteProfile(String profileName); } \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.ui/model/org/eclipse/rse/internal/model/SystemHostPool.java b/rse/plugins/org.eclipse.rse.ui/model/org/eclipse/rse/internal/model/SystemHostPool.java index c7ec2f792a0..efe27093e21 100644 --- a/rse/plugins/org.eclipse.rse.ui/model/org/eclipse/rse/internal/model/SystemHostPool.java +++ b/rse/plugins/org.eclipse.rse.ui/model/org/eclipse/rse/internal/model/SystemHostPool.java @@ -14,6 +14,7 @@ * David Dykstal (IBM) - created and used RSEPReferencesManager * - moved SystemsPreferencesManager to a new plugin * Martin Oberhuber (Wind River) - [175262] IHost.getSystemType() should return IRSESystemType + * David Dykstal (IBM) - 142806: refactoring persistence framework ********************************************************************************/ package org.eclipse.rse.internal.model; @@ -28,6 +29,7 @@ import org.eclipse.rse.core.RSECorePlugin; import org.eclipse.rse.core.RSEPreferencesManager; import org.eclipse.rse.core.model.Host; import org.eclipse.rse.core.model.IHost; +import org.eclipse.rse.core.model.IRSEPersistableContainer; import org.eclipse.rse.core.model.ISystemHostPool; import org.eclipse.rse.core.model.ISystemProfile; import org.eclipse.rse.core.model.RSEModelObject; @@ -508,70 +510,7 @@ public class SystemHostPool extends RSEModelObject implements ISystemHostPool invalidateCache(); } - // ------------------------- - // SAVE / RESTORE METHODS... - // ------------------------- /** - * Save all connections to disk. - * Attempts to save all of them, swallowing exceptions, then at the end throws the last exception caught. - */ - public boolean commit() - { - return RSECorePlugin.getThePersistenceManager().commit(this); - } - - /** - * Attempt to save single connection to disk. - */ - public void commit(IHost connection) - { - commit(); - } - - /** - * Restore connections from disk - */ - protected void restore() - throws Exception - { - //System.out.println("... . in pool.restore "); - - //FIXME - } - - /** - * Restore a connection of a given name from disk... - */ - protected IHost restore(String connectionName) - throws Exception - { - /*FIXME - //System.out.println("in SystemConnectionPoolImpl#restore for connection " + connectionName); - String fileName = getRootSaveFileName(connectionName); - //System.out.println(".......fileName = " + fileName); - //System.out.println(".......folderName = " + getConnectionFolder(connectionName).getName()); - java.util.List ext = getMOFHelpers().restore(getConnectionFolder(connectionName),fileName); - - // should be exactly one profile... - Iterator iList = ext.iterator(); - SystemConnection connection = (SystemConnection)iList.next(); - if (connection != null) - { - if (!connection.getAliasName().equalsIgnoreCase(connectionName)) - { - RSEUIPlugin.logDebugMessage(this.getClass().getName(),"Incorrect alias name found in connections.xmi file for " + connectionName+". Name was reset"); - connection.setAliasName(connectionName); // just in case! - } - internalAddConnection(connection); - } - return connection; - */ - return null; - } - - - - /** * Return the unqualified save file name with the extension .xmi */ protected static String getSaveFileName(IHost connection) @@ -596,11 +535,6 @@ public class SystemHostPool extends RSEModelObject implements ISystemHostPool return fileName; } - - - - - public String toString() { if (getName() == null) @@ -608,6 +542,7 @@ public class SystemHostPool extends RSEModelObject implements ISystemHostPool else return getName(); } + /** * @generated This field/method will be replaced during code generation */ @@ -651,5 +586,77 @@ public class SystemHostPool extends RSEModelObject implements ISystemHostPool return result.toString(); } + /** + * Restore connections from disk + */ + protected void restore() + throws Exception + { + //System.out.println("... . in pool.restore "); + + //FIXME + } + + /** + * Restore a connection of a given name from disk... + */ + protected IHost restore(String connectionName) + throws Exception + { + /*FIXME + //System.out.println("in SystemConnectionPoolImpl#restore for connection " + connectionName); + String fileName = getRootSaveFileName(connectionName); + //System.out.println(".......fileName = " + fileName); + //System.out.println(".......folderName = " + getConnectionFolder(connectionName).getName()); + java.util.List ext = getMOFHelpers().restore(getConnectionFolder(connectionName),fileName); + + // should be exactly one profile... + Iterator iList = ext.iterator(); + SystemConnection connection = (SystemConnection)iList.next(); + if (connection != null) + { + if (!connection.getAliasName().equalsIgnoreCase(connectionName)) + { + RSEUIPlugin.logDebugMessage(this.getClass().getName(),"Incorrect alias name found in connections.xmi file for " + connectionName+". Name was reset"); + connection.setAliasName(connectionName); // just in case! + } + internalAddConnection(connection); + } + return connection; + */ + return null; + } + + /** + * System host pools are not persisted and do not exist in the persistence hierarchy. + * @return null + */ + public IRSEPersistableContainer getPersistableParent() { + return null; + } + + public IRSEPersistableContainer[] getPersistableChildren() { + return new IRSEPersistableContainer[0]; + } + + // ------------------------- + // SAVE / RESTORE METHODS... + // ------------------------- + /** + * Save all connections to disk. + * Attempts to save all of them, swallowing exceptions, then at the end throws the last exception caught. + */ + public boolean commit() + { + return RSECorePlugin.getThePersistenceManager().commit(this); + } + + /** + * Attempt to save single connection to disk. + */ + public void commit(IHost connection) + { + commit(); + } } \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.ui/model/org/eclipse/rse/internal/model/SystemProfile.java b/rse/plugins/org.eclipse.rse.ui/model/org/eclipse/rse/internal/model/SystemProfile.java index df944423156..3293c7c1d52 100644 --- a/rse/plugins/org.eclipse.rse.ui/model/org/eclipse/rse/internal/model/SystemProfile.java +++ b/rse/plugins/org.eclipse.rse.ui/model/org/eclipse/rse/internal/model/SystemProfile.java @@ -11,7 +11,7 @@ * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * * Contributors: - * {Name} (company) - description of contribution. + * David Dykstal (IBM) - 142806: refactoring persistence framework ********************************************************************************/ package org.eclipse.rse.internal.model; @@ -22,12 +22,14 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.rse.core.filters.ISystemFilterPool; import org.eclipse.rse.core.filters.ISystemFilterPoolManager; import org.eclipse.rse.core.model.IHost; +import org.eclipse.rse.core.model.IRSEPersistableContainer; import org.eclipse.rse.core.model.ISystemProfile; import org.eclipse.rse.core.model.ISystemProfileManager; import org.eclipse.rse.core.model.ISystemRegistry; import org.eclipse.rse.core.model.RSEModelObject; import org.eclipse.rse.core.subsystems.ISubSystemConfiguration; import org.eclipse.rse.internal.core.model.RSEModelResources; +import org.eclipse.rse.persistence.IRSEPersistenceProvider; import org.eclipse.rse.ui.RSEUIPlugin; /** @@ -38,6 +40,7 @@ public class SystemProfile extends RSEModelObject implements ISystemProfile, IAd { private ISystemProfileManager mgr; + private IRSEPersistenceProvider provider; private boolean active; private String name = null; private boolean defaultPrivate = false; @@ -100,8 +103,7 @@ public class SystemProfile extends RSEModelObject implements ISystemProfile, IAd } } ISystemFilterPool[] allPools = new ISystemFilterPool[poolsVector.size()]; - for (int idx=0; idx