1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-10 01:35:39 +02:00

[235148] get rid of dead code for caching

This commit is contained in:
Martin Oberhuber 2008-06-03 08:51:37 +00:00
parent 359627faa0
commit 9e2fc1d12d

View file

@ -1,20 +1,19 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2007, 2008 Wind River Systems, Inc. and others. * Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Uwe Stieber (Wind River) - initial API and implementation. * Uwe Stieber (Wind River) - initial API and implementation.
* Javier Montalvo Orus (Symbian) - [174992] default wizard hides special ones * Javier Montalvo Orus (Symbian) - [174992] default wizard hides special ones
* David McKnight (IBM) - [216252] MessageFormat.format -> NLS.bind * David McKnight (IBM) - [216252] MessageFormat.format -> NLS.bind
* Martin Oberhuber (Wind River) - [235148] get rid of dead code for caching
*******************************************************************************/ *******************************************************************************/
package org.eclipse.rse.ui.wizards.newconnection; package org.eclipse.rse.ui.wizards.newconnection;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.IStructuredSelection;
@ -27,12 +26,11 @@ import org.eclipse.rse.ui.wizards.registries.RSEAbstractWizardRegistry;
/** /**
* RSE New connection wizard registry implementation. * RSE New connection wizard registry implementation.
* *
* @noextend This class is not intended to be subclassed by clients. * @noextend This class is not intended to be subclassed by clients.
* @noinstantiate This class is not intended to be instantiated by clients. * @noinstantiate This class is not intended to be instantiated by clients.
*/ */
public class RSENewConnectionWizardRegistry extends RSEAbstractWizardRegistry { public class RSENewConnectionWizardRegistry extends RSEAbstractWizardRegistry {
private final Map cache = new HashMap();
// Initialize-On-Demand Holder Class idiom: // Initialize-On-Demand Holder Class idiom:
// Lazy initialization and thread-safe single instance. // Lazy initialization and thread-safe single instance.
@ -53,14 +51,13 @@ public class RSENewConnectionWizardRegistry extends RSEAbstractWizardRegistry {
*/ */
protected RSENewConnectionWizardRegistry() { protected RSENewConnectionWizardRegistry() {
super(); super();
cache.clear();
} }
protected IRSEWizardRegistryElement createWizardRegistryElementFor(IConfigurationElement element) { protected IRSEWizardRegistryElement createWizardRegistryElementFor(IConfigurationElement element) {
IRSEWizardRegistryElement wizardElement = null; IRSEWizardRegistryElement wizardElement = null;
if ("newConnectionWizard".equals(element.getName())) wizardElement = new RSENewConnectionWizardDescriptor(this, element); //$NON-NLS-1$ if ("newConnectionWizard".equals(element.getName())) wizardElement = new RSENewConnectionWizardDescriptor(this, element); //$NON-NLS-1$
return wizardElement != null ? wizardElement : super.createWizardRegistryElementFor(element); return wizardElement != null ? wizardElement : super.createWizardRegistryElementFor(element);
} }
@ -70,13 +67,13 @@ public class RSENewConnectionWizardRegistry extends RSEAbstractWizardRegistry {
protected String getExtensionPointId() { protected String getExtensionPointId() {
return RSEUIPlugin.getDefault().getBundle().getSymbolicName() + ".newConnectionWizards"; //$NON-NLS-1$ return RSEUIPlugin.getDefault().getBundle().getSymbolicName() + ".newConnectionWizards"; //$NON-NLS-1$
} }
/** /**
* Returns the new connection wizard descriptor to use for the specified selection. * Returns the new connection wizard descriptor to use for the specified selection.
* The selection is expected to contain the selected system type as first element. * The selection is expected to contain the selected system type as first element.
* *
* @see #getWizardForSystemType(IRSESystemType) for more information. * @see #getWizardForSystemType(IRSESystemType) for more information.
* *
* @param selection A structure selection containing the selected system type as first element. Must be not <code>null</code>. * @param selection A structure selection containing the selected system type as first element. Must be not <code>null</code>.
* @return A registered new connection wizard descriptor or <code>null</code>. * @return A registered new connection wizard descriptor or <code>null</code>.
*/ */
@ -86,12 +83,12 @@ public class RSENewConnectionWizardRegistry extends RSEAbstractWizardRegistry {
} }
/** /**
* Returns the new connection wizard to use for the specified system type. * Returns the new connection wizard to use for the specified system type.
* Once queried for a specific system type, the method returns always the same wizard * Once queried for a specific system type, the method returns always the same wizard
* instance. If there are multiple wizards registered for a specific system type, * instance. If there are multiple wizards registered for a specific system type,
* the first wizard found will be taken and the other wizards will be dropped. If * the first wizard found will be taken and the other wizards will be dropped. If
* this case is happening, a corresponding warning message is send to the error log. * this case is happening, a corresponding warning message is send to the error log.
* *
* @param systemType The selected system type to query the wizard for. Must be not <code>null</code>. * @param systemType The selected system type to query the wizard for. Must be not <code>null</code>.
* @return A registered new connection wizard or the default RSE new connection wizard. Can be only <code>null</code> * @return A registered new connection wizard or the default RSE new connection wizard. Can be only <code>null</code>
* if the default RSE new connection wizard contribution has been removed from plugin.xml! * if the default RSE new connection wizard contribution has been removed from plugin.xml!
@ -99,52 +96,40 @@ public class RSENewConnectionWizardRegistry extends RSEAbstractWizardRegistry {
public IRSENewConnectionWizardDescriptor getWizardForSystemType(IRSESystemType systemType) { public IRSENewConnectionWizardDescriptor getWizardForSystemType(IRSESystemType systemType) {
assert systemType != null; assert systemType != null;
IRSENewConnectionWizardDescriptor defaultDescriptor = (IRSENewConnectionWizardDescriptor)findElementById("org.eclipse.rse.ui.wizards.newconnection.RSEDefaultNewConnectionWizard"); //$NON-NLS-1$ IRSENewConnectionWizardDescriptor defaultDescriptor = (IRSENewConnectionWizardDescriptor)findElementById("org.eclipse.rse.ui.wizards.newconnection.RSEDefaultNewConnectionWizard"); //$NON-NLS-1$
IRSENewConnectionWizardDescriptor descriptor = null; IRSENewConnectionWizardDescriptor descriptor = null;
String id = systemType.getId(); String id = systemType.getId();
if (cache.containsKey(id)) {
Object candidate = cache.get(id);
if (candidate instanceof IRSENewConnectionWizardDescriptor) {
descriptor = (IRSENewConnectionWizardDescriptor)candidate;
} else {
cache.remove(id);
}
}
// check if there is any wizard explicitly registered for the given system type // check if there is any wizard explicitly registered for the given system type
if (descriptor == null) { // Get the list of all wizards and always walk through _all_ of them
// Get the list of all wizards and always walk through _all_ of them // to find possible duplicates (which will be notified as warnings to
// to find possible duplicates (which will be notified as warnings to // the user)
// the user) IRSEWizardRegistryElement[] elements = getElements();
IRSEWizardRegistryElement[] elements = getElements(); for (int i = 0; i < elements.length; i++) {
for (int i = 0; i < elements.length; i++) { IRSEWizardRegistryElement element = elements[i];
IRSEWizardRegistryElement element = elements[i]; if (element instanceof IRSENewConnectionWizardDescriptor) {
if (element instanceof IRSENewConnectionWizardDescriptor) { IRSENewConnectionWizardDescriptor candidate = (IRSENewConnectionWizardDescriptor) element;
IRSENewConnectionWizardDescriptor candidate = (IRSENewConnectionWizardDescriptor)element; if (candidate != defaultDescriptor) {
if(candidate != defaultDescriptor) String[] systemTypeIds = candidate.getSystemTypeIds();
{ if (Arrays.asList(systemTypeIds).contains(id)) {
String[] systemTypeIds = candidate.getSystemTypeIds(); if (descriptor == null) {
if (Arrays.asList(systemTypeIds).contains(id)) { descriptor = candidate;
if (descriptor == null) { } else {
descriptor = candidate; String message = "Duplicated new connection wizard registration for system type ''{0}'' (wizard id = {1})."; //$NON-NLS-1$
} else { message = NLS.bind(message, id, candidate.getId());
String message = "Duplicated new connection wizard registration for system type ''{0}'' (wizard id = {1})."; //$NON-NLS-1$ RSECorePlugin.getDefault().getLogger().logWarning(message);
message = NLS.bind(message, id, candidate.getId());
RSECorePlugin.getDefault().getLogger().logWarning(message);
}
} }
} }
} }
} }
// if the descriptor here is still null, always return the default RSE
// new connection wizard descriptor
if (descriptor == null) {
descriptor = defaultDescriptor;
}
} }
// if the descriptor here is still null, always return the default RSE
// new connection wizard descriptor
if (descriptor == null) {
descriptor = defaultDescriptor;
}
return descriptor; return descriptor;
} }
} }