KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > registry > RegistryChangeEvent


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.core.internal.registry;
12
13 import java.util.Arrays JavaDoc;
14 import java.util.Map JavaDoc;
15 import org.eclipse.core.runtime.IExtensionDelta;
16 import org.eclipse.core.runtime.IRegistryChangeEvent;
17
18 /**
19  * A registry change event implementation. A filter can be specified. In that case, only
20  * deltas for the selected host will be available to clients.
21  */

22 public final class RegistryChangeEvent implements IRegistryChangeEvent {
23     private String JavaDoc filter;
24     private Map JavaDoc deltas;
25
26     public RegistryChangeEvent(Map JavaDoc deltas, String JavaDoc filter) {
27         this.deltas = deltas;
28         this.filter = filter;
29     }
30
31     private RegistryDelta[] getHostDeltas() {
32         // if there is a filter, return only the delta for the selected plug-in
33
if (filter != null) {
34             RegistryDelta singleDelta = getHostDelta(filter);
35             return singleDelta == null ? new RegistryDelta[0] : new RegistryDelta[] {singleDelta};
36         }
37         // there is no filter - return all deltas
38
return (RegistryDelta[]) deltas.values().toArray(new RegistryDelta[deltas.size()]);
39     }
40
41     private RegistryDelta getHostDelta(String JavaDoc pluginId) {
42         if (filter != null && !pluginId.equals(filter))
43             return null;
44         return (RegistryDelta) deltas.get(pluginId);
45     }
46
47     public IExtensionDelta[] getExtensionDeltas() {
48         RegistryDelta[] hostDeltas = getHostDeltas();
49         if (hostDeltas.length == 0)
50             return new IExtensionDelta[0];
51         int extensionDeltasSize = 0;
52         for (int i = 0; i < hostDeltas.length; i++)
53             extensionDeltasSize += hostDeltas[i].getExtensionDeltasCount();
54         IExtensionDelta[] extensionDeltas = new IExtensionDelta[extensionDeltasSize];
55         for (int i = 0, offset = 0; i < hostDeltas.length; i++) {
56             IExtensionDelta[] hostExtDeltas = hostDeltas[i].getExtensionDeltas();
57             System.arraycopy(hostExtDeltas, 0, extensionDeltas, offset, hostExtDeltas.length);
58             offset += hostExtDeltas.length;
59         }
60         return extensionDeltas;
61     }
62
63     public IExtensionDelta[] getExtensionDeltas(String JavaDoc hostName) {
64         RegistryDelta hostDelta = getHostDelta(hostName);
65         if (hostDelta == null)
66             return new IExtensionDelta[0];
67         return hostDelta.getExtensionDeltas();
68     }
69
70     public IExtensionDelta[] getExtensionDeltas(String JavaDoc hostName, String JavaDoc extensionPoint) {
71         RegistryDelta hostDelta = getHostDelta(hostName);
72         if (hostDelta == null)
73             return new IExtensionDelta[0];
74         return hostDelta.getExtensionDeltas(hostName + '.' + extensionPoint);
75     }
76
77     public IExtensionDelta getExtensionDelta(String JavaDoc hostName, String JavaDoc extensionPoint, String JavaDoc extension) {
78         RegistryDelta hostDelta = getHostDelta(hostName);
79         if (hostDelta == null)
80             return null;
81         return hostDelta.getExtensionDelta(hostName + '.' + extensionPoint, extension);
82     }
83
84     public String JavaDoc toString() {
85         return "RegistryChangeEvent: " + Arrays.asList(getHostDeltas()); //$NON-NLS-1$
86
}
87 }
88
Popular Tags