Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e2b8e479ac2ae654b25925d240c0452c3576eff7 (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
/*******************************************************************************
 * Copyright (c) 2000, 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.core.internal.registry;

import java.util.Arrays;
import java.util.Map;
import org.eclipse.core.runtime.IExtensionDelta;
import org.eclipse.core.runtime.IRegistryChangeEvent;

/**
 * A registry change event implementation. A filter can be specified. In that case, only 
 * deltas for the selected host will be available to clients.
 */
public final class RegistryChangeEvent implements IRegistryChangeEvent {
	private String filter;
	private Map deltas;

	public RegistryChangeEvent(Map deltas, String filter) {
		this.deltas = deltas;
		this.filter = filter;
	}

	private RegistryDelta[] getHostDeltas() {
		// if there is a filter, return only the delta for the selected plug-in
		if (filter != null) {
			RegistryDelta singleDelta = getHostDelta(filter);
			return singleDelta == null ? new RegistryDelta[0] : new RegistryDelta[] {singleDelta};
		}
		// there is no filter - return all deltas
		return (RegistryDelta[]) deltas.values().toArray(new RegistryDelta[deltas.size()]);
	}

	private RegistryDelta getHostDelta(String pluginId) {
		if (filter != null && !pluginId.equals(filter))
			return null;
		return (RegistryDelta) deltas.get(pluginId);
	}

	@Override
	public IExtensionDelta[] getExtensionDeltas() {
		RegistryDelta[] hostDeltas = getHostDeltas();
		if (hostDeltas.length == 0)
			return new IExtensionDelta[0];
		int extensionDeltasSize = 0;
		for (int i = 0; i < hostDeltas.length; i++)
			extensionDeltasSize += hostDeltas[i].getExtensionDeltasCount();
		IExtensionDelta[] extensionDeltas = new IExtensionDelta[extensionDeltasSize];
		for (int i = 0, offset = 0; i < hostDeltas.length; i++) {
			IExtensionDelta[] hostExtDeltas = hostDeltas[i].getExtensionDeltas();
			System.arraycopy(hostExtDeltas, 0, extensionDeltas, offset, hostExtDeltas.length);
			offset += hostExtDeltas.length;
		}
		return extensionDeltas;
	}

	@Override
	public IExtensionDelta[] getExtensionDeltas(String hostName) {
		RegistryDelta hostDelta = getHostDelta(hostName);
		if (hostDelta == null)
			return new IExtensionDelta[0];
		return hostDelta.getExtensionDeltas();
	}

	@Override
	public IExtensionDelta[] getExtensionDeltas(String hostName, String extensionPoint) {
		RegistryDelta hostDelta = getHostDelta(hostName);
		if (hostDelta == null)
			return new IExtensionDelta[0];
		return hostDelta.getExtensionDeltas(hostName + '.' + extensionPoint);
	}

	@Override
	public IExtensionDelta getExtensionDelta(String hostName, String extensionPoint, String extension) {
		RegistryDelta hostDelta = getHostDelta(hostName);
		if (hostDelta == null)
			return null;
		return hostDelta.getExtensionDelta(hostName + '.' + extensionPoint, extension);
	}

	@Override
	public String toString() {
		return "RegistryChangeEvent:  " + Arrays.asList(getHostDeltas()); //$NON-NLS-1$
	}
}

Back to the top