1 11 package org.eclipse.core.internal.registry.osgi; 12 13 import org.eclipse.core.internal.registry.RegistryMessages; 14 import org.eclipse.core.internal.runtime.RuntimeLog; 15 import org.eclipse.core.runtime.*; 16 import org.eclipse.core.runtime.spi.IRegistryProvider; 17 import org.osgi.framework.BundleContext; 18 import org.osgi.util.tracker.ServiceTracker; 19 20 public final class RegistryProviderOSGI implements IRegistryProvider { 21 22 private ServiceTracker registryTracker = null; 23 24 27 public IExtensionRegistry getRegistry() { 28 if (registryTracker == null) { 29 BundleContext context = Activator.getContext(); 30 if (context == null) { 31 RuntimeLog.log(new Status(IStatus.ERROR, RegistryMessages.OWNER_NAME, 0, RegistryMessages.bundle_not_activated, null)); 32 return null; 33 } 34 registryTracker = new ServiceTracker(context, IExtensionRegistry.class.getName(), null); 35 registryTracker.open(); 36 } 37 return (IExtensionRegistry) registryTracker.getService(); 38 } 39 40 43 public void release() { 44 if (registryTracker != null) { 45 registryTracker.close(); 46 registryTracker = null; 47 } 48 } 49 } 50 | Popular Tags |