1 11 package org.eclipse.ui.internal.components; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.core.runtime.IConfigurationElement; 15 import org.eclipse.ui.internal.components.framework.ComponentException; 16 import org.eclipse.ui.internal.components.framework.ComponentFactory; 17 import org.eclipse.ui.internal.components.framework.ComponentHandle; 18 import org.eclipse.ui.internal.components.framework.IServiceProvider; 19 import org.eclipse.ui.internal.components.framework.ReflectionFactory; 20 import org.eclipse.ui.internal.components.framework.SingletonFactory; 21 22 27 public class ExecutableExtensionFactory extends ComponentFactory { 28 29 private String attributeId; 30 private IConfigurationElement configElement; 31 32 private ComponentFactory cachedAdapter = null; 33 34 44 public ExecutableExtensionFactory(IConfigurationElement configElement, String attributeId) { 45 this.configElement = configElement; 46 this.attributeId = attributeId; 47 } 48 49 52 public ComponentHandle createHandle(IServiceProvider availableServices) throws ComponentException { 53 if (cachedAdapter != null) { 56 try { 57 ComponentHandle result = cachedAdapter.createHandle(availableServices); 58 return result; 59 } catch (ComponentException e) { 60 if (cachedAdapter instanceof ReflectionFactory || cachedAdapter instanceof SingletonFactory) { 65 throw e; 66 } 67 68 throw new ComponentException(cachedAdapter.getClass(), e); 69 } 70 } 71 72 IServiceProvider actualContainer = availableServices; 76 77 try { 78 cachedAdapter = (ComponentFactory)configElement.createExecutableExtension("class"); } catch (CoreException e) { 80 throw new ComponentException(configElement, e); 81 } 82 83 return cachedAdapter.createHandle(actualContainer); 84 } 85 86 89 public int hashCode() { 90 return configElement.hashCode() + attributeId.hashCode(); 91 } 92 93 96 public boolean equals(Object obj) { 97 if (!(obj instanceof ExecutableExtensionFactory)) { 98 return false; 99 } 100 ExecutableExtensionFactory t = (ExecutableExtensionFactory)obj; 101 102 return configElement == t.configElement 103 && attributeId.equals(t.attributeId); 104 } 105 106 public void dispose() { 107 cachedAdapter = null; 108 } 109 110 } 111 112 | Popular Tags |