コード例 #1
0
 private PackageSource findRequiredSource(String pkgName, KeyedHashSet visited) {
   if (requiredBundles == null) return null;
   synchronized (requiredSources) {
     PackageSource result = (PackageSource) requiredSources.getByKey(pkgName);
     if (result != null) return result.isNullSource() ? null : result;
   }
   if (visited == null) visited = new KeyedHashSet(false);
   visited.add(bundle); // always add ourselves so we do not recurse back to ourselves
   ArrayList result = new ArrayList(3);
   for (int i = 0; i < requiredBundles.length; i++) {
     BundleLoader requiredLoader = requiredBundles[i].getBundleLoader();
     requiredLoader.addExportedProvidersFor(proxy.getSymbolicName(), pkgName, result, visited);
   }
   // found some so cache the result for next time and return
   PackageSource source;
   if (result.size() == 0) {
     // did not find it in our required bundles lets record the failure
     // so we do not have to do the search again for this package.
     source = NullPackageSource.getNullPackageSource(pkgName);
   } else if (result.size() == 1) {
     // if there is just one source, remember just the single source
     source = (PackageSource) result.get(0);
   } else {
     // if there was more than one source, build a multisource and cache that.
     PackageSource[] srcs = (PackageSource[]) result.toArray(new PackageSource[result.size()]);
     source = createMultiSource(pkgName, srcs);
   }
   synchronized (requiredSources) {
     requiredSources.add(source);
   }
   return source.isNullSource() ? null : source;
 }
コード例 #2
0
 private PackageSource findImportedSource(String pkgName, KeyedHashSet visited) {
   KeyedHashSet imports = getImportedSources(visited);
   if (imports == null) return null;
   synchronized (imports) {
     return (PackageSource) imports.getByKey(pkgName);
   }
 }
コード例 #3
0
  final void addExportedProvidersFor(
      String symbolicName, String packageName, ArrayList result, KeyedHashSet visited) {
    if (!visited.add(bundle)) return;

    // See if we locally provide the package.
    PackageSource local = null;
    if (isExportedPackage(packageName)) local = proxy.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.
    if (requiredBundles != null) {
      int size = reexportTable == null ? 0 : reexportTable.length;
      int reexportIndex = 0;
      for (int i = 0; i < requiredBundles.length; i++) {
        if (local != null) {
          // 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.
          requiredBundles[i]
              .getBundleLoader()
              .addExportedProvidersFor(symbolicName, packageName, result, visited);
        } else if (reexportIndex < size && reexportTable[reexportIndex] == i) {
          reexportIndex++;
          requiredBundles[i]
              .getBundleLoader()
              .addExportedProvidersFor(symbolicName, packageName, result, visited);
        }
      }
    }

    // now add the locally provided package.
    if (local != null && local.isFriend(symbolicName)) result.add(local);
  }
コード例 #4
0
 public synchronized KeyedHashSet getImportedSources(KeyedHashSet visited) {
   if ((loaderFlags & FLAG_IMPORTSINIT) != 0) return importedSources;
   BundleDescription bundleDesc = proxy.getBundleDescription();
   ExportPackageDescription[] packages = bundleDesc.getResolvedImports();
   if (packages != null && packages.length > 0) {
     if (importedSources == null) importedSources = new KeyedHashSet(packages.length, false);
     for (int i = 0; i < packages.length; i++) {
       if (packages[i].getExporter() == bundleDesc)
         continue; // ignore imports resolved to this bundle
       PackageSource source = createExportPackageSource(packages[i], visited);
       if (source != null) importedSources.add(source);
     }
   }
   loaderFlags |= FLAG_IMPORTSINIT;
   return importedSources;
 }
コード例 #5
0
 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;
 }