1 11 package org.eclipse.osgi.framework.internal.core; 12 13 import java.io.IOException ; 14 import java.net.URL ; 15 import java.util.Enumeration ; 16 17 import org.osgi.service.packageadmin.ExportedPackage; 18 import org.osgi.service.packageadmin.PackageAdmin; 19 20 26 public class GlobalPolicy implements IBuddyPolicy { 27 private PackageAdmin admin; 28 29 public GlobalPolicy(PackageAdmin admin) { 30 this.admin = admin; 31 } 32 33 public Class loadClass(String name) { 34 ExportedPackage pkg = admin.getExportedPackage(BundleLoader.getPackageName(name)); 35 if (pkg == null) 36 return null; 37 try { 38 return pkg.getExportingBundle().loadClass(name); 39 } catch (ClassNotFoundException e) { 40 return null; 41 } 42 } 43 44 public URL loadResource(String name) { 45 ExportedPackage pkg = admin.getExportedPackage(BundleLoader.getResourcePackageName(name)); 47 if (pkg == null) 48 return null; 49 return pkg.getExportingBundle().getResource(name); 50 } 51 52 public Enumeration loadResources(String name) { 53 ExportedPackage[] pkgs = admin.getExportedPackages(BundleLoader.getResourcePackageName(name)); 55 if (pkgs == null || pkgs.length == 0) 56 return null; 57 58 Enumeration results = null; 60 for (int i = 0; i < pkgs.length; i++) { 61 try { 62 results = BundleLoader.compoundEnumerations(results, pkgs[i].getExportingBundle().getResources(name)); 63 } catch (IOException e) { 64 } 66 } 67 68 return results; 69 } 70 } 71 | Popular Tags |