Skip to main content
summaryrefslogtreecommitdiffstats
blob: fd9f62b13687e12515c28c669f2a3529efab87ca (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package org.eclipse.jst.common.internal.annotations.core;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.jem.util.RegistryReader;
import org.eclipse.jem.util.logger.proxy.Logger;

public class AnnotationsProviderManager extends RegistryReader {
	
	public static final AnnotationsProviderManager INSTANCE = new AnnotationsProviderManager();
	
	static {
		INSTANCE.readRegistry();
	}

	public static class Descriptor {

		public static final String EXTENSION_PT_PLUGIN = "org.eclipse.jst.common.annotations.core"; //$NON-NLS-1$
		public static final String ANNOTATIONS_PROVIDER = "annotationsProvider"; //$NON-NLS-1$
		public static final String CLASSNAME = "className"; //$NON-NLS-1$
		
		private final IConfigurationElement configElement;

		public Descriptor(IConfigurationElement aConfigElement) {
			super();
			configElement = aConfigElement;
		}

		public IAnnotationsProvider createInstance() {
			IAnnotationsProvider instance = null;
			try {
				instance = (IAnnotationsProvider) configElement.createExecutableExtension(CLASSNAME);
			} catch (CoreException e) {
				Logger.getLogger().logError(e);
			}
			return instance;
		}
	}
	
	private List annotationsProviders;
	
	/**
	 * Default constructor
	 */
	public AnnotationsProviderManager() {
		super(Descriptor.EXTENSION_PT_PLUGIN, Descriptor.ANNOTATIONS_PROVIDER);
	}
	
	@Override
	public boolean readElement(IConfigurationElement element) {
		if (!element.getName().equals(Descriptor.ANNOTATIONS_PROVIDER))
			return false;
		addAnnotationsProvider(new Descriptor(element));
		return true;
	}
	
	/**
	 * @param descriptor
	 */
	protected void addAnnotationsProvider(Descriptor descriptor) {
		IAnnotationsProvider provider = descriptor.createInstance();
		if (provider != null)
			getAnnotationsProviders().add(provider);
	}
	
	/**
	 * @return Returns the annotationsProviders.
	 */
	public List getAnnotationsProviders() {
		if (annotationsProviders == null)
			annotationsProviders = new ArrayList();
		return annotationsProviders;
	}

}

Back to the top