diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/filters/ISystemFilterPoolManager.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/filters/ISystemFilterPoolManager.java index 460fcc39b70..a18ebb374a3 100644 --- a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/filters/ISystemFilterPoolManager.java +++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/filters/ISystemFilterPoolManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2007 IBM Corporation and others. + * Copyright (c) 2002, 2008 IBM Corporation and others. * 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 @@ -12,7 +12,8 @@ * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * * Contributors: - * {Name} (company) - description of contribution. + * David Dykstal (IBM) - [197036] All filter pools created on clean workspace + * cleaned javadoc for renameSystemFilterPool *******************************************************************************/ package org.eclipse.rse.core.filters; @@ -237,19 +238,13 @@ public interface ISystemFilterPoolManager extends IRSEPersistableContainer { public boolean preTestRenameFilterPool(ISystemFilterPool pool) throws Exception; /** - * Rename a given filter pool. Dependending on the save policy, the - * appropriate file or folder on disk will also be renamed. - *
- * Does the following: + * Rename a filter pool. *
true
)
+ * which is preferred since we do not want to load subsystem configurations unless necessary.
* @param systemType system type to filter
- * @param filterDuplicateServiceSubSystemConfigurations set false by default
+ * @param filterDuplicates if true and the subsystem configuration uses services then return only one
+ * subsystem configuration that supports this service. Which configuration is returned is undefined.
+ * @return an array of subsystem configurations meeting the criteria
*/
- public ISubSystemConfiguration[] getSubSystemConfigurationsBySystemType(IRSESystemType systemType, boolean filterDuplicateServiceSubSystemConfigurations);
+ public ISubSystemConfiguration[] getSubSystemConfigurationsBySystemType(IRSESystemType systemType, boolean filterDuplicates);
+
+ /**
+ * Return all subsystem configurations which support the given system type.
+ * If the type is null, returns all subsystem confgurations.
+ * @param systemType system type to filter
+ * @param filterDuplicates if true and the subsystem configuration uses services then return only one
+ * subsystem configuration that supports this service. Which configuration is returned is undefined.
+ * @param activate if true activate the respective configurations if not already active, if false return only those that are already active.
+ * @return an array of subsystem configurations meeting the criteria
+ */
+ public ISubSystemConfiguration[] getSubSystemConfigurationsBySystemType(IRSESystemType systemType, boolean filterDuplicates, boolean activate);
// ----------------------------------
// SYSTEMVIEWINPUTPROVIDER METHODS...
@@ -211,59 +228,52 @@ public interface ISystemRegistry extends ISchedulingRule, IAdaptable, ISystemVie
public void setSystemProfileActive(ISystemProfile profile, boolean makeActive);
/**
- * Return the list of connector services provided for the given host
- * @param conn the host
+ * Return the list of connector services currently configured for the given host
+ * @param host the host
* @return the list of connector services
*/
- public IConnectorService[] getConnectorServices(IHost conn);
+ public IConnectorService[] getConnectorServices(IHost host);
// ----------------------------
// SUBSYSTEM METHODS...
// ----------------------------
/**
- * Return list of subsystem objects for a given connection. If the subsystems have
- * not all been read into memory, this loads them up
+ * Return list of subsystem objects for a given host.
+ * @param host the host for which to return the subsystems that are currently known.
+ * @return an array of subsystem objects known to this host.
*/
- public ISubSystem[] getSubSystems(IHost conn);
+ public ISubSystem[] getSubSystems(IHost host);
/**
- * Return list of subsystem objects for a given connection. Use the force
- * flag to indicate whether or not to restore from disk
+ * Return list of subsystem objects for a given connection.
+ * @param host the host for which to return the subsystems that are known.
+ * @param force if true, force the creation of subsystems for which the system type of this host is configured.
+ * Use this parameter with care since it can cause extensive initialization.
+ * @return the list of subsystems known to this host, possibly after the creation of subsystems.
+ * @deprecated Use {@link #getSubSystems(IHost)} instead, the "force" parameter is now ignored.
*/
- public ISubSystem[] getSubSystems(IHost conn, boolean force);
+ public ISubSystem[] getSubSystems(IHost host, boolean force);
/**
* Get those subsystems that are registered against a given connection,
* which are an instance of the given interface class.
- *
- * This method activates all subsystem configurations of the given
- * host in order to support checking against the given interface.
- * If lazy loading is desired, use {@link #getSubSystems(IHost, boolean)}
- * with a boolean parameter false
instead, and check against
- * the class instance in client code.
*
- * This method activates all subsystem configurations of the given
- * host in order to support checking against the given interface.
- * If lazy loading is desired, use {@link #getSubSystems(IHost, boolean)}
- * with a boolean parameter false
instead, and check against
- * the class instance in client code.
*
+ * @param profileName Name of the system profile to which the host is to be added.
+ * @param systemType system type of the new host.
+ * @param hostName unique host name within the profile.
+ * @param hostAddress ip name of host.
+ * @param description optional description of the connection. May be null.
+ * @param createSubSystems true
to create subsystems for the host, false
otherwise.
+ * @return IHost object, or null if it failed to create. This is typically because the hostName is not unique. Call getLastException() if necessary.
+ * @since 3.0
+ */
+ public IHost createHost(String profileName, IRSESystemType systemType, String hostName, String hostAddress, String description, boolean createSubSystems) throws Exception;
+
+ /**
* Update an existing host given the new information.
* This method:
*
* This interface is not intended to be implemented by clients. Subsystem - * configuration implementations must subclass {@link SubSystemConfiguration} + * configuration implementations must subclass SubSystemConfiguration * rather than implementing this interface directly. *
*/ @@ -351,11 +352,13 @@ public interface ISubSystemConfiguration extends ISystemFilterPoolManagerProvide /** * Called by SystemRegistry's renameSystemProfile method to ensure we update our - * subsystem names within each subsystem. - *- * This is called AFTER changing the profile's name!! + * subsystem names within each subsystem. + * This should be invoked after changing the profile's name. + * @param subsystem the subsystem to be updated + * @param oldProfileName the old profile name + * @param newProfileName the new profile name */ - public void renameSubSystemProfile(ISubSystem ss, String oldProfileName, String newProfileName); + public void renameSubSystemProfile(ISubSystem subsystem, String oldProfileName, String newProfileName); /** * Called by SystemRegistry's renameSystemProfile method to pre-test if we are going to run into errors on a @@ -488,7 +491,22 @@ public interface ISubSystemConfiguration extends ISystemFilterPoolManagerProvide // FILTER POOL METHODS... // --------------------------------- /** - * Get the filter pool manager for the given profile + * A subsystem configuration has a filter pool manager for each profile. + * Get the filter pool manager for the given profile. + * @param profile The system profile for which to get the manager. + * @param force if true then create the default filters for this subsystem configuration in this profile. This should only be + * done during initial subsystem creation, not during subsystem restore. + * @return a filter pool manager + */ + public ISystemFilterPoolManager getFilterPoolManager(ISystemProfile profile, boolean force); + + /** + * A subsystem configuration has a filter pool manager for each profile. + * Get the filter pool manager for the given profile. + * Do not force the creation of default filter pools. + * Fully equivalent to getFilterPoolManager(profile, false). + * @param profile The system profile for which to get the manager. + * @return a filter pool manager */ public ISystemFilterPoolManager getFilterPoolManager(ISystemProfile profile); diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/filters/SystemFilterPoolManager.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/filters/SystemFilterPoolManager.java index 2f8f9243e8d..61f52f8043d 100644 --- a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/filters/SystemFilterPoolManager.java +++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/internal/core/filters/SystemFilterPoolManager.java @@ -12,6 +12,7 @@ * * Contributors: * David Dykstal (IBM) - 142806: refactoring persistence framework + * David Dykstal (IBM) - [197036] removed caching mechanism to clean up logic ********************************************************************************/ package org.eclipse.rse.internal.core.filters; @@ -57,10 +58,10 @@ import org.eclipse.rse.logging.Logger; * This class is not intended to be subclassed by clients. */ public class SystemFilterPoolManager extends RSEPersistableObject implements ISystemFilterPoolManager { - private ISystemFilterPool[] poolArray = null; // cache for performance +// private ISystemFilterPool[] poolArray = null; // cache for performance private ISystemFilterPoolManagerProvider caller = null; private Object poolMgrData; - private Vector poolNames; +// private Vector poolNames; private boolean initialized = false; private boolean suspendCallbacks = false; @@ -152,7 +153,8 @@ public class SystemFilterPoolManager extends RSEPersistableObject implements ISy */ protected boolean singleFilterStringOnly = SINGLE_FILTER_STRING_ONLY_EDEFAULT; - protected List pools = null; + protected List pools = new ArrayList(3); +// protected List pools = null; /** * Constructor @@ -210,7 +212,7 @@ public class SystemFilterPoolManager extends RSEPersistableObject implements ISy initialize(logger, caller, name); // core data } setSupportsNestedFilters(allowNestedFilters); // cascade it down - invalidatePoolCache(); +// invalidatePoolCache(); // List pools = getPools(); // ISystemFilterPool pool = null; // Vector poolNames = getSystemFilterPoolNamesVector(); @@ -397,17 +399,20 @@ public class SystemFilterPoolManager extends RSEPersistableObject implements ISy * Return array of SystemFilterPools managed by this manager. */ public ISystemFilterPool[] getSystemFilterPools() { - //System.out.println("Inside getSFPools for mgr "+getName()+". poolArray null? "+(poolArray==null)); - if ((poolArray == null) || (getPools().size() != poolArray.length)) { - List pools = getPools(); - poolArray = new ISystemFilterPool[pools.size()]; - Iterator i = pools.iterator(); - int idx = 0; - while (i.hasNext()) - poolArray[idx++] = (ISystemFilterPool) i.next(); - //System.out.println("Pool array created. length = "+poolArray.length); - } - return poolArray; + ISystemFilterPool[] result = new ISystemFilterPool[pools.size()]; + pools.toArray(result); + return result; +// //System.out.println("Inside getSFPools for mgr "+getName()+". poolArray null? "+(poolArray==null)); +// if ((poolArray == null) || (getPools().size() != poolArray.length)) { +// List pools = getPools(); +// poolArray = new ISystemFilterPool[pools.size()]; +// Iterator i = pools.iterator(); +// int idx = 0; +// while (i.hasNext()) +// poolArray[idx++] = (ISystemFilterPool) i.next(); +// //System.out.println("Pool array created. length = "+poolArray.length); +// } +// return poolArray; } /** @@ -425,24 +430,31 @@ public class SystemFilterPoolManager extends RSEPersistableObject implements ISy * Get list of filter pool names currently existing. */ public Vector getSystemFilterPoolNamesVector() { - List pools = getPools(); - if ((poolNames == null) || (poolNames.size() != pools.size())) // been invalidated? - { - poolNames = new Vector(); - Iterator i = pools.iterator(); - while (i.hasNext()) - poolNames.addElement(((ISystemFilterPool) i.next()).getName()); + Vector result = new Vector(pools.size()); + for (Iterator z = pools.iterator(); z.hasNext();) { + ISystemFilterPool pool = (ISystemFilterPool) z.next(); + String poolName = pool.getName(); + result.add(poolName); } - return poolNames; + return result; +// List pools = getPools(); +// if ((poolNames == null) || (poolNames.size() != pools.size())) // been invalidated? +// { +// poolNames = new Vector(); +// Iterator i = pools.iterator(); +// while (i.hasNext()) +// poolNames.addElement(((ISystemFilterPool) i.next()).getName()); +// } +// return poolNames; } /* * Call this to invalidate array cache after any activity */ - private void invalidatePoolCache() { - poolArray = null; - poolNames = null; - } +// private void invalidatePoolCache() { +// poolArray = null; +// poolNames = null; +// } /** * Create a new filter pool. @@ -473,9 +485,9 @@ public class SystemFilterPoolManager extends RSEPersistableObject implements ISy pool.setSystemFilterPoolManager(this); pool.setStringsCaseSensitive(areStringsCaseSensitive()); pool.setSupportsDuplicateFilterStrings(isSetSupportsDuplicateFilterStrings() && supportsDuplicateFilterStrings()); - List pools = getPools(); +// List pools = getPools(); pools.add(pool); - invalidatePoolCache(); +// invalidatePoolCache(); commit(pool); if ((caller != null) && !suspendCallbacks) { caller.filterEventFilterPoolCreated(pool); @@ -501,63 +513,22 @@ public class SystemFilterPoolManager extends RSEPersistableObject implements ISy * @param pool The filter pool object to physically delete */ public void deleteSystemFilterPool(ISystemFilterPool pool) throws Exception { - - // remove all references IRSEBaseReferencingObject[] refs = pool.getReferencingObjects(); - //boolean needsSave = false; if (refs != null) { for (int idx = 0; idx < refs.length; idx++) { if (refs[idx] instanceof ISystemFilterPoolReference) { ISystemFilterPoolReference fpRef = (ISystemFilterPoolReference) refs[idx]; ISystemFilterPoolReferenceManager fprMgr = fpRef.getFilterPoolReferenceManager(); - if (fprMgr != null) fprMgr.removeSystemFilterPoolReference(fpRef, false);// false means don't dereference + if (fprMgr != null) { + fprMgr.removeSystemFilterPoolReference(fpRef, false); // false means don't dereference DWD why? + } } } } - // DWD removing a pool should mark its parent profile as dirty and cause a save to be "scheduled" - - // remove from model - List pools = getPools(); pools.remove(pool); - invalidatePoolCache(); - - /* FIXME - // now in EMF, the pools are "owned" by the Resource, and only referenced by this pool manager, - // so I don't think just removing it from the manager is enough... it must also be removed from its - // resource. Phil. - Resource res = pool.eResource(); - if (res != null) - res.getContents().remove(pool); - - // remove from disk - if ( (savePolicy == SystemFilterConstants.SAVE_POLICY_ONE_FILEANDFOLDER_PER_POOL) || - (savePolicy == SystemFilterConstants.SAVE_POLICY_ONE_FILE_PER_FILTER) ) - { - String expectedFolderName = derivePoolFolderName(poolName); - if (expectedFolderName.equals(poolFolder.getName())) - { - // folder name equals what we would have named it if left to us. - // assumption is this folder only exists to hold this pool! - if (poolFolder.exists()) - getResourceHelpers().deleteResource(poolFolder); - } - } - else if (savePolicy == SystemFilterConstants.SAVE_POLICY_ONE_FILE_PER_POOL_SAME_FOLDER) - { - String poolFileName = SystemFilterPoolImpl.getSaveFileName(getMOFHelpers(),pool); - IFile poolFile = SystemResourceHelpers.getResourceHelpers().getFile(poolFolder,poolFileName); - if (poolFile.exists()) - getResourceHelpers().deleteResource(poolFile); - } - else // all pools in one file per manager. Just save it - { - commit(); - } - invalidatePoolCache(); - // if caller provider, callback to inform them of this event - if ((caller != null) && !suspendCallbacks) - caller.filterEventFilterPoolDeleted(pool); - */ + _profile.setDirty(true); + _profile.commit(); + getProvider().filterEventFilterPoolDeleted(pool); } /** @@ -576,174 +547,25 @@ public class SystemFilterPoolManager extends RSEPersistableObject implements ISy } /** - * Pre-test if we are going to run into any trouble renaming any of the files or folders - * used to persist a filter pool. - * @return true if everything seems ok, false if a file/folder is in use. + * Pre-test if we are going to run into any trouble renaming a filter pool. + * @return true if the pool can be renamed. */ public boolean preTestRenameFilterPool(ISystemFilterPool pool) throws Exception { - boolean ok = true; /* - * DWD this looks like it needs to be modified so that it queries the persistence - * manager to see if the pool can be renamed. The provider is in charge of determining - * pool names in the persistent form. The Manager will have to construct a DOM - * object for this pool and query the appropriate provider. - */ - /* FIXME - if ( (savePolicy == SystemFilterConstants.SAVE_POLICY_ONE_FILEANDFOLDER_PER_POOL) || - (savePolicy == SystemFilterConstants.SAVE_POLICY_ONE_FILE_PER_FILTER) ) - { - String expectedFolderName = derivePoolFolderName(pool.getName()); - boolean ourFolderName = expectedFolderName.equals(pool.getFolder().getName()); - // we must rename the old file... - String poolFileName = SystemFilterPoolImpl.getSaveFileName(getMOFHelpers(),pool); - IFile poolFile = getResourceHelpers().getFile(pool.getFolder(),poolFileName); - IFolder poolFolder = pool.getFolder(); - - // first, pre-test for file-in-use error: - boolean inUse = poolFile.exists() && SystemResourceHelpers.testIfResourceInUse(poolFile); - if (inUse) - { - SystemMessage msg = RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_FILE_INUSE); - msg.makeSubstitution(poolFile.getFullPath()); - throw new SystemMessageException(msg); - } - // next, pre-test for folder-in-use error: - if (ourFolderName) - { - inUse = poolFolder.exists() && SystemResourceHelpers.testIfResourceInUse(poolFolder); - if (inUse) - { - SystemMessage msg = RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_FOLDER_INUSE); - msg.makeSubstitution(poolFolder.getFullPath()); - throw new SystemMessageException(msg); - } - } - } - else if (savePolicy == SystemFilterConstants.SAVE_POLICY_ONE_FILE_PER_POOL_SAME_FOLDER) - { - String poolFileName = SystemFilterPoolImpl.getSaveFileName(getMOFHelpers(),pool); - IFile poolFile = getResourceHelpers().getFile(pool.getFolder(),poolFileName); - // first, pre-test for file-in-use error: - boolean inUse = poolFile.exists() && SystemResourceHelpers.testIfResourceInUse(poolFile); - if (inUse) - { - SystemMessage msg = RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_FILE_INUSE); - msg.makeSubstitution(poolFile.getFullPath()); - throw new SystemMessageException(msg); - } - } + * The default implementation returns true. Persistence providers should be able to handle this + * circumstance regardless. If a pool can be renamed internally, it should be able to be + * renamed in its persistent form. */ + boolean ok = true; return ok; } - /** - * Rename a given filter pool. Dependending on the save policy, the - * appropriate file or folder on disk will also be renamed. - *
- * Does the following: - *
- * To protect against crashes, if there are no subsystems, an array of length zero is returned. + /* (non-Javadoc) + * @see org.eclipse.rse.core.model.ISystemRegistry#getSubSystems(org.eclipse.rse.core.model.IHost, boolean) */ - public ISubSystem[] getSubSystems(IHost conn) - { - return getSubSystems(conn, ISubSystemConfiguration.FORCE_INTO_MEMORY); + public ISubSystem[] getSubSystems(IHost host, boolean force) { + return getSubSystems(host); } - /** - * Return list of subsystem objects for a given connection. - * Demand pages the subsystem factories into memory if they aren't already. - *
- * To protect against crashes, if there are no subsystems, an array of length zero is returned. + /* (non-Javadoc) + * @see org.eclipse.rse.core.model.ISystemRegistry#getSubSystems(org.eclipse.rse.core.model.IHost) */ - public ISubSystem[] getSubSystems(IHost conn, boolean force) - { - ISubSystem[] subsystems = null; - - if (subsystemConfigurationProxies != null) - { - List v = new ArrayList(); - for (int idx = 0; idx < subsystemConfigurationProxies.length; idx++) - { - if (!force && !subsystemConfigurationProxies[idx].isSubSystemConfigurationActive()) { - //avoid instantiation if not forced. - continue; - } - - if (subsystemConfigurationProxies[idx].appliesToSystemType(conn.getSystemType())) - { - ISubSystemConfiguration factory = subsystemConfigurationProxies[idx].getSubSystemConfiguration(); - if (factory != null) - { - ISubSystem[] sss = factory.getSubSystems(conn, force); - if (sss != null) - for (int jdx = 0; jdx < sss.length; jdx++) - v.add(sss[jdx]); + public ISubSystem[] getSubSystems(IHost host) { + IRSESystemType systemType = host.getSystemType(); + List subsystems = new ArrayList(); + if (subsystemConfigurationProxies != null) { + for (int i = 0; i < subsystemConfigurationProxies.length; i++) { + ISubSystemConfigurationProxy proxy = subsystemConfigurationProxies[i]; + if (proxy.appliesToSystemType(systemType)) { + if (proxy.isSubSystemConfigurationActive()) { + ISubSystemConfiguration config = proxy.getSubSystemConfiguration(); + ISubSystem[] ssArray = config.getSubSystems(host, false); + if (ssArray == null) { // create a subsystem for this connection and config + ssArray = this.createSubSystems(host, new ISubSystemConfiguration[] {config}); + } + subsystems.addAll(Arrays.asList(ssArray)); } } } - subsystems = (ISubSystem[])v.toArray(new ISubSystem[v.size()]); } - return subsystems; + ISubSystem[] result = new ISubSystem[subsystems.size()]; + subsystems.toArray(result); + return result; } /** @@ -1147,12 +1123,15 @@ public class SystemRegistry implements ISystemRegistry dataStream.append("."); //$NON-NLS-1$ dataStream.append(connectionName); return dataStream.toString(); - } - - public ISubSystem[] getSubsystems(IHost connection, Class subsystemInterface) + } + + /* (non-Javadoc) + * @see org.eclipse.rse.core.model.ISystemRegistry#getSubsystems(org.eclipse.rse.core.model.IHost, java.lang.Class) + */ + public ISubSystem[] getSubsystems(IHost host, Class subsystemInterface) { List matches = new ArrayList(); - ISubSystem[] allSS = connection.getSubSystems(); + ISubSystem[] allSS = getSubSystems(host); for (int i = 0; i < allSS.length; i++) { ISubSystem ss = allSS[i]; @@ -1164,10 +1143,13 @@ public class SystemRegistry implements ISystemRegistry return (ISubSystem[])matches.toArray(new ISubSystem[matches.size()]); } - public ISubSystem[] getServiceSubSystems(IHost connection, Class serviceType) + /* (non-Javadoc) + * @see org.eclipse.rse.core.model.ISystemRegistry#getServiceSubSystems(org.eclipse.rse.core.model.IHost, java.lang.Class) + */ + public ISubSystem[] getServiceSubSystems(IHost host, Class serviceType) { List matches = new ArrayList(); - ISubSystem[] allSS = connection.getSubSystems(); + ISubSystem[] allSS = getSubSystems(host); for (int i = 0; i < allSS.length; i++) { ISubSystem ss = allSS[i]; @@ -1187,9 +1169,9 @@ public class SystemRegistry implements ISystemRegistry * (non-Javadoc) * @see org.eclipse.rse.core.model.ISystemRegistry#getSubSystemsBySubSystemConfigurationCategory(java.lang.String, org.eclipse.rse.core.model.IHost) */ - public ISubSystem[] getSubSystemsBySubSystemConfigurationCategory(String factoryCategory, IHost connection) + public ISubSystem[] getSubSystemsBySubSystemConfigurationCategory(String factoryCategory, IHost host) { - ISubSystem[] subsystems = getSubSystems(connection); + ISubSystem[] subsystems = getSubSystems(host); if ((subsystems != null) && (subsystems.length > 0)) { Vector v = new Vector(); @@ -1658,82 +1640,116 @@ public class SystemRegistry implements ISystemRegistry } /** - * Create a connection object, given the connection pool and given all the possible attributes. - *
- * THE RESULTING CONNECTION OBJECT IS ADDED TO THE LIST OF EXISTING CONNECTIONS FOR YOU, IN - * THE PROFILE YOU SPECIFY. THE PROFILE IS ALSO SAVED TO DISK. + * Create a host object, given its host pool and its attributes. *
* This method: *
* @param profileName Name of the system profile the connection is to be added to.
- * @param systemType system type matching one of the system types
- * defined via the systemTypes extension point.
- * @param connectionName unique connection name.
- * @param hostName ip name of host.
+ * @param systemType system type matching one of the system types defined via the systemTypes extension point.
+ * @param hostName unique connection name.
+ * @param hostAddress IP name of host.
* @param description optional description of the connection. Can be null.
* @param defaultUserId userId to use as the default for the subsystems.
* @param defaultUserIdLocation one of the constants in {@link org.eclipse.rse.core.IRSEUserIdConstants}
- * that tells us where to set the user Id
+ * that tells us where to set the user Id
* @param createSubSystems true
to create subsystems for the host, false
otherwise.
* @param newConnectionWizardPages when called from the New Connection wizard this is union of the list of additional
- * wizard pages supplied by the subsystem factories that pertain to the specified system type. Else null.
+ * wizard pages supplied by the subsystem factories that pertain to the specified system type. Else null.
* @return SystemConnection object, or null if it failed to create. This is typically
- * because the connectionName is not unique. Call getLastException() if necessary.
+ * because the connectionName is not unique. Call getLastException() if necessary.
*/
- public IHost createHost(
- String profileName,
- IRSESystemType systemType,
- String connectionName,
- String hostName,
- String description,
- String defaultUserId,
- int defaultUserIdLocation,
- boolean createSubSystems,
- ISystemNewConnectionWizardPage[] newConnectionWizardPages)
- throws Exception {
- lastException = null;
- ISystemHostPool pool = getHostPool(profileName);
- IHost conn = null;
- boolean promptable = false; // systemType.equals(IRSESystemType.SYSTEMTYPE_PROMPT);
- try
- {
- // create, register and save new connection...
- if ((defaultUserId != null) && (defaultUserId.length() == 0))
- defaultUserId = null;
- conn = pool.createHost(systemType, connectionName, hostName, description, defaultUserId, defaultUserIdLocation);
- if (conn == null) // conn already exists
- {
- conn = pool.getHost(connectionName);
+ // FIXME need to remove ISystemNewConnectionWizardPage[] from this and replace with IAdaptable[]
+ public IHost createHost(final String profileName, final IRSESystemType systemType, final String hostName,
+ final String hostAddress, final String description, final String defaultUserId,
+ final int defaultUserIdLocation, final boolean createSubSystems,
+ final ISystemNewConnectionWizardPage[] newConnectionWizardPages) throws Exception {
+ final ISystemRegistry sr = this;
+ class CreateHostOperation implements ISystemProfileOperation {
+ private IHost host = null;
+ private ISubSystem[] subsystems = new ISubSystem[0];
+ IHost getHost() {
+ return host;
}
- if (promptable)
- conn.setPromptable(true);
- }
- catch (Exception exc)
- {
- lastException = exc;
- SystemBasePlugin.logError("Exception in createConnection for " + connectionName, exc); //$NON-NLS-1$
- throw exc;
- }
- if ((lastException == null) && !promptable && createSubSystems) {
- // only 1 factory used per service type
- ISubSystemConfiguration[] factories = getSubSystemConfigurationsBySystemType(systemType, true);
- ISubSystem subSystems[] = new ISubSystem[factories.length];
- for (int idx = 0; idx < factories.length; idx++) {
- ISubSystemConfiguration factory = factories[idx];
- ISystemNewConnectionWizardPage[] interestingPages = getApplicableWizardPages(factory, newConnectionWizardPages);
- subSystems[idx] = factory.createSubSystem(conn, true, interestingPages); // give it the opportunity to create a subsystem
+ public ISubSystem[] getSubSystems() {
+ return subsystems;
+ }
+ public IStatus run() {
+ IStatus status = Status.OK_STATUS;
+ ISystemHostPool pool = getHostPool(profileName);
+ try {
+ // create, register and save new connection...
+ String uid = defaultUserId;
+ if ((uid != null) && (uid.length() == 0)) {
+ uid = null;
+ }
+ host = pool.createHost(systemType, hostName, hostAddress, description, uid, defaultUserIdLocation);
+ if (host == null) { // did not create since host already exists
+ host = pool.getHost(hostName);
+ }
+ } catch (Exception e) {
+ String pluginId = RSEUIPlugin.getDefault().getSymbolicName();
+ String message = MessageFormat.format("Exception in createHost for {0}", new Object[] {hostName});
+ status = new Status(IStatus.ERROR, pluginId, message, e);
+ }
+ if (status.isOK()) {
+ if (createSubSystems) {
+ // determine the list of configs to use to create subsystems from
+ List configs = new ArrayList(10); // arbitrary but reasonable
+ if (newConnectionWizardPages != null) {
+ // if there are wizard pages need to at least use those
+ for (int i = 0; i < newConnectionWizardPages.length; i++) {
+ configs.add(newConnectionWizardPages[i].getSubSystemConfiguration());
+ }
+ // add any non-service subsystem configs that aren't already there that apply to this systemtype
+ ISubSystemConfiguration[] configsArray = getSubSystemConfigurationsBySystemType(systemType, false);
+ for (int i = 0; i < configsArray.length; i++) {
+ ISubSystemConfiguration config = configsArray[i];
+ boolean isStrange = !(config instanceof IServiceSubSystemConfiguration);
+ boolean isAbsent = !configs.contains(config);
+ if (isStrange && isAbsent) {
+ configs.add(config);
+ }
+ }
+ } else {
+ // just get the defaults with the service subsystems filtered
+ ISubSystemConfiguration[] configsArray = getSubSystemConfigurationsBySystemType(systemType, true);
+ configs = Arrays.asList(configsArray);
+ }
+ // only subsystem configuration is used per service type
+ subsystems = new ISubSystem[configs.size()];
+ ISystemProfile profile = host.getSystemProfile();
+ int i = 0;
+ for (Iterator z = configs.iterator(); z.hasNext();) {
+ ISubSystemConfiguration config = (ISubSystemConfiguration) z.next();
+ config.getFilterPoolManager(profile, true); // create the filter pool
+ ISystemNewConnectionWizardPage[] interestingPages = getApplicableWizardPages(config, newConnectionWizardPages);
+ subsystems[i] = config.createSubSystem(host, true, interestingPages); // give it the opportunity to create a subsystem
+ i++;
+ }
+ }
+ host.commit();
+ }
+ return status;
}
- FireNewHostEvents fire = new FireNewHostEvents(conn, subSystems, this);
- Display.getDefault().asyncExec(fire);
}
- conn.commit();
+ CreateHostOperation op = new CreateHostOperation();
+ IStatus status = SystemProfileManager.run(op);
+ lastException = (Exception) status.getException();
+ if (lastException != null) {
+ SystemBasePlugin.logError(status.getMessage(), lastException);
+ throw lastException;
+ }
+ IHost host = op.getHost();
+ ISubSystem[] subsystems = op.getSubSystems();
+ FireNewHostEvents fire = new FireNewHostEvents(host, subsystems, sr);
+ Display.getDefault().asyncExec(fire);
SystemPreferencesManager.setConnectionNamesOrder(); // update preferences order list
- return conn;
+ return host;
}
/*
@@ -1949,33 +1965,12 @@ public class SystemRegistry implements ISystemRegistry
return createHost(profileName, systemType, connectionName, hostName, description, true);
}
- /**
- * Create a connection object. This is a simplified version
- *
- * THE RESULTING CONNECTION OBJECT IS ADDED TO THE LIST OF EXISTING CONNECTIONS FOR YOU, IN - * THE PROFILE YOU SPECIFY. THE PROFILE IS ALSO SAVED TO DISK. - *
- * This method: - *
- * @param profileName Name of the system profile the connection is to be added to.
- * @param systemType system type matching one of the system types
- * defined via the systemTypes extension point.
- * @param connectionName unique connection name.
- * @param hostName ip name of host.
- * @param description optional description of the connection. Can be null.
- * @param createSubSystems true
to create subsystems for the host, false
otherwise.
- * @return SystemConnection object, or null if it failed to create. This is typically
- * because the connectionName is not unique. Call getLastException() if necessary.
- * @since 2.0
+ /* (non-Javadoc)
+ * @see org.eclipse.rse.core.model.ISystemRegistry#createHost(java.lang.String, org.eclipse.rse.core.IRSESystemType, java.lang.String, java.lang.String, java.lang.String, boolean)
*/
public IHost createHost(String profileName, IRSESystemType systemType, String connectionName, String hostName, String description, boolean createSubSystems) throws Exception
{
- return createHost(profileName, systemType, connectionName, hostName, description, null, IRSEUserIdConstants.USERID_LOCATION_HOST, null);
+ return createHost(profileName, systemType, connectionName, hostName, description, null, IRSEUserIdConstants.USERID_LOCATION_HOST, createSubSystems, null);
}
/*
@@ -2318,7 +2313,7 @@ public class SystemRegistry implements ISystemRegistry
public boolean isAnySubSystemConnected(IHost conn)
{
boolean any = false;
- ISubSystem[] subsystems = getSubSystems(conn, false);
+ ISubSystem[] subsystems = getSubSystems(conn);
if (subsystems == null)
return false;
for (int idx = 0; !any && (idx < subsystems.length); idx++)
@@ -2352,7 +2347,7 @@ public class SystemRegistry implements ISystemRegistry
return false;
}
-
+
/*
* (non-Javadoc)
* @see org.eclipse.rse.core.model.ISystemRegistry#areAllSubSystemsConnected(org.eclipse.rse.core.model.IHost)
@@ -2394,7 +2389,7 @@ public class SystemRegistry implements ISystemRegistry
public void disconnectAllSubSystems(IHost conn)
{
// get subsystems lazily, because not instantiated ones cannot be disconnected anyways.
- ISubSystem[] subsystems = getSubSystems(conn, false);
+ ISubSystem[] subsystems = getSubSystems(conn);
if (subsystems == null)
return;
diff --git a/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/subsystems/SubSystem.java b/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/subsystems/SubSystem.java
index 62c2737f584..a13424cca64 100644
--- a/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/subsystems/SubSystem.java
+++ b/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/subsystems/SubSystem.java
@@ -28,13 +28,19 @@
* David McKnight (IBM) - [186363] get rid of obsolete calls to SubSystem.connect()
* David McKnight (IBM) - [211472] [api][breaking] IRemoteObjectResolver.getObjectWithAbsoluteName() needs a progress monitor
* David McKnight (IBM) - [212403] [apidoc][breaking] Fixing docs of SubSystem#getConnectorService() and making internalConnect() private
+ * David Dykstal (IBM) - [197036] pulled up subsystem configuration switching logic from the service subsystem layer
+ * implemented IServiceSubSystem here so that subsystem configuration switching can be
+ * made common among all service subsystems.
********************************************************************************/
package org.eclipse.rse.core.subsystems;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Vector;
import org.eclipse.core.resources.IResource;
@@ -51,6 +57,7 @@ import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.rse.core.RSECorePlugin;
import org.eclipse.rse.core.RSEPreferencesManager;
+import org.eclipse.rse.core.events.ISystemModelChangeEvent;
import org.eclipse.rse.core.events.ISystemModelChangeEvents;
import org.eclipse.rse.core.events.ISystemResourceChangeEvents;
import org.eclipse.rse.core.events.SystemResourceChangeEvent;
@@ -69,6 +76,9 @@ 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.RSEModelObject;
+import org.eclipse.rse.internal.core.model.ISystemProfileOperation;
+import org.eclipse.rse.internal.core.model.SystemModelChangeEvent;
+import org.eclipse.rse.internal.core.model.SystemProfileManager;
import org.eclipse.rse.internal.ui.GenericMessages;
import org.eclipse.rse.services.clientserver.messages.SystemMessage;
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
@@ -122,7 +132,7 @@ import org.eclipse.ui.progress.WorkbenchJob;
*/
public abstract class SubSystem extends RSEModelObject
- implements IAdaptable, ISubSystem,
+ implements IAdaptable, ISubSystem, IServiceSubSystem,
ISystemFilterPoolReferenceManagerProvider
{
@@ -175,6 +185,8 @@ public abstract class SubSystem extends RSEModelObject
*/
protected ISystemFilterPoolReferenceManager filterPoolReferenceManager = null;
+ private Map poolReferencesMap = new HashMap();
+
private class NullRunnableContext implements IRunnableContext {
public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException {
IProgressMonitor monitor = new NullProgressMonitor();
@@ -2958,7 +2970,7 @@ public abstract class SubSystem extends RSEModelObject
{
ISubSystem firstSS = null;
ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry();
- ISubSystem[] sses = registry.getSubSystems(getHost(), false);
+ ISubSystem[] sses = registry.getSubSystems(getHost());
for (int i = 0; i < sses.length; i++)
{
ISubSystem ss = sses[i];
@@ -3049,4 +3061,131 @@ public abstract class SubSystem extends RSEModelObject
return result;
}
+ /* Service Subsystem support */
+
+ /**
+ * Perform the subsystem specific processing required to complete a subsystem configuration switch for a
+ * service subsystem. The subsystem will typically query this configuration for interesting properties or
+ * policies. It should also reset any state to a fresh start.
+ * This supplied implementation does nothing. Subclasses may override if they implement a service subsystem.
+ * @param newConfiguration the configuration this subsystem should use from this point.
+ */
+ protected void internalSwitchServiceSubSystemConfiguration(IServiceSubSystemConfiguration newConfiguration) {
+ }
+
+ /**
+ * Determine if a service subsystem is capable of switching to this new configuration.
+ * This is usually a test of this configuration's type against the type expected by this subsystem.
+ * This supplied implementation returns false. Subclasses should override if they implement a service subsystem.
+ * @param configuration the configuration to which this subsystem may switch
+ * @return true if this subsystem is capable of switching to this configuration, false otherwise. This implementation
+ * returns false.
+ * @see IServiceSubSystem#canSwitchTo(IServiceSubSystemConfiguration)
+ */
+ public boolean canSwitchTo(IServiceSubSystemConfiguration configuration) {
+ return false;
+ }
+
+ /**
+ * Switch to use another subsystem configuration. This default implementation will test if the subsystem is a
+ * service subsystem and if the subsystem is compatible with the suggested configuration. If it is the switch will
+ * be performed and internalSwitchSubSystemConfiguration will be called.
+ * @see IServiceSubSystem#switchServiceFactory(IServiceSubSystemConfiguration)
+ * @see #internalSwitchServiceSubSystemConfiguration(IServiceSubSystemConfiguration)
+ */
+ public void switchServiceFactory(final IServiceSubSystemConfiguration config) {
+ if (config != getSubSystemConfiguration() && canSwitchTo(config)) {
+ // define the operation to be executed
+ ISystemProfileOperation op = new ISystemProfileOperation() {
+ public IStatus run() {
+ doSwitchServiceConfiguration(config);
+ return Status.OK_STATUS;
+ }
+ };
+ // execute the operation in a commit guard
+ SystemProfileManager.run(op);
+ }
+ }
+
+ /**
+ * Return the service type for this subsystem.
+ * @return the default implementation returns null. Subclasses that implement service subsystems
+ * should return a type as specified in the interface.
+ * @see org.eclipse.rse.core.subsystems.IServiceSubSystem#getServiceType()
+ */
+ public Class getServiceType() {
+ return null;
+ }
+
+ /**
+ * Actually perform the switch inside the commit guard
+ * @param newConfig
+ */
+ private void doSwitchServiceConfiguration(IServiceSubSystemConfiguration newConfig) {
+ try {
+ disconnect();
+ } catch (Exception e) {
+ }
+ IHost host = getHost();
+ // remove the old references and store them for later use
+ ISubSystemConfiguration oldConfig = getSubSystemConfiguration();
+ if (oldConfig.supportsFilters()) {
+ ISystemFilterPoolReferenceManager fprm = getSystemFilterPoolReferenceManager();
+ List poolReferences = Arrays.asList(fprm.getSystemFilterPoolReferences());
+ poolReferencesMap.put(oldConfig, poolReferences);
+ for (Iterator z = poolReferences.iterator(); z.hasNext();) {
+ ISystemFilterPoolReference poolReference = (ISystemFilterPoolReference) z.next();
+ fprm.removeSystemFilterPoolReference(poolReference, true);
+ }
+ fprm.setSystemFilterPoolManagerProvider(null);
+ }
+ setSubSystemConfiguration(newConfig);
+ setConfigurationId(newConfig.getId());
+ setName(newConfig.getName());
+ // add the new pools to the manager
+ if (newConfig.supportsFilters()) {
+ ISystemFilterPoolReferenceManager fprm = getSystemFilterPoolReferenceManager();
+ fprm.setSystemFilterPoolManagerProvider(newConfig);
+ List poolReferences = (List) poolReferencesMap.get(newConfig);
+ if (poolReferences == null) {
+ // create default pools
+ ISystemProfile profile = host.getSystemProfile();
+ ISystemFilterPoolManager poolManager = newConfig.getFilterPoolManager(profile, true); // get and initialize the new filter pool manager
+ int eventType = ISystemModelChangeEvents.SYSTEM_RESOURCE_CHANGED;
+ int resourceType = ISystemModelChangeEvents.SYSTEM_RESOURCETYPE_CONNECTION;
+ ISystemModelChangeEvent event = new SystemModelChangeEvent(eventType, resourceType, host);
+ RSECorePlugin.getTheSystemRegistry().fireEvent(event); // signal a model change event as well
+ // create references to those pools
+ fprm.setDefaultSystemFilterPoolManager(poolManager);
+ ISystemFilterPool[] pools = poolManager.getSystemFilterPools();
+ for (int i = 0; i < pools.length; i++) {
+ ISystemFilterPool pool = pools[i];
+ fprm.addReferenceToSystemFilterPool(pool);
+ }
+ } else { // use the found pools
+ for (Iterator z = poolReferences.iterator(); z.hasNext();) {
+ ISystemFilterPoolReference poolReference = (ISystemFilterPoolReference) z.next();
+ fprm.addSystemFilterPoolReference(poolReference);
+ }
+ fprm.resolveReferencesAfterRestore();
+ }
+ filterEventFilterPoolReferencesReset(); // signal a resource change event
+ }
+
+ // switch the connector service
+ IConnectorService oldConnectorService = getConnectorService();
+ oldConnectorService.deregisterSubSystem(this);
+ IConnectorService newConnectorService = newConfig.getConnectorService(host);
+ setConnectorService(newConnectorService);
+ oldConnectorService.commit();
+ newConnectorService.commit();
+
+ // call the subsystem specfic switching support
+ internalSwitchServiceSubSystemConfiguration(newConfig);
+
+ // commit the subsystem
+ setDirty(true);
+ commit();
+ }
+
}
\ No newline at end of file
diff --git a/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/subsystems/SubSystemConfiguration.java b/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/subsystems/SubSystemConfiguration.java
index a24176c9921..de5492013bd 100644
--- a/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/subsystems/SubSystemConfiguration.java
+++ b/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/subsystems/SubSystemConfiguration.java
@@ -25,6 +25,8 @@
* Rupen Mardirossian (IBM) - [189434] Move Up/Down on Filters Error
* Kevin Doyle (IBM) - [190445] Set Position of cloned event in cloneEvent()
* Martin Oberhuber (Wind River) - [195392] Avoid setting port 0 in initializeSubSystem()
+ * David Dykstal (IBM) - [197036] rewrote getFilterPoolManager to delay the creation of default filter pools until the corresponding
+ * a subsystem configuration is actually used for a host.
********************************************************************************/
package org.eclipse.rse.core.subsystems;
@@ -67,6 +69,7 @@ import org.eclipse.rse.internal.core.filters.SystemFilterStartHere;
import org.eclipse.rse.internal.core.model.SystemProfileManager;
import org.eclipse.rse.internal.ui.SystemPropertyResources;
import org.eclipse.rse.internal.ui.SystemResources;
+import org.eclipse.rse.logging.Logger;
import org.eclipse.rse.services.clientserver.messages.SystemMessage;
import org.eclipse.rse.ui.ISystemMessages;
import org.eclipse.rse.ui.RSEUIPlugin;
@@ -632,31 +635,20 @@ public abstract class SubSystemConfiguration implements ISubSystemConfiguration
// SUBSYSTEM METHODS...
// ---------------------------------
- /**
- * Called by SystemRegistry's renameSystemProfile method to ensure we update our
- * subsystem names within each subsystem.
- *
- * This is called AFTER changing the profile's name!! + /* (non-Javadoc) + * @see org.eclipse.rse.core.subsystems.ISubSystemConfiguration#renameSubSystemProfile(org.eclipse.rse.core.subsystems.ISubSystem, java.lang.String, java.lang.String) */ - public void renameSubSystemProfile(ISubSystem ss, String oldProfileName, String newProfileName) - { - //RSEUIPlugin.logDebugMessage(this.getClass().getName(), "Inside renameSubSystemProfile. newProfileName = "+newProfileName+", old ssName = "+ss.getName()); - //renameFilterPoolManager(getSystemProfile(newProfileName)); // update filter pool manager name - ss.renamingProfile(oldProfileName, newProfileName); - ISystemFilterPoolReferenceManager sfprm = ss.getSystemFilterPoolReferenceManager(); - if (sfprm != null) - { - sfprm.regenerateReferencedSystemFilterPoolNames(); // ask it to re-ask each pool for its reference name + public void renameSubSystemProfile(ISubSystem subsystem, String oldProfileName, String newProfileName) { + subsystem.renamingProfile(oldProfileName, newProfileName); + ISystemFilterPoolReferenceManager sfprm = subsystem.getSystemFilterPoolReferenceManager(); + if (sfprm != null) { + sfprm.regenerateReferencedSystemFilterPoolNames(); // ask it to re-ask each pool for its reference name } - try - { - saveSubSystem(ss); + try { + saveSubSystem(subsystem); + } catch (Exception exc) { + RSECorePlugin.getDefault().getLogger().logError("Unexpected error saving subsystem.", exc); //$NON-NLS-1$ } - catch (Exception exc) - { - // already dealt with in save? - } - } /** @@ -1015,9 +1007,7 @@ public abstract class SubSystemConfiguration implements ISubSystemConfiguration try { saveSubSystem(subsys); - //DKM - save this event til all the processing is done! - // fire model change event in case any BP code is listening... - //RSECorePlugin.getTheSystemRegistry().fireModelChangeEvent(ISystemModelChangeEvents.SYSTEM_RESOURCE_ADDED, ISystemModelChangeEvents.SYSTEM_RESOURCETYPE_SUBSYSTEM, subsys, null); + RSECorePlugin.getTheSystemRegistry().fireModelChangeEvent(ISystemModelChangeEvents.SYSTEM_RESOURCE_ADDED, ISystemModelChangeEvents.SYSTEM_RESOURCETYPE_SUBSYSTEM, subsys, null); } catch (Exception exc) { @@ -1597,79 +1587,55 @@ public abstract class SubSystemConfiguration implements ISubSystemConfiguration } return activeManagers; } - - /** - * Get the filter pool manager for the given profile + + /* (non-Javadoc) + * @see org.eclipse.rse.core.subsystems.ISubSystemConfiguration#getFilterPoolManager(org.eclipse.rse.core.model.ISystemProfile) */ - public ISystemFilterPoolManager getFilterPoolManager(ISystemProfile profile) - { - // it is important to key by profile object not profile name, since that - // name can change but the object never should for any one session. + public ISystemFilterPoolManager getFilterPoolManager(ISystemProfile profile) { + return getFilterPoolManager(profile, false); + } + + /* (non-Javadoc) + * @see org.eclipse.rse.core.subsystems.ISubSystemConfiguration#getFilterPoolManager(org.eclipse.rse.core.model.ISystemProfile, boolean) + */ + public ISystemFilterPoolManager getFilterPoolManager(ISystemProfile profile, boolean force) { + // it is important to key by profile object not profile name, since that name can change but the object never should for any one session. ISystemFilterPoolManager mgr = (ISystemFilterPoolManager) filterPoolManagersPerProfile.get(profile); - //System.out.println("in getFilterPoolManager for ssfactory "+getId()+" for profile " + profile.getName() + ", mgr found? " + (mgr!=null)); - if (mgr == null) - { - try - { - mgr = SystemFilterPoolManager.createSystemFilterPoolManager(profile, RSECorePlugin.getDefault().getLogger(), this, // the caller - getFilterPoolManagerName(profile), // the filter pool manager name - supportsNestedFilters(), // whether or not nested filters are allowed - ISystemFilterSavePolicies.SAVE_POLICY_ONE_FILE_PER_FILTER, filterNamingPolicy); - mgr.setSingleFilterStringOnly(!supportsMultipleFilterStrings()); // DWD was restored flag? - } - catch (Exception exc) - { + if (mgr == null) { + try { + Logger logger = RSECorePlugin.getDefault().getLogger(); + String managerName = getFilterPoolManagerName(profile); + boolean supportsNested = supportsNestedFilters(); + int savePolicy = ISystemFilterSavePolicies.SAVE_POLICY_ONE_FILE_PER_FILTER; + mgr = SystemFilterPoolManager.createSystemFilterPoolManager(profile, logger, this, managerName, supportsNested, savePolicy, filterNamingPolicy);// the filter pool manager name + mgr.setSingleFilterStringOnly(!supportsMultipleFilterStrings()); + mgr.setWasRestored(false); // not yet initialized + } catch (Exception exc) { SystemBasePlugin.logError("Restore/Creation of SystemFilterPoolManager " + getFilterPoolManagerName(profile) + " failed!", exc); //$NON-NLS-1$ //$NON-NLS-2$ SystemMessageDialog.displayExceptionMessage(null, exc); - return null; // something very bad happend! + return null; // something very bad happened! } - addFilterPoolManager(profile, mgr); - - boolean restored = mgr.wasRestored(); - //System.out.println("...after createSystemFilterPoolManager for " + mgr.getName() + ", restored = " + restored); - - // allow subclasses to create default filter pool... - if (!restored) - { - ISystemFilterPool defaultPool = createDefaultFilterPool(mgr); - if (defaultPool != null) - { - defaultPool.setDefault(true); - try - { - defaultPool.commit(); - } - catch (Exception exc) - { - } - } + } + boolean initialized = mgr.wasRestored(); + if (force && !initialized) { + String defaultPoolName = getDefaultFilterPoolName(profile.getName(), getId()); + ISystemFilterPool defaultPool = mgr.getSystemFilterPool(defaultPoolName); + if (defaultPool == null) { + // allow subclasses to create default filter pool... + defaultPool = createDefaultFilterPool(mgr); // createDefaultFilterPool(mgr) is typically overridden by subclasses } - // else filter pools restored for this profile. Allow subclasses chance to do post-processing, - // such as any migration needed - else - { - if (doPostRestoreProcessing(mgr)) - { - try - { - mgr.commit(); - } - catch (Exception exc) - { - } - } + if (defaultPool != null) { + defaultPool.setDefault(true); + defaultPool.commit(); } - // these should be inside the above logic but we need them outside for now because they were - // added late and there are existing filter pool managers that need this to be set for. - // In a future release we should move them inside the if (!restored) logic. Phil. - if (supportsDuplicateFilterStrings()) - mgr.setSupportsDuplicateFilterStrings(true); - if (isCaseSensitive()) - mgr.setStringsCaseSensitive(isCaseSensitive()); + if (supportsDuplicateFilterStrings()) mgr.setSupportsDuplicateFilterStrings(true); + if (isCaseSensitive()) mgr.setStringsCaseSensitive(true); + mgr.setWasRestored(true); } return mgr; } + /** * Do post-restore-processing of an existing filter pool manager. * This is where child classes do any required migration work. By default, we do nothing.