1 11 package org.eclipse.ui.internal.components.registry; 12 13 import java.util.HashMap ; 14 import java.util.Map ; 15 16 import org.eclipse.core.runtime.IConfigurationElement; 17 import org.eclipse.core.runtime.IExtension; 18 import org.eclipse.core.runtime.IPath; 19 import org.eclipse.core.runtime.Path; 20 import org.eclipse.ui.internal.components.ExecutableExtensionFactory; 21 import org.eclipse.ui.internal.components.framework.ClassIdentifier; 22 import org.eclipse.ui.internal.components.framework.ComponentFactory; 23 24 27 public class ServiceExtensionPoint { 28 29 private static final String ATT_IMPLEMENTATION = "class"; private static final String ATT_COMPONENT = "component"; private static final String ATT_INTERFACE = "interface"; private static final String ATT_INTERFACES = "services"; 34 private IExtensionPointMonitor extensionPointMonitor = new IExtensionPointMonitor() { 35 38 public void added(IExtension newExtension) { 39 processExtension(newExtension, true); 40 } 41 44 public void removed(IExtension oldExtension) { 45 processExtension(oldExtension, false); 46 } 47 }; 48 49 private Map services = new HashMap (); 50 private ComponentRegistry registry; 51 private ExtensionPointManager manager; 52 53 54 public ServiceExtensionPoint(ExtensionPointManager manager, ComponentRegistry scope) { 55 this.manager = manager; 56 registry = scope; 57 manager.addMonitor(ATT_INTERFACES, extensionPointMonitor); 58 } 59 60 public void dispose() { 61 manager.removeMonitor(ATT_INTERFACES, extensionPointMonitor); 62 } 63 64 private ClassIdentifier getType(IConfigurationElement element, String attributeName) { 65 return new ClassIdentifier(element.getNamespace(), element.getAttribute(attributeName)); 66 } 67 68 private void processExtension(IExtension extension, boolean added) { 69 IConfigurationElement[] elements = extension.getConfigurationElements(); 70 71 for (int i = 0; i < elements.length; i++) { 72 IConfigurationElement element = elements[i]; 73 74 if (element.getName().equals(ATT_COMPONENT)) { 75 ClassIdentifier className = getType(element, ATT_IMPLEMENTATION); ClassIdentifier interfaceName = getType(element, ATT_INTERFACE); 77 String scopeId = element.getAttribute("scope"); ComponentFactory serviceFactory = null; 79 IPath scopePath = new Path(scopeId); 80 81 if (added) { 82 ExecutableExtensionFactory factory = new ExecutableExtensionFactory(element, ATT_IMPLEMENTATION); registry.addType(scopeId, interfaceName, factory); 84 } else { 85 registry.removeType(scopeId, interfaceName); 86 } 87 } else if (element.getName().equals("scope")) { String id = element.getAttribute("id"); 90 if (added) { 91 92 ScopeDefinition def = new ScopeDefinition(); 93 94 IConfigurationElement[] children = element.getChildren(); 96 97 for (int j = 0; j < children.length; j++) { 98 IConfigurationElement child = children[j]; 99 100 String name = child.getName(); 101 102 if (name.equals("requiresScope")) { String scopeName = child.getAttribute("id"); def.addExtends(new SymbolicScopeReference(scopeName, IScopeReference.REL_REQUIRES)); 105 } else if (name.equals("extendsScope")) { String scopeName = child.getAttribute("id"); def.addExtends(new SymbolicScopeReference(scopeName, IScopeReference.REL_EXTENDS)); 108 } else if (name.equals("requiresInterface")) { String typeName = child.getAttribute("id"); def.addDependency(new ClassIdentifier(extension.getNamespace(), typeName)); 111 } 112 } 113 114 registry.loadScope(id, def); 115 } else { 116 registry.unloadScope(id); 117 } 118 } 119 120 } 133 } 134 } 135 | Popular Tags |