Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 89abdf44bbae2d8b582f75610f213ba58f6813c7 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*******************************************************************************
 * Copyright (c) 2004, 2009 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.core.internal.registry;

import java.util.ArrayList;
import java.util.Arrays;
import org.eclipse.core.runtime.*;

/**
 * This is the copy of the ExtensionPointHandle minus the getDeclaringPluginDescriptor()
 * method that was moved into compatibility plugin.
 *
 * This class should not be used directly. Use ExtensionPointHandle instead.
 *
 * @since org.eclipse.equinox.registry 3.2
 */
public class BaseExtensionPointHandle extends Handle implements IExtensionPoint {

	public BaseExtensionPointHandle(IObjectManager objectManager, int id) {
		super(objectManager, id);
	}

	@Override
	public IExtension[] getExtensions() {
		return (IExtension[]) objectManager.getHandles(getExtensionPoint().getRawChildren(), RegistryObjectManager.EXTENSION);
	}

	// This method is left for backward compatibility only
	@Override
	public String getNamespace() {
		return getContributor().getName();
	}

	@Override
	public String getNamespaceIdentifier() {
		return getExtensionPoint().getNamespace();
	}

	@Override
	public IContributor getContributor() {
		return getExtensionPoint().getContributor();
	}

	protected boolean shouldPersist() {
		return getExtensionPoint().shouldPersist();
	}

	@Override
	public IExtension getExtension(String extensionId) {
		if (extensionId == null)
			return null;
		int[] children = getExtensionPoint().getRawChildren();
		for (int i = 0; i < children.length; i++) {
			//	Here we directly get the object because it avoids the creation of garbage and because we'll need the object anyway to compare the value
			if (extensionId.equals(((Extension) objectManager.getObject(children[i], RegistryObjectManager.EXTENSION)).getUniqueIdentifier()))
				return (ExtensionHandle) objectManager.getHandle(children[i], RegistryObjectManager.EXTENSION);
		}
		return null;
	}

	@Override
	public IConfigurationElement[] getConfigurationElements() {
		//get the actual extension objects since we'll need to get the configuration elements information.
		Extension[] tmpExtensions = (Extension[]) objectManager.getObjects(getExtensionPoint().getRawChildren(), RegistryObjectManager.EXTENSION);
		if (tmpExtensions.length == 0)
			return ConfigurationElementHandle.EMPTY_ARRAY;

		ArrayList<Handle> result = new ArrayList<>();
		for (int i = 0; i < tmpExtensions.length; i++) {
			result.addAll(Arrays.asList(objectManager.getHandles(tmpExtensions[i].getRawChildren(), RegistryObjectManager.CONFIGURATION_ELEMENT)));
		}
		return result.toArray(new IConfigurationElement[result.size()]);
	}

	public String getLabelAsIs() {
		return getExtensionPoint().getLabelAsIs();
	}

	@Override
	public String getLabel() {
		return getExtensionPoint().getLabel();
	}

	@Override
	public String getLabel(String locale) {
		return getExtensionPoint().getLabel(locale);
	}

	@Override
	public String getSchemaReference() {
		return getExtensionPoint().getSchemaReference();
	}

	@Override
	public String getSimpleIdentifier() {
		return getExtensionPoint().getSimpleIdentifier();
	}

	@Override
	public String getUniqueIdentifier() {
		return getExtensionPoint().getUniqueIdentifier();
	}

	@Override
	RegistryObject getObject() {
		return getExtensionPoint();
	}

	protected ExtensionPoint getExtensionPoint() {
		return (ExtensionPoint) objectManager.getObject(getId(), RegistryObjectManager.EXTENSION_POINT);
	}

	@Override
	public boolean isValid() {
		try {
			getExtensionPoint();
		} catch (InvalidRegistryObjectException e) {
			return false;
		}
		return true;
	}
}

Back to the top