Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5b121bf59efb4559e0b41a23d9f534bca361d71b (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
134
135
136
137
138
139
140
141
142
143
144
145
/*******************************************************************************
 * Copyright (c) 2004, 2006 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.Map;
import org.eclipse.core.runtime.InvalidRegistryObjectException;

/**
 * @since 3.1
 */
public class TemporaryObjectManager implements IObjectManager {
	private Map<?, ?> actualObjects; //id --> registry objects
	private RegistryObjectManager parent; //the main object manager (should be equals to extensionRegistry.getObjectManager)

	public TemporaryObjectManager(Map<?, ?> actualObjects, RegistryObjectManager parent) {
		this.actualObjects = actualObjects;
		this.parent = parent;
	}

	@Override
	public Handle getHandle(int id, byte type) {
		switch (type) {
			case RegistryObjectManager.EXTENSION_POINT :
				return new ExtensionPointHandle(this, id);

			case RegistryObjectManager.EXTENSION :
				return new ExtensionHandle(this, id);

			case RegistryObjectManager.CONFIGURATION_ELEMENT :
				return new ConfigurationElementHandle(this, id);

			case RegistryObjectManager.THIRDLEVEL_CONFIGURATION_ELEMENT :
			default : //avoid compiler error, type should always be known
				return new ThirdLevelConfigurationElementHandle(this, id);
		}
	}

	@Override
	public Handle[] getHandles(int[] ids, byte type) {
		Handle[] results = null;
		int nbrId = ids.length;
		switch (type) {
			case RegistryObjectManager.EXTENSION_POINT :
				if (nbrId == 0)
					return ExtensionPointHandle.EMPTY_ARRAY;
				results = new ExtensionPointHandle[nbrId];
				for (int i = 0; i < nbrId; i++) {
					results[i] = new ExtensionPointHandle(this, ids[i]);
				}
				break;

			case RegistryObjectManager.EXTENSION :
				if (nbrId == 0)
					return ExtensionHandle.EMPTY_ARRAY;
				results = new ExtensionHandle[nbrId];
				for (int i = 0; i < nbrId; i++) {
					results[i] = new ExtensionHandle(this, ids[i]);
				}
				break;

			case RegistryObjectManager.CONFIGURATION_ELEMENT :
				if (nbrId == 0)
					return ConfigurationElementHandle.EMPTY_ARRAY;
				results = new ConfigurationElementHandle[nbrId];
				for (int i = 0; i < nbrId; i++) {
					results[i] = new ConfigurationElementHandle(this, ids[i]);
				}
				break;

			case RegistryObjectManager.THIRDLEVEL_CONFIGURATION_ELEMENT :
				if (nbrId == 0)
					return ConfigurationElementHandle.EMPTY_ARRAY;
				results = new ThirdLevelConfigurationElementHandle[nbrId];
				for (int i = 0; i < nbrId; i++) {
					results[i] = new ThirdLevelConfigurationElementHandle(this, ids[i]);
				}
				break;
		}
		return results;
	}

	@Override
	synchronized public Object getObject(int id, byte type) {
		Object result = null;
		try {
			result = parent.getObject(id, type);
		} catch (InvalidRegistryObjectException e) {
			if (actualObjects != null) {
				result = actualObjects.get(new Integer(id));
			}
		}
		if (result == null)
			throw new InvalidRegistryObjectException();
		return result;
	}

	@Override
	synchronized public RegistryObject[] getObjects(int[] values, byte type) {
		if (values.length == 0) {
			switch (type) {
				case RegistryObjectManager.EXTENSION_POINT :
					return ExtensionPoint.EMPTY_ARRAY;
				case RegistryObjectManager.EXTENSION :
					return Extension.EMPTY_ARRAY;
				case RegistryObjectManager.CONFIGURATION_ELEMENT :
				case RegistryObjectManager.THIRDLEVEL_CONFIGURATION_ELEMENT :
					return ConfigurationElement.EMPTY_ARRAY;
			}
		}

		RegistryObject[] results = null;
		switch (type) {
			case RegistryObjectManager.EXTENSION_POINT :
				results = new ExtensionPoint[values.length];
				break;
			case RegistryObjectManager.EXTENSION :
				results = new Extension[values.length];
				break;
			case RegistryObjectManager.CONFIGURATION_ELEMENT :
			case RegistryObjectManager.THIRDLEVEL_CONFIGURATION_ELEMENT :
				results = new ConfigurationElement[values.length];
				break;
		}
		for (int i = 0; i < values.length; i++) {
			results[i] = (RegistryObject) getObject(values[i], type);
		}
		return results;
	}

	@Override
	public synchronized void close() {
		actualObjects = null;
	}
}

Back to the top