1 11 package org.eclipse.core.internal.registry; 12 13 import java.util.Arrays ; 14 import java.util.Map ; 15 import org.eclipse.core.runtime.IExtensionDelta; 16 import org.eclipse.core.runtime.IRegistryChangeEvent; 17 18 22 public final class RegistryChangeEvent implements IRegistryChangeEvent { 23 private String filter; 24 private Map deltas; 25 26 public RegistryChangeEvent(Map deltas, String filter) { 27 this.deltas = deltas; 28 this.filter = filter; 29 } 30 31 private RegistryDelta[] getHostDeltas() { 32 if (filter != null) { 34 RegistryDelta singleDelta = getHostDelta(filter); 35 return singleDelta == null ? new RegistryDelta[0] : new RegistryDelta[] {singleDelta}; 36 } 37 return (RegistryDelta[]) deltas.values().toArray(new RegistryDelta[deltas.size()]); 39 } 40 41 private RegistryDelta getHostDelta(String 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 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 hostName, String 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 hostName, String extensionPoint, String 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 toString() { 85 return "RegistryChangeEvent: " + Arrays.asList(getHostDeltas()); } 87 } 88 | Popular Tags |