Ejemplo n.º 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;
 }
Ejemplo n.º 2
0
 /**
  * Adds a list of DynamicImport-Package manifest elements to the dynamic import tables of this
  * BundleLoader. Duplicate packages are checked and not added again.
  *
  * @param packages the DynamicImport-Package elements to add.
  */
 public final synchronized void addDynamicImportPackage(ManifestElement[] packages) {
   if (packages == null) return;
   ArrayList dynamicImports = new ArrayList(packages.length);
   for (int i = 0; i < packages.length; i++) dynamicImports.add(packages[i].getValue());
   if (dynamicImports.size() > 0)
     addDynamicImportPackage((String[]) dynamicImports.toArray(new String[dynamicImports.size()]));
 }
Ejemplo n.º 3
0
  /**
   * Adds a list of DynamicImport-Package manifest elements to the dynamic import tables of this
   * BundleLoader. Duplicate packages are checked and not added again. This method is not thread
   * safe. Callers should ensure synchronization when calling this method.
   *
   * @param packages the DynamicImport-Package elements to add.
   */
  private void addDynamicImportPackage(String[] packages) {
    if (packages == null) return;

    loaderFlags |= FLAG_HASDYNAMICIMPORTS;
    int size = packages.length;
    ArrayList stems;
    if (dynamicImportPackageStems == null) {
      stems = new ArrayList(size);
    } else {
      stems = new ArrayList(size + dynamicImportPackageStems.length);
      for (int i = 0; i < dynamicImportPackageStems.length; i++) {
        stems.add(dynamicImportPackageStems[i]);
      }
    }

    ArrayList names;
    if (dynamicImportPackages == null) {
      names = new ArrayList(size);
    } else {
      names = new ArrayList(size + dynamicImportPackages.length);
      for (int i = 0; i < dynamicImportPackages.length; i++) {
        names.add(dynamicImportPackages[i]);
      }
    }

    for (int i = 0; i < size; i++) {
      String name = packages[i];
      if (isDynamicallyImported(name)) continue;
      if (name.equals("*")) {
        /* shortcut */
        //$NON-NLS-1$
        loaderFlags |= FLAG_HASDYNAMICEIMPORTALL;
        return;
      }

      if (name.endsWith(".*")) // $NON-NLS-1$
      stems.add(name.substring(0, name.length() - 1));
      else names.add(name);
    }

    size = stems.size();
    if (size > 0) dynamicImportPackageStems = (String[]) stems.toArray(new String[size]);

    size = names.size();
    if (size > 0) dynamicImportPackages = (String[]) names.toArray(new String[size]);
  }
Ejemplo n.º 4
0
 private void addDynamicImportPackage(ImportPackageSpecification[] packages) {
   if (packages == null) return;
   ArrayList dynamicImports = new ArrayList(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((String[]) dynamicImports.toArray(new String[dynamicImports.size()]));
 }
Ejemplo n.º 5
0
 private static PackageSource createMultiSource(String packageName, PackageSource[] sources) {
   if (sources.length == 1) return sources[0];
   ArrayList sourceList = new ArrayList(sources.length);
   for (int i = 0; i < sources.length; i++) {
     SingleSourcePackage[] innerSources = sources[i].getSuppliers();
     for (int j = 0; j < innerSources.length; j++)
       if (!sourceList.contains(innerSources[j])) sourceList.add(innerSources[j]);
   }
   return new MultiSourcePackage(
       packageName,
       (SingleSourcePackage[]) sourceList.toArray(new SingleSourcePackage[sourceList.size()]));
 }