1 11 package org.eclipse.pde.internal.core; 12 13 import java.net.URL ; 14 import java.util.ArrayList ; 15 16 import org.eclipse.core.resources.IProject; 17 import org.eclipse.osgi.service.resolver.BundleDescription; 18 import org.eclipse.osgi.service.resolver.HostSpecification; 19 import org.eclipse.pde.core.plugin.IExtensions; 20 import org.eclipse.pde.core.plugin.IFragmentModel; 21 import org.eclipse.pde.core.plugin.IPluginExtensionPoint; 22 import org.eclipse.pde.core.plugin.IPluginModel; 23 import org.eclipse.pde.core.plugin.IPluginModelBase; 24 import org.eclipse.pde.core.plugin.PluginRegistry; 25 import org.eclipse.pde.internal.core.ibundle.IBundlePluginModelBase; 26 import org.eclipse.pde.internal.core.plugin.ExternalPluginModelBase; 27 28 public class PDEManager { 29 30 public static IFragmentModel[] findFragmentsFor(IPluginModelBase model) { 31 ArrayList result = new ArrayList (); 32 BundleDescription desc = getBundleDescription(model); 33 if (desc != null) { 34 BundleDescription[] fragments = desc.getFragments(); 35 for (int i = 0; i < fragments.length; i++) { 36 IPluginModelBase candidate = PluginRegistry.findModel(fragments[i]); 37 if (candidate instanceof IFragmentModel) { 38 result.add(candidate); 39 } 40 } 41 } 42 return (IFragmentModel[])result.toArray(new IFragmentModel[result.size()]); 43 } 44 45 public static IPluginModel findHostFor(IFragmentModel fragment) { 46 BundleDescription desc = getBundleDescription(fragment); 47 if (desc != null) { 48 HostSpecification spec = desc.getHost(); 49 if (spec != null) { 50 IPluginModelBase host = PluginRegistry.findModel(spec.getName()); 51 if (host instanceof IPluginModel) 52 return (IPluginModel)host; 53 } 54 } 55 return null; 56 } 57 58 private static BundleDescription getBundleDescription(IPluginModelBase model) { 59 BundleDescription desc = model.getBundleDescription(); 60 61 if (desc == null && model.getUnderlyingResource() != null) { 62 IProject project = model.getUnderlyingResource().getProject(); 66 IPluginModelBase coreModel = PluginRegistry.findModel(project); 67 if (coreModel != null) 68 desc = coreModel.getBundleDescription(); 69 } 70 return desc; 71 } 72 73 public static URL [] getNLLookupLocations(IPluginModelBase model) { 74 ArrayList urls = new ArrayList (); 75 addNLLocation(model, urls); 76 if (model instanceof IPluginModel) { 77 IFragmentModel[] fragments = findFragmentsFor(model); 78 for (int i = 0; i < fragments.length; i++) { 79 addNLLocation(fragments[i], urls); 80 } 81 } else if (model instanceof IFragmentModel){ 82 IPluginModel host = findHostFor((IFragmentModel)model); 83 if (host != null) 84 addNLLocation(host, urls); 85 } 86 return (URL [])urls.toArray(new URL [urls.size()]); 87 } 88 89 private static void addNLLocation(IPluginModelBase model, ArrayList urls) { 90 URL location = model.getNLLookupLocation(); 91 if (location != null) 92 urls.add(location); 93 } 94 95 public static String getBundleLocalization(IPluginModelBase model) { 96 if (model instanceof IBundlePluginModelBase && model.getUnderlyingResource() != null) 97 return((IBundlePluginModelBase)model).getBundleLocalization(); 98 99 if (model instanceof ExternalPluginModelBase) 100 return ((ExternalPluginModelBase)model).getLocalization(); 101 102 return "plugin"; } 104 105 public static IPluginExtensionPoint findExtensionPoint(String fullID) { 106 IPluginModelBase[] bases = PluginRegistry.getActiveModels(); 107 for (int i = 0; i < bases.length; i++) { 108 IExtensions extensions = bases[i].getExtensions(); 109 if (extensions == null) 110 continue; 111 IPluginExtensionPoint[] points = extensions.getExtensionPoints(); 112 for (int j = 0; j < points.length; j++) { 113 if (fullID.equals(points[j].getFullId())) 114 return points[j]; 115 } 116 } 117 return null; 118 } 119 120 } 121 | Popular Tags |