KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > runtime > ContributorFactoryOSGi


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.runtime;
12
13 import org.eclipse.core.internal.registry.osgi.OSGIUtils;
14 import org.eclipse.core.runtime.spi.RegistryContributor;
15 import org.osgi.framework.Bundle;
16
17 /**
18  * The contributor factory creates new registry contributors for use in OSGi-based
19  * registries.
20  * <p>
21  * This class can not be extended or instantiated by clients.
22  * </p><p>
23  * <b>Note:</b> This class/interface is part of an interim API that is still under
24  * development and expected to change significantly before reaching stability.
25  * It is being made available at this early stage to solicit feedback from pioneering
26  * adopters on the understanding that any code that uses this API will almost certainly
27  * be broken (repeatedly) as the API evolves.
28  * </p>
29  * @since org.eclipse.equinox.registry 3.2
30  */

31 public final class ContributorFactoryOSGi {
32
33     /**
34      * Creates registry contributor object based on a Bundle. The bundle must not
35      * be <code>null</code>.
36      *
37      * @param contributor bundle associated with the contribution
38      * @return new registry contributor based on the Bundle
39      */

40     public static IContributor createContributor(Bundle contributor) {
41         String JavaDoc id = Long.toString(contributor.getBundleId());
42         String JavaDoc name = contributor.getSymbolicName();
43         String JavaDoc hostId = null;
44         String JavaDoc hostName = null;
45
46         // determine host properties, if any
47
if (OSGIUtils.getDefault().isFragment(contributor)) {
48             Bundle[] hosts = OSGIUtils.getDefault().getHosts(contributor);
49             if (hosts != null) {
50                 Bundle hostBundle = hosts[0];
51                 hostId = Long.toString(hostBundle.getBundleId());
52                 hostName = hostBundle.getSymbolicName();
53             }
54         }
55
56         return new RegistryContributor(id, name, hostId, hostName);
57     }
58
59     /**
60      * Returns the OSGi bundle used to define this contributor. If a fragment
61      * was used to create the contributor, the fragment is returned.
62      *
63      * <p>The method may return null if the contributor is not based on a bundle,
64      * if the bundle can't be found, or if the bundle is presently unresolved or
65      * uninstalled.</p>
66      *
67      * @param contributor bundle-based registry contributor
68      * @return the actual OSGi bundle associated with this contributor
69      * @since org.eclipse.equinox.registry 3.3
70      */

71     public static Bundle resolve(IContributor contributor) {
72         if (contributor == null)
73             return null;
74         if (!(contributor instanceof RegistryContributor))
75             return null;
76         String JavaDoc symbolicName = ((RegistryContributor) contributor).getActualName();
77         return OSGIUtils.getDefault().getBundle(symbolicName);
78     }
79 }
80
Popular Tags