KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > PDEStateHelper


1 /*******************************************************************************
2  * Copyright (c) 2003, 2007 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.pde.internal.core;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.osgi.service.resolver.BundleDescription;
17 import org.eclipse.osgi.service.resolver.ExportPackageDescription;
18 import org.eclipse.pde.core.plugin.IFragmentModel;
19 import org.eclipse.pde.core.plugin.IPluginExtensionPoint;
20 import org.eclipse.pde.core.plugin.IPluginModelBase;
21 import org.eclipse.pde.core.plugin.PluginRegistry;
22
23
24 public class PDEStateHelper {
25
26     /**
27      * Returns the bundles that export packages being imported via the Import-Package header
28      * by resolved fragments of a given bundle
29      *
30      * @param root the bundle
31      * @return
32      * an array of bundles supplying packages to resolved fragments of the given bundle
33      */

34     public static BundleDescription[] getImportedByFragments(BundleDescription root) {
35         BundleDescription[] fragments = root.getFragments();
36         List JavaDoc list = new ArrayList JavaDoc();
37         for (int i = 0; i < fragments.length; i++) {
38             if (fragments[i].isResolved()) {
39                 BundleDescription[] toAdd = getImportedBundles(fragments[i]);
40                 for (int j = 0; j < toAdd.length; j++) {
41                     if (!list.contains(toAdd[j]))
42                         list.add(toAdd[j]);
43                 }
44             }
45         }
46         BundleDescription[] result = new BundleDescription[list.size()];
47         return (BundleDescription[]) list.toArray(result);
48     }
49     
50     /**
51      * Returns the bundles that export packages imported by the given bundle
52      * via the Import-Package header
53      *
54      * @param root the given bundle
55      *
56      * @return an array of bundles that export packages being imported by the given bundle
57      */

58     public static BundleDescription[] getImportedBundles(BundleDescription root) {
59         if (root == null)
60             return new BundleDescription[0];
61         ExportPackageDescription[] packages = root.getResolvedImports();
62         ArrayList JavaDoc resolvedImports = new ArrayList JavaDoc(packages.length);
63         for (int i = 0; i < packages.length; i++)
64             if (!root.getLocation().equals(packages[i].getExporter().getLocation())
65                     && !resolvedImports.contains(packages[i].getExporter()))
66                 resolvedImports.add(packages[i].getExporter());
67         return (BundleDescription[]) resolvedImports.toArray(new BundleDescription[resolvedImports.size()]);
68     }
69
70     public static IPluginExtensionPoint findExtensionPoint(String JavaDoc fullID) {
71         if (fullID == null || fullID.length() == 0)
72             return null;
73         // separate plugin ID first
74
int lastDot = fullID.lastIndexOf('.');
75         if (lastDot == -1)
76             return null;
77         String JavaDoc pluginID = fullID.substring(0, lastDot);
78         IPluginModelBase model = PluginRegistry.findModel(pluginID);
79         if (model == null)
80             return PDEManager.findExtensionPoint(fullID);
81         String JavaDoc pointID = fullID.substring(lastDot + 1);
82         IPluginExtensionPoint[] points = model.getPluginBase().getExtensionPoints();
83         for (int i = 0; i < points.length; i++) {
84             IPluginExtensionPoint point = points[i];
85             if (point.getId().equals(pointID))
86                 return point;
87         }
88         IFragmentModel[] fragments = PDEManager.findFragmentsFor(model);
89         for (int i = 0; i < fragments.length; i++) {
90             points = fragments[i].getPluginBase().getExtensionPoints();
91             for (int j = 0; j < points.length; j++)
92                 if (points[j].getId().equals(pointID))
93                     return points[j];
94         }
95         return PDEManager.findExtensionPoint(fullID);
96     }
97     
98 }
99
Popular Tags