KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > registry > osgi > RegistryProviderOSGI


1 /*******************************************************************************
2  * Copyright (c) 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.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     /* (non-Javadoc)
25      * @see org.eclipse.equinox.registry.IRegistryProvider#getRegistry()
26      */

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     /**
41      * Release OSGi tracker
42      */

43     public void release() {
44         if (registryTracker != null) {
45             registryTracker.close();
46             registryTracker = null;
47         }
48     }
49 }
50
Popular Tags