private void addDynamicImportPackage(ImportPackageSpecification[] packages) { if (packages == null) return; List<String> dynamicImports = new ArrayList<String>(packages.length); for (int i = 0; i < packages.length; i++) if (ImportPackageSpecification.RESOLUTION_DYNAMIC.equals(packages[i].getDirective(Constants.RESOLUTION_DIRECTIVE))) dynamicImports.add(packages[i].getName()); if (dynamicImports.size() > 0) addDynamicImportPackage(dynamicImports.toArray(new String[dynamicImports.size()])); }
public Enumeration<URL> getResources(String name) { Enumeration<URL> results = null; for (int i = 0; i < suppliers.length; i++) results = BundleLoader.compoundEnumerations(results, suppliers[i].getResources(name)); return results; }
public final PackageSource getPackageSource(String pkgName) { PackageSource result = findSource(pkgName); if (!isExportedPackage(pkgName)) return result; // if the package is exported then we need to get the local source PackageSource localSource = exportSources.getPackageSource(pkgName); if (result == null) return localSource; if (localSource == null) return result; return createMultiSource(pkgName, new PackageSource[] {result, localSource}); }
Class<?> findClass(String name, boolean checkParent) throws ClassNotFoundException { ClassLoader parentCL = getParentClassLoader(); if (checkParent && parentCL != null && name.startsWith(JAVA_PACKAGE)) // 1) if startsWith "java." delegate to parent and terminate search // we want to throw ClassNotFoundExceptions if a java.* class cannot be loaded from the parent. return parentCL.loadClass(name); try { if (USE_GLOBAL_DEADLOCK_AVOIDANCE_LOCK) lock(createClassLoader()); return findClassInternal(name, checkParent, parentCL); } finally { if (USE_GLOBAL_DEADLOCK_AVOIDANCE_LOCK) unlock(); } }
Class<?> findClass(String name, boolean checkParent) throws ClassNotFoundException { ClassLoader parentCL = getParentClassLoader(); if (checkParent && parentCL != null && name.startsWith(JAVA_PACKAGE)) // 1) if startsWith "java." delegate to parent and terminate search // we want to throw ClassNotFoundExceptions if a java.* class cannot be loaded from the parent. return parentCL.loadClass(name); return findClassInternal(name, checkParent, parentCL); }
@Override protected Collection<String> listResources(String path, String filePattern, int options) { String pkgName = getResourcePackageName(path.endsWith("/") ? path : path + '/'); //$NON-NLS-1$ if ((path.length() > 1) && (path.charAt(0) == '/')) /* if name has a leading slash */ path = path.substring(1); /* remove leading slash before search */ Map<String, PackageSource> importSources = getImportedSources(null); Collection<PackageSource> imports; synchronized (importSources) { if (id.equals(pkgName) || (subPackages && isSubPackage(pkgName, id))) packages.add(id); visited.add(this); // always add ourselves so we do not recurse back to ourselves for (ModuleWire bundleWire : requiredBundleWires) { BundleLoader loader = getProviderLoader(bundleWire); if (loader != null) { loader.addProvidedPackageNames(pkgName, packages, subPackages, visited); PackageSource externalSource = findImportedSource(name, null); if (externalSource != null) { externalSource = findRequiredSource(name, null); Collection<String> localResources = getModuleClassLoader().listLocalResources(path, filePattern, options); for (String resource : localResources) { String resourcePkg = getResourcePackageName(resource); if (!importedPackages.contains(resourcePkg) && !result.contains(resource)) result.add(resource);
final void addExportedProvidersFor(String packageName, List<PackageSource> result, Collection<BundleLoader> visited) { if (visited.contains(this)) return; visited.add(this); // See if we locally provide the package. PackageSource local = null; if (isExportedPackage(packageName)) local = exportSources.getPackageSource(packageName); else if (isSubstitutedExport(packageName)) { result.add(findImportedSource(packageName, visited)); return; // should not continue to required bundles in this case } // Must search required bundles that are exported first. for (ModuleWire bundleWire : requiredBundleWires) { if (local != null || BundleNamespace.VISIBILITY_REEXPORT.equals(bundleWire.getRequirement().getDirectives().get(BundleNamespace.REQUIREMENT_VISIBILITY_DIRECTIVE))) { // always add required bundles first if we locally provide the package // This allows a bundle to provide a package from a required bundle without // re-exporting the whole required bundle. BundleLoader loader = getProviderLoader(bundleWire); if (loader != null) { loader.addExportedProvidersFor(packageName, result, visited); } } } // now add the locally provided package. if (local != null) result.add(local); }
final void addProvidedPackageNames(String symbolicName, String packageName, List<String> result, boolean subPackages, KeyedHashSet visitied) { if (!visitied.add(bundle)) return; for (String exported : exportedPackages) { if (exported.equals(packageName) || (subPackages && isSubPackage(packageName, exported))) { if (!result.contains(exported)) result.add(exported); } } if (substitutedPackages != null) for (String substituted : substitutedPackages) { if (substituted.equals(packageName) || (subPackages && isSubPackage(packageName, substituted))) { if (!result.contains(substituted)) result.add(substituted); } } if (requiredBundles != null) { int size = reexportTable == null ? 0 : reexportTable.length; int reexportIndex = 0; for (int i = 0; i < requiredBundles.length; i++) { if (reexportIndex < size && reexportTable[reexportIndex] == i) { reexportIndex++; requiredBundles[i].getBundleLoader().addProvidedPackageNames(symbolicName, packageName, result, subPackages, visitied); } } } }
final PackageSource createExportPackageSource(ModuleWire importWire, Collection<BundleLoader> visited) { String name = (String) importWire.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE); BundleLoader providerLoader = (BundleLoader) importWire.getProviderWiring().getModuleLoader(); if (providerLoader == null) { return createMultiSource(name, new PackageSource[0]); } PackageSource requiredSource = providerLoader.findRequiredSource(name, visited); PackageSource exportSource = providerLoader.exportSources.createPackageSource(importWire.getCapability(), false); if (requiredSource == null) return exportSource; return createMultiSource(name, new PackageSource[] {requiredSource, exportSource}); }
private PackageSource findDynamicSource(String pkgName) { if (!isExportedPackage(pkgName) && isDynamicallyImported(pkgName)) { if (debug.DEBUG_LOADER) { Debug.println("BundleLoader[" + this + "] attempting to resolve dynamic package: " + pkgName); //$NON-NLS-1$ //$NON-NLS-2$ } ModuleRevision revision = wiring.getRevision(); ModuleWire dynamicWire = revision.getRevisions().getModule().getContainer().resolveDynamic(pkgName, revision); if (dynamicWire != null) { PackageSource source = createExportPackageSource(dynamicWire, null); if (debug.DEBUG_LOADER) { Debug.println("BundleLoader[" + this + "] using dynamic import source: " + source); //$NON-NLS-1$ //$NON-NLS-2$ } synchronized (importedSources) { importedSources.add(source); } return source; } } return null; }
public Enumeration<URL> loadResources(String name) { //get all exported packages that match the resource's package ExportedPackage[] pkgs = admin.getExportedPackages(BundleLoader.getResourcePackageName(name)); if (pkgs == null || pkgs.length == 0) return null; //get all matching resources for each package Enumeration<URL> results = null; for (int i = 0; i < pkgs.length; i++) { try { results = BundleLoader.compoundEnumerations(results, pkgs[i].getExportingBundle().getResources(name)); } catch (IOException e) { //ignore IO problems and try next package } } return results; } }
BundleLoader loader = (BundleLoader) bundleWire.getProviderWiring().getModuleLoader(); if (loader != null) { loader.addExportedProvidersFor(pkgName, result, visited); source = createMultiSource(pkgName, srcs);
@Override public ModuleLoader createModuleLoader(ModuleWiring wiring) { if (wiring.getBundle().getBundleId() == 0) { ClassLoader cl = EquinoxContainer.class.getClassLoader(); cl = cl == null ? BOOT_CLASSLOADER : cl; return new SystemBundleLoader(wiring, container, cl); } if ((wiring.getRevision().getTypes() & BundleRevision.TYPE_FRAGMENT) != 0) { return new FragmentLoader(); } return new BundleLoader(wiring, container, moduleClassLoaderParent); }
/** * Finds the class for a bundle. This method is used for delegation by the bundle's classloader. */ public Class<?> findClass(String name) throws ClassNotFoundException { return findClass(name, true); }
static public void closeBundleLoader(BundleLoaderProxy proxy) { if (proxy == null) return; // First close the BundleLoader BundleLoader loader = proxy.getBasicBundleLoader(); if (loader != null) loader.close(); proxy.setStale(); // if proxy is not null then make sure to unset user object // associated with the proxy in the state BundleDescription description = proxy.getBundleDescription(); // must set it back to the bundle object; not null // need to make sure the user object is a BundleReference description.setUserObject(proxy.getBundleData()); } }
private PackageSource findDynamicSource(String pkgName) { if (isDynamicallyImported(pkgName)) { ExportPackageDescription exportPackage = bundle.getFramework().getAdaptor().getState().linkDynamicImport(proxy.getBundleDescription(), pkgName); if (exportPackage != null) { PackageSource source = createExportPackageSource(exportPackage, null); synchronized (this) { if (importedSources == null) importedSources = new KeyedHashSet(false); } synchronized (importedSources) { importedSources.add(source); } return source; } } return null; }
final PackageSource createExportPackageSource(ModuleWire importWire, Collection<BundleLoader> visited) { String name = (String) importWire.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE); BundleLoader providerLoader = getProviderLoader(importWire); if (providerLoader == null) { return createMultiSource(name, new PackageSource[0]); } PackageSource requiredSource = providerLoader.findRequiredSource(name, visited); PackageSource exportSource = providerLoader.exportSources.createPackageSource(importWire.getCapability(), false); if (requiredSource == null) return exportSource; return createMultiSource(name, new PackageSource[] {requiredSource, exportSource}); }
private Map<String, PackageSource> getImportedSources(Collection<BundleLoader> visited) { synchronized (importedSources) { if (importsInitialized) { return importedSources; } List<ModuleWire> importWires = wiring.getRequiredModuleWires(PackageNamespace.PACKAGE_NAMESPACE); if (importWires != null) { for (ModuleWire importWire : importWires) { PackageSource source = createExportPackageSource(importWire, visited); if (source != null) { importedSources.put(source.getId(), source); } } } importsInitialized = true; return importedSources; } }
final void addProvidedPackageNames(String packageName, List<String> result, boolean subPackages, Collection<BundleLoader> visited) { if (visited.contains(this)) return; visited.add(this); synchronized (exportedPackages) { for (String exported : exportedPackages) { if (exported.equals(packageName) || (subPackages && isSubPackage(packageName, exported))) { if (!result.contains(exported)) result.add(exported); } } } for (String substituted : wiring.getSubstitutedNames()) { if (substituted.equals(packageName) || (subPackages && isSubPackage(packageName, substituted))) { if (!result.contains(substituted)) result.add(substituted); } } for (ModuleWire bundleWire : requiredBundleWires) { if (BundleNamespace.VISIBILITY_REEXPORT.equals(bundleWire.getRequirement().getDirectives().get(BundleNamespace.REQUIREMENT_VISIBILITY_DIRECTIVE))) { BundleLoader loader = getProviderLoader(bundleWire); if (loader != null) { loader.addProvidedPackageNames(packageName, result, subPackages, visited); } } } }
Class<?> findClass(String name, boolean checkParent) throws ClassNotFoundException { if (checkParent && parent != null && name.startsWith(JAVA_PACKAGE)) // 1) if startsWith "java." delegate to parent and terminate search // we want to throw ClassNotFoundExceptions if a java.* class cannot be loaded from the parent. return parent.loadClass(name); return findClassInternal(name, checkParent); }