1 11 package org.eclipse.ltk.internal.ui.refactoring; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.core.runtime.Assert; 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IConfigurationElement; 19 import org.eclipse.core.runtime.IExtensionRegistry; 20 import org.eclipse.core.runtime.Platform; 21 22 23 public abstract class DescriptorManager { 24 25 private String fExtensionPoint; 26 private String fVariableName; 27 private AbstractDescriptor[] fExtensions; 28 29 public DescriptorManager(String extensionPoint, String variableName) { 30 Assert.isNotNull(extensionPoint); 31 Assert.isNotNull(variableName); 32 fExtensionPoint= extensionPoint; 33 fVariableName= variableName; 34 } 35 36 public AbstractDescriptor getDescriptor(Object element) throws CoreException { 37 if (fExtensions == null) 38 init(); 39 40 List candidates= new ArrayList (1); 41 for (int i= 0; i < fExtensions.length; i++) { 42 AbstractDescriptor descriptor= fExtensions[i]; 43 if (descriptor.matches(element, fVariableName)) { 44 candidates.add(descriptor); 45 } 46 descriptor.clear(); 47 } 48 if (candidates.size() == 0) 49 return null; 50 return (AbstractDescriptor)candidates.get(0); 52 } 53 54 protected abstract AbstractDescriptor createDescriptor(IConfigurationElement element); 55 56 58 private void init() { 59 IExtensionRegistry registry= Platform.getExtensionRegistry(); 60 IConfigurationElement[] ces= registry.getConfigurationElementsFor( 61 RefactoringUIPlugin.getPluginId(), 62 fExtensionPoint); 63 fExtensions= new AbstractDescriptor[ces.length]; 64 for (int i= 0; i < ces.length; i++) { 65 fExtensions[i]= createDescriptor(ces[i]); 66 } 67 } 68 } 69 | Popular Tags |