From 7e0a48a36eb0b52b3446903ae8a555cd8f331d25 Mon Sep 17 00:00:00 2001 From: David Dykstal Date: Thu, 21 Sep 2006 17:26:40 +0000 Subject: [PATCH] Bug 158180 - Forward reference logic fixed in SystemFilterPoolReference. Since there may actually be valid broken references cases were added to handle those as well. --- .../persistence/dom/RSEDOMImporter.java | 11 +---- .../SystemViewFilterPoolReferenceAdapter.java | 23 ++++++--- .../SystemFilterPoolReferenceManager.java | 3 +- .../filters/SystemFilterPoolReference.java | 23 ++++++++- .../rse/core/subsystems/SubSystem.java | 49 +++++++++---------- 5 files changed, 61 insertions(+), 48 deletions(-) diff --git a/rse/plugins/org.eclipse.rse.core/persistence/org/eclipse/rse/internal/persistence/dom/RSEDOMImporter.java b/rse/plugins/org.eclipse.rse.core/persistence/org/eclipse/rse/internal/persistence/dom/RSEDOMImporter.java index c5853fedec3..d98e0d79258 100644 --- a/rse/plugins/org.eclipse.rse.core/persistence/org/eclipse/rse/internal/persistence/dom/RSEDOMImporter.java +++ b/rse/plugins/org.eclipse.rse.core/persistence/org/eclipse/rse/internal/persistence/dom/RSEDOMImporter.java @@ -481,20 +481,13 @@ public class RSEDOMImporter implements IRSEDOMImporter /* * DWD filterpool can be null when restoring since there can be forward references. * A profile may be being restored that has references to a filter pool in a profile that doesn't yet exist. - * Need to create an "unresolved" reference instead of a null object and then patch them up - * at the end. + * Need to create an "unresolved" reference instead of a null object and then patch them up on first access. */ // create reference to the filterpool if (filterPool != null) { filterPoolReference = referenceManager.addReferenceToSystemFilterPool(filterPool); } else { - try { - filterPoolReference = referenceManager.addReferenceToSystemFilterPool(filterPoolManager, filterPoolName); - } catch(NullPointerException e) { - //TODO Workaround for bug 153253 -- should be fixed properly - System.err.println("TODO: Fix bug 153253 - NPE reading connection-private filter pools"); - e.printStackTrace(); - } + filterPoolReference = referenceManager.addReferenceToSystemFilterPool(filterPoolManager, filterPoolName); } } return filterPoolReference; diff --git a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/view/SystemViewFilterPoolReferenceAdapter.java b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/view/SystemViewFilterPoolReferenceAdapter.java index d3009ed51d9..c6e3f16d87b 100644 --- a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/view/SystemViewFilterPoolReferenceAdapter.java +++ b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/view/SystemViewFilterPoolReferenceAdapter.java @@ -140,15 +140,22 @@ public class SystemViewFilterPoolReferenceAdapter /** - * Return the label for this object. Uses getName() on the filter pool object. + * @param element the filter pool reference masquerading as an object + * @return the label for this filter pool reference. */ - public String getText(Object element) - { - boolean qualifyNames = RSEUIPlugin.getTheSystemRegistry().getQualifiedHostNames(); - if (!qualifyNames) - return getFilterPool(element).getName(); - else - return SubSystemHelpers.getParentSystemProfile(getFilterPool(element))+"." + getFilterPool(element).getName(); + public String getText(Object element) { + String result = "unknown"; // $NON-NLS-1$ + ISystemFilterPool pool = getFilterPool(element); + if (pool != null) { + result = pool.getName(); +// the following looks like it was copied from the host adapter and not really needed here. +// boolean qualifyNames = RSEUIPlugin.getTheSystemRegistry().getQualifiedHostNames(); +// if (qualifyNames) { +// String prefix = SubSystemHelpers.getParentSystemProfile(pool).getName(); +// result = prefix + "." + result; +// } + } + return result; } /** * Return the name of this object, which may be different than the display text ({#link #getText(Object)}. diff --git a/rse/plugins/org.eclipse.rse.ui/filters/org/eclipse/rse/filters/SystemFilterPoolReferenceManager.java b/rse/plugins/org.eclipse.rse.ui/filters/org/eclipse/rse/filters/SystemFilterPoolReferenceManager.java index 7a74a720489..52c14c9a6da 100644 --- a/rse/plugins/org.eclipse.rse.ui/filters/org/eclipse/rse/filters/SystemFilterPoolReferenceManager.java +++ b/rse/plugins/org.eclipse.rse.ui/filters/org/eclipse/rse/filters/SystemFilterPoolReferenceManager.java @@ -542,13 +542,12 @@ public class SystemFilterPoolReferenceManager extends SystemPersistableReference return filterPoolReference; } - // DWD Working - the method above and this one can be combined? /* (non-Javadoc) * @see org.eclipse.rse.filters.ISystemFilterPoolReferenceManager#addReferenceToSystemFilterPool(org.eclipse.rse.filters.ISystemFilterPoolManager, java.lang.String) */ public ISystemFilterPoolReference addReferenceToSystemFilterPool(ISystemFilterPoolManager filterPoolManager, String filterPoolName) { ISystemFilterPoolReference filterPoolReference = createSystemFilterPoolReference(filterPoolManager, filterPoolName); - addReferencingObject(filterPoolReference); // DWD - should be done in addReferencingObject? + addReferencingObject(filterPoolReference); filterPoolReference.setParentReferenceManager(this); invalidateFilterPoolReferencesCache(); quietSave(); diff --git a/rse/plugins/org.eclipse.rse.ui/filters/org/eclipse/rse/internal/filters/SystemFilterPoolReference.java b/rse/plugins/org.eclipse.rse.ui/filters/org/eclipse/rse/internal/filters/SystemFilterPoolReference.java index 6b8d3fa7661..e1a8d65e89b 100644 --- a/rse/plugins/org.eclipse.rse.ui/filters/org/eclipse/rse/internal/filters/SystemFilterPoolReference.java +++ b/rse/plugins/org.eclipse.rse.ui/filters/org/eclipse/rse/internal/filters/SystemFilterPoolReference.java @@ -16,6 +16,9 @@ package org.eclipse.rse.internal.filters; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.Platform; import org.eclipse.rse.core.filters.ISystemFilter; @@ -27,8 +30,10 @@ 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.ISystemProfile; import org.eclipse.rse.core.subsystems.ISubSystem; import org.eclipse.rse.internal.references.SystemPersistableReferencingObject; +import org.eclipse.rse.model.SystemRegistry; /** * A reference to a filter pool. A reference may be "resolved" or "unresolved". @@ -144,12 +149,26 @@ public class SystemFilterPoolReference extends SystemPersistableReferencingObjec if (filterPool == null) { String filterPoolName = getReferencedFilterPoolName(); filterPool = filterPoolManager.getSystemFilterPool(filterPoolName); + if (filterPool == null) { + Pattern p = Pattern.compile("(^.*):"); + Matcher m = p.matcher(filterPoolName); + if (m.find()) { + String profileName = m.group(1); + ISystemProfile profile = SystemRegistry.getSystemRegistry().getSystemProfile(profileName); + if (profile != null) { + ISystemFilterPool[] pools = profile.getFilterPools(); + for (int i = 0; i < pools.length && filterPool == null; i++) { + ISystemFilterPool pool = pools[i]; + if (filterPoolName.equals(pool.getName())) filterPool = pool; + } + } + } + } if (filterPool != null) { setReferenceToFilterPool(filterPool); - } else { - this.setReferenceBroken(true); } } + setReferenceBroken(filterPool == null); return filterPool; } 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 221349da208..4836811d8e6 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 @@ -1072,35 +1072,30 @@ public abstract class SubSystem extends RSEModelObject implements IAdaptable, IS // ------------------------------- // FILTER POOL REFERENCE EVENTS... // ------------------------------- - /** - * A new filter pool reference has been created - */ - public void filterEventFilterPoolReferenceCreated(ISystemFilterPoolReference newPoolRef) - { - if (getSubSystemConfiguration().showFilterPools()) - { - fireEvent(newPoolRef, EVENT_ADD, this); - fireEvent(newPoolRef, EVENT_REVEAL_AND_SELECT, this); - } - else if (newPoolRef.getReferencedFilterPool().getSystemFilterCount()>0) - { - ISystemFilterReference[] filterRefs = newPoolRef.getSystemFilterReferences(this); - fireEvent(filterRefs, EVENT_ADD_MANY, this, -1); // -1 means append to end - } - try { - //System.out.println(" calling saveSubSystem(this)..."); - getSubSystemConfiguration().saveSubSystem(this); - //System.out.println(" Back and done!"); - // fire model change event in case any BP code is listening... - RSEUIPlugin.getTheSystemRegistry().fireModelChangeEvent(ISystemModelChangeEvents.SYSTEM_RESOURCE_ADDED, ISystemModelChangeEvents.SYSTEM_RESOURCETYPE_FILTERPOOLREF, newPoolRef, null); - } - catch (Exception exc) - { - SystemBasePlugin.logError("Error saving subsystem "+getName(),exc); - } - } /** + * A new filter pool reference has been created. Fire the appropriate events for this. + */ + public void filterEventFilterPoolReferenceCreated(ISystemFilterPoolReference newPoolRef) { + if (getSubSystemConfiguration().showFilterPools()) { + fireEvent(newPoolRef, EVENT_ADD, this); + fireEvent(newPoolRef, EVENT_REVEAL_AND_SELECT, this); + } else { + ISystemFilterPool pool = newPoolRef.getReferencedFilterPool(); + if (pool != null && pool.getSystemFilterCount() > 0) { + ISystemFilterReference[] filterRefs = newPoolRef.getSystemFilterReferences(this); + fireEvent(filterRefs, EVENT_ADD_MANY, this, -1); // -1 means append to end + } + } + try { + getSubSystemConfiguration().saveSubSystem(this); + RSEUIPlugin.getTheSystemRegistry().fireModelChangeEvent(ISystemModelChangeEvents.SYSTEM_RESOURCE_ADDED, ISystemModelChangeEvents.SYSTEM_RESOURCETYPE_FILTERPOOLREF, newPoolRef, null); + } catch (Exception exc) { + SystemBasePlugin.logError("Error saving subsystem " + getName(), exc); + } + } + + /** * A filter pool reference has been deleted */ public void filterEventFilterPoolReferenceDeleted(ISystemFilterPoolReference filterPoolRef)