KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ltk > internal > ui > refactoring > DescriptorManager


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.ltk.internal.ui.refactoring;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
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 JavaDoc fExtensionPoint;
26     private String JavaDoc fVariableName;
27     private AbstractDescriptor[] fExtensions;
28
29     public DescriptorManager(String JavaDoc extensionPoint, String JavaDoc variableName) {
30         Assert.isNotNull(extensionPoint);
31         Assert.isNotNull(variableName);
32         fExtensionPoint= extensionPoint;
33         fVariableName= variableName;
34     }
35     
36     public AbstractDescriptor getDescriptor(Object JavaDoc element) throws CoreException {
37         if (fExtensions == null)
38             init();
39             
40         List JavaDoc candidates= new ArrayList JavaDoc(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         // No support for conflicts yet.
51
return (AbstractDescriptor)candidates.get(0);
52     }
53     
54     protected abstract AbstractDescriptor createDescriptor(IConfigurationElement element);
55     
56     // ---- extension point reading -----------------------------------
57

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