KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > components > registry > ServiceExtensionPoint


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.components.registry;
12
13 import java.util.HashMap JavaDoc;
14 import java.util.Map JavaDoc;
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 /**
25  * @since 3.1
26  */

27 public class ServiceExtensionPoint {
28     
29     private static final String JavaDoc ATT_IMPLEMENTATION = "class"; //$NON-NLS-1$
30
private static final String JavaDoc ATT_COMPONENT = "component"; //$NON-NLS-1$
31
private static final String JavaDoc ATT_INTERFACE = "interface"; //$NON-NLS-1$
32
private static final String JavaDoc ATT_INTERFACES = "services"; //$NON-NLS-1$
33

34     private IExtensionPointMonitor extensionPointMonitor = new IExtensionPointMonitor() {
35         /* (non-Javadoc)
36          * @see org.eclipse.ui.internal.component.IExtensionPointMonitor#added(org.eclipse.core.runtime.IExtension)
37          */

38         public void added(IExtension newExtension) {
39             processExtension(newExtension, true);
40         }
41         /* (non-Javadoc)
42          * @see org.eclipse.ui.internal.component.IExtensionPointMonitor#removed(org.eclipse.core.runtime.IExtension)
43          */

44         public void removed(IExtension oldExtension) {
45             processExtension(oldExtension, false);
46         }
47     };
48     
49     private Map JavaDoc services = new HashMap JavaDoc();
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 JavaDoc 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); //$NON-NLS-1$
76
ClassIdentifier interfaceName = getType(element, ATT_INTERFACE);
77                 String JavaDoc scopeId = element.getAttribute("scope"); //$NON-NLS-1$
78
ComponentFactory serviceFactory = null;
79                 IPath scopePath = new Path(scopeId);
80                                 
81                 if (added) {
82                     ExecutableExtensionFactory factory = new ExecutableExtensionFactory(element, ATT_IMPLEMENTATION); //$NON-NLS-1$
83
registry.addType(scopeId, interfaceName, factory);
84                 } else {
85                     registry.removeType(scopeId, interfaceName);
86                 }
87             } else if (element.getName().equals("scope")) { //$NON-NLS-1$
88
String JavaDoc id = element.getAttribute("id"); //$NON-NLS-1$
89

90                 if (added) {
91                     
92                     ScopeDefinition def = new ScopeDefinition();
93                     
94                     // Get extended scopes
95
IConfigurationElement[] children = element.getChildren();
96                     
97                     for (int j = 0; j < children.length; j++) {
98                         IConfigurationElement child = children[j];
99                         
100                         String JavaDoc name = child.getName();
101                         
102                         if (name.equals("requiresScope")) { //$NON-NLS-1$
103
String JavaDoc scopeName = child.getAttribute("id"); //$NON-NLS-1$
104
def.addExtends(new SymbolicScopeReference(scopeName, IScopeReference.REL_REQUIRES));
105                         } else if (name.equals("extendsScope")) { //$NON-NLS-1$
106
String JavaDoc scopeName = child.getAttribute("id"); //$NON-NLS-1$
107
def.addExtends(new SymbolicScopeReference(scopeName, IScopeReference.REL_EXTENDS));
108                         } else if (name.equals("requiresInterface")) { //$NON-NLS-1$
109
String JavaDoc typeName = child.getAttribute("id"); //$NON-NLS-1$
110
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 // else if (element.getName().equals("modifier")) {
121
// IComponentType className = getType(element, "implementation");
122
// IComponentType interfaceName = getType(element, ATT_INTERFACE);
123
// IComponentType protocolName = getType(element, "protocol");
124
// String scopeId = element.getAttribute("scope");
125
//
126
// if (added) {
127
// registry.addModifier(scopeId, className, protocolName, new ComponentTypeFactory(interfaceName));
128
// } else {
129
// registry.removeModifier(scopeId, className, protocolName);
130
// }
131
// }
132
}
133     }
134 }
135
Popular Tags