org.eclipse.osgi_3.8.2.v20130124-134944

    }
      if (hook != null) {
        hook.filterMatches(imp.getRequirement(), asCapabilities(new ArrayMap(capabilities, candidates)));
      }
    } while (timestamp != state.getTimeStamp());
    for (List<BundleCapability> capabilities = candidates.iterator(); capabilities.hasNext();)
    {
      ResolverExport export = (ResolverExport)capabilities.next();
      if (DEBUG_IMPORTS) {
        log("CHECKING: " + export.getExporter().getBundleDescription() + ", " + export.getName());
      }
      int originalState = export.getExporter().getState();
      if ((!imp.isDynamic()) || (originalState == 2))
      {
        if ((imp.getSelectedSupplier() != null) && (((ResolverExport)imp.getSelectedSupplier()).getExporter() == imp.getBundle())) {
          break;
        }
        imp.addPossibleSupplier(export);
        if (imp.getBundle() != export.getExporter())
        {
          for (int j = 0; j < substitutableExps.length; j++) {
            if (substitutableExps[j].getSubstitute() == null) {
              substitutableExps[j].setSubstitute(export);
            }
          }
          if (((originalState != 2) && (!resolveBundle(export.getExporter(), cycle)) && (!developmentMode)) || (export.getSubstitute() != null))
          {
            imp.removePossibleSupplier(export);
            if (imp.getSelectedSupplier() != null) {
              continue;
            }
            for (int j = 0; j < substitutableExps.length; j++) {
              if (substitutableExps[j].getSubstitute() == export) {
                substitutableExps[j].setSubstitute(null);
              }
            }
            continue;
          }
        }
        else
        {
          if (export.getSubstitute() != null) {
            continue;
          }
        }
        if ((imp.getBundle() != export.getExporter()) && 
          (export.getExporter().getState() == 1)) {
          if (!cycle.contains(imp.getBundle()))
          {
            cycle.add(imp.getBundle());
            if (DEBUG_CYCLES) {
              log("import-package cycle: " + imp.getBundle() + " -> " + imp.getSelectedSupplier() + " from " + imp.getSelectedSupplier().getBundleDescription());
            }
          }
        }
        if (DEBUG_IMPORTS) {
          log("Found match: " + export.getExporter() + ". Wiring " + imp.getBundle() + ":" + imp.getName());
        }
        result = true;
      }
    }
    if (result) {
      return true;
    }
    if (imp.isOptional()) {
      return true;
    }
    if ((substitutableExps.length > 0) && (substitutableExps[0].getSubstitute() == null)) {
      return true;
    }
    return false;
  }
  
  private void setBundleUnresolved(ResolverBundle bundle, boolean removed, boolean keepFragsAttached)
  {
    if ((bundle.getState() == 0) && (!developmentMode)) {
      return;
    }
    if ((removed) || (!keepFragsAttached))
    {
      resolverExports.remove(bundle.getExportPackages());
      removeGenerics(bundle.getGenericCapabilities());
      bundle.detachAllFragments();
      bundle.detachFromHosts();
      bundle.initialize(false);
      if (!removed)
      {
        resolverExports.put(bundle.getExportPackages());
        addGenerics(bundle.getGenericCapabilities());
      }
    }
    if ((!removed) && ((!developmentMode) || (!unresolvedBundles.contains(bundle)))) {
      unresolvedBundles.add(bundle);
    }
    bundle.setState(0);
  }
  
  private void setBundleResolved(ResolverBundle bundle)
  {
    if (bundle.getState() == 2) {
      return;
    }
    unresolvedBundles.remove(bundle);
    bundle.setState(2);
  }
  
  private void setBundleResolving(ResolverBundle bundle)
  {
    if (bundle.getState() == 1) {
      return;
    }
    unresolvedBundles.remove(bundle);
    bundle.setState(1);
  }
  
  private void stateResolveBundles(ResolverBundle[] resolvedBundles)
  {
    for (int i = 0; i < resolvedBundles.length; i++) {
      if (!resolvedBundles[i].getBundleDescription().isResolved()) {
        stateResolveBundle(resolvedBundles[i]);
      }
    }
  }
  
  private void stateResolveConstraints(ResolverBundle rb)
  {
    ResolverImport[] imports = rb.getImportPackages();
    for (int i = 0; i < imports.length; i++)
    {
      ResolverExport export = (ResolverExport)imports[i].getSelectedSupplier();
      BaseDescription supplier = export == null ? null : export.getExportPackageDescription();
      state.resolveConstraint(imports[i].getVersionConstraint(), supplier);
    }
    BundleConstraint[] requires = rb.getRequires();
    for (int i = 0; i < requires.length; i++)
    {
      ResolverBundle bundle = (ResolverBundle)requires[i].getSelectedSupplier();
      BaseDescription supplier = bundle == null ? null : bundle.getBundleDescription();
      state.resolveConstraint(requires[i].getVersionConstraint(), supplier);
    }
    GenericConstraint[] genericRequires = rb.getGenericRequires();
    for (int i = 0; i < genericRequires.length; i++)
    {
      VersionSupplier[] matchingCapabilities = genericRequires[i].getMatchingCapabilities();
      if (matchingCapabilities == null) {
        state.resolveConstraint(genericRequires[i].getVersionConstraint(), null);
      } else {
        for (int j = 0; j < matchingCapabilities.length; j++) {
          state.resolveConstraint(genericRequires[i].getVersionConstraint(), matchingCapabilities[j].getBaseDescription());
        }
      }
    }
  }
  
  private void stateResolveFragConstraints(ResolverBundle rb)
  {
    ResolverBundle host = (ResolverBundle)rb.getHost().getSelectedSupplier();
    ImportPackageSpecification[] imports = rb.getBundleDescription().getImportPackages();
    for (int i = 0; i < imports.length; i++)
    {
      ResolverImport hostImport = host == null ? null : host.getImport(imports[i].getName());
      ResolverExport export = (ResolverExport)(hostImport == null ? null : hostImport.getSelectedSupplier());
      BaseDescription supplier = export == null ? null : export.getExportPackageDescription();
      state.resolveConstraint(imports[i], supplier);
    }
    BundleSpecification[] requires = rb.getBundleDescription().getRequiredBundles();
    for (int i = 0; i < requires.length; i++)
    {
      BundleConstraint hostRequire = host == null ? null : host.getRequire(requires[i].getName());
      ResolverBundle bundle = (ResolverBundle)(hostRequire == null ? null : hostRequire.getSelectedSupplier());
      BaseDescription supplier = bundle == null ? null : bundle.getBundleDescription();
      state.resolveConstraint(requires[i], supplier);
    }
    GenericConstraint[] genericRequires = rb.getGenericRequires();
    for (int i = 0; i < genericRequires.length; i++)
    {
      VersionSupplier[] matchingCapabilities = genericRequires[i].getMatchingCapabilities();
      if (matchingCapabilities == null) {
        state.resolveConstraint(genericRequires[i].getVersionConstraint(), null);
      } else {
        for (int j = 0; j < matchingCapabilities.length; j++) {
          state.resolveConstraint(genericRequires[i].getVersionConstraint(), matchingCapabilities[j].getBaseDescription());
        }
      }
    }
  }
  
  private void stateResolveBundle(ResolverBundle rb)
  {
    if ((!rb.isResolved()) && (!developmentMode)) {
      return;
    }
    if (rb.isFragment()) {
      stateResolveFragConstraints(rb);
    } else {
      stateResolveConstraints(rb);
    }
    Map<String, List<StateWire>> stateWires = new HashMap();
    
    ResolverExport[] exports = rb.getSelectedExports();
    List<ExportPackageDescription> selectedExports = new ArrayList(exports.length);
    for (int i = 0; i < exports.length; i++) {
      if (permissionChecker.checkPackagePermission(exports[i].getExportPackageDescription())) {
        selectedExports.add(exports[i].getExportPackageDescription());
      }
    }
    ExportPackageDescription[] selectedExportsArray = (ExportPackageDescription[])selectedExports.toArray(new ExportPackageDescription[selectedExports.size()]);
    
    ResolverExport[] substituted = rb.getSubstitutedExports();
    List<ExportPackageDescription> substitutedExports = new ArrayList(substituted.length);
    for (int i = 0; i < substituted.length; i++) {
      substitutedExports.add(substituted[i].getExportPackageDescription());
    }
    ExportPackageDescription[] substitutedExportsArray = (ExportPackageDescription[])substitutedExports.toArray(new ExportPackageDescription[substitutedExports.size()]);
    
    ExportPackageDescription[] exportsWiredToArray = getExportsWiredTo(rb, stateWires);
    
    BundleConstraint[] requires = rb.getRequires();
    List<BundleDescription> bundlesWiredTo = new ArrayList(requires.length);
    List<StateWire> requireWires = new ArrayList(requires.length);
    for (int i = 0; i < requires.length; i++) {
      if (requires[i].getSelectedSupplier() != null)
      {
        BundleDescription supplier = (BundleDescription)requires[i].getSelectedSupplier().getBaseDescription();
        bundlesWiredTo.add(supplier);
        StateWire requireWire = newStateWire(rb.getBundleDescription(), requires[i].getVersionConstraint(), supplier, supplier);
        requireWires.add(requireWire);
      }
    }
    BundleDescription[] bundlesWiredToArray = (BundleDescription[])bundlesWiredTo.toArray(new BundleDescription[bundlesWiredTo.size()]);
    if (!requireWires.isEmpty()) {
      stateWires.put("osgi.wiring.bundle", requireWires);
    }
    GenericCapability[] capabilities = rb.getGenericCapabilities();
    List<GenericDescription> selectedCapabilities = new ArrayList(capabilities.length);
    GenericCapability[] arrayOfGenericCapability1;
    int j = (arrayOfGenericCapability1 = capabilities).length;
    for (int i = 0; i < j; i++)
    {
      GenericCapability capability = arrayOfGenericCapability1[i];
      if ((capability.isEffective()) && (permissionChecker.checkCapabilityPermission(capability.getGenericDescription()))) {
        selectedCapabilities.add(capability.getGenericDescription());
      }
    }
    GenericDescription[] selectedCapabilitiesArray = (GenericDescription[])selectedCapabilities.toArray(new GenericDescription[selectedCapabilities.size()]);
    
    GenericConstraint[] genericRequires = rb.getGenericRequires();
    Object resolvedGenericRequires = new ArrayList(genericRequires.length);
    GenericConstraint[] arrayOfGenericConstraint1;
    int m = (arrayOfGenericConstraint1 = genericRequires).length;
    for (int k = 0; k < m; k++)
    {
      GenericConstraint genericConstraint = arrayOfGenericConstraint1[k];
      VersionSupplier[] matching = genericConstraint.getMatchingCapabilities();
      if (matching != null)
      {
        VersionSupplier[] arrayOfVersionSupplier1;
        int i1 = (arrayOfVersionSupplier1 = matching).length;
        for (int n = 0; n < i1; n++)
        {
          VersionSupplier capability = arrayOfVersionSupplier1[n];
          GenericDescription supplier = ((GenericCapability)capability).getGenericDescription();
          ((List)resolvedGenericRequires).add(supplier);
          StateWire genericWire = newStateWire(rb.getBundleDescription(), genericConstraint.getVersionConstraint(), supplier.getSupplier(), supplier);
          List<StateWire> genericWires = (List)stateWires.get(genericConstraint.getNameSpace());
          if (genericWires == null)
          {
            genericWires = new ArrayList();
            stateWires.put(genericConstraint.getNameSpace(), genericWires);
          }
          genericWires.add(genericWire);
        }
      }
    }
    GenericDescription[] capabilitiesWiredToArray = (GenericDescription[])((List)resolvedGenericRequires).toArray(new GenericDescription[((List)resolvedGenericRequires).size()]);
    
    BundleDescription[] hostBundles = null;
    if (rb.isFragment())
    {
      VersionSupplier[] matchingBundles = rb.getHost().getPossibleSuppliers();
      if ((matchingBundles != null) && (matchingBundles.length > 0))
      {
        hostBundles = new BundleDescription[matchingBundles.length];
        Object hostWires = new ArrayList(matchingBundles.length);
        stateWires.put("osgi.wiring.host", hostWires);
        for (int i = 0; i < matchingBundles.length; i++)
        {
          hostBundles[i] = matchingBundles[i].getBundleDescription();
          StateWire hostWire = newStateWire(rb.getBundleDescription(), rb.getHost().getVersionConstraint(), hostBundles[i], hostBundles[i]);
          ((List)hostWires).add(hostWire);
          if (hostBundles[i].isResolved())
          {
            ExportPackageDescription[] newSelectedExports = null;
            GenericDescription[] newSelectedCapabilities = null;
            if (rb.isNewFragmentExports())
            {
              ResolverExport[] hostExports = ((ResolverBundle)matchingBundles[i]).getSelectedExports();
              newSelectedExports = new ExportPackageDescription[hostExports.length];
              for (int j = 0; j < hostExports.length; j++) {
                newSelectedExports[j] = hostExports[j].getExportPackageDescription();
              }
            }
            if (rb.isNewFragmentCapabilities())
            {
              GenericCapability[] hostCapabilities = ((ResolverBundle)matchingBundles[i]).getGenericCapabilities();
              newSelectedCapabilities = new GenericDescription[hostCapabilities.length];
              for (int j = 0; j < hostCapabilities.length; j++) {
                newSelectedCapabilities[j] = hostCapabilities[j].getGenericDescription();
              }
            }
            if ((newSelectedCapabilities != null) || (newSelectedExports != null))
            {
              if (newSelectedCapabilities == null) {
                newSelectedCapabilities = hostBundles[i].getSelectedGenericCapabilities();
              }
              if (newSelectedExports == null) {
                newSelectedExports = hostBundles[i].getSelectedExports();
              }
              state.resolveBundle(hostBundles[i], true, null, newSelectedExports, hostBundles[i].getSubstitutedExports(), newSelectedCapabilities, hostBundles[i].getResolvedRequires(), hostBundles[i].getResolvedImports(), hostBundles[i].getResolvedGenericRequires(), ((BundleDescriptionImpl)hostBundles[i]).getWires());
            }
          }
        }
      }
    }
    state.resolveBundle(rb.getBundleDescription(), rb.isResolved(), hostBundles, selectedExportsArray, substitutedExportsArray, selectedCapabilitiesArray, bundlesWiredToArray, exportsWiredToArray, capabilitiesWiredToArray, stateWires);
  }
  
  private static ExportPackageDescription[] getExportsWiredTo(ResolverBundle rb, Map<String, List<StateWire>> stateWires)
  {
    ResolverImport[] imports = rb.getImportPackages();
    List<ExportPackageDescription> exportsWiredTo = new ArrayList(imports.length);
    List<StateWire> importWires = new ArrayList(imports.length);
    for (int i = 0; i < imports.length; i++) {
      if (imports[i].getSelectedSupplier() != null)
      {
        ExportPackageDescription supplier = (ExportPackageDescription)imports[i].getSelectedSupplier().getBaseDescription();
        exportsWiredTo.add(supplier);
        StateWire wire = newStateWire(rb.getBundleDescription(), imports[i].getVersionConstraint(), supplier.getExporter(), supplier);
        importWires.add(wire);
      }
    }
    if ((stateWires != null) && (!importWires.isEmpty())) {
      stateWires.put("osgi.wiring.package", importWires);
    }
    return (ExportPackageDescription[])exportsWiredTo.toArray(new ExportPackageDescription[exportsWiredTo.size()]);
  }
  
  private static StateWire newStateWire(BundleDescription requirementHost, VersionConstraint declaredRequirement, BundleDescription capabilityHost, BaseDescription declaredCapability)
  {
    BaseDescription fragDeclared = ((BaseDescriptionImpl)declaredCapability).getFragmentDeclaration();
    declaredCapability = fragDeclared != null ? fragDeclared : declaredCapability;
    return new StateWire(requirementHost, declaredRequirement, capabilityHost, declaredCapability);
  }
  
  public synchronized ExportPackageDescription resolveDynamicImport(BundleDescription importingBundle, String requestedPackage)
  {
    if (state == null) {
      throw new IllegalStateException("RESOLVER_NO_STATE");
    }
    if (!initialized) {
      initialize();
    }
    hook = ((state instanceof StateImpl) ? ((StateImpl)state).getResolverHook() : null);
    try
    {
      ResolverBundle rb = (ResolverBundle)bundleMapping.get(importingBundle);
      if (rb.getExport(requestedPackage) != null) {
        return null;
      }
      ResolverImport[] resolverImports = rb.getImportPackages();
      ExportPackageDescription localExportPackageDescription1;
      for (int j = 0; j < resolverImports.length; j++) {
        if (resolverImports[j].isDynamic())
        {
          ExportPackageDescription supplier = resolveDynamicImport(resolverImports[j], requestedPackage);
          if (supplier != null) {
            return supplier;
          }
        }
      }
      ImportPackageSpecification[] addedDynamicImports = importingBundle.getAddedDynamicImportPackages();
      ImportPackageSpecification[] arrayOfImportPackageSpecification1;
      int j = (arrayOfImportPackageSpecification1 = addedDynamicImports).length;
      for (int i = 0; i < j; i++)
      {
        ImportPackageSpecification addedDynamicImport = arrayOfImportPackageSpecification1[i];
        ResolverImport newImport = new ResolverImport(rb, addedDynamicImport);
        ExportPackageDescription supplier = resolveDynamicImport(newImport, requestedPackage);
        if (supplier != null) {
          return supplier;
        }
      }
      if ((DEBUG) || (DEBUG_IMPORTS)) {
        log("Failed to resolve dynamic import: " + requestedPackage);
      }
      return null;
    }
    finally
    {
      hook = null;
    }
  }
  
  private void addStateWire(BundleDescription importingBundle, VersionConstraint requirement, BundleDescription capabilityHost, ExportPackageDescription capability)
  {
    Map<String, List<StateWire>> wires = ((BundleDescriptionImpl)importingBundle).getWires();
    List<StateWire> imports = (List)wires.get("osgi.wiring.package");
    if (imports == null)
    {
      imports = new ArrayList();
      wires.put("osgi.wiring.package", imports);
    }
    imports.add(newStateWire(importingBundle, requirement, capabilityHost, capability));
  }
  
  private ExportPackageDescription resolveDynamicImport(ResolverImport dynamicImport, String requestedPackage)
  {
    String importName = dynamicImport.getName();
    if ((importName.equals("*")) || (
      (importName.endsWith(".*")) && (requestedPackage.startsWith(importName.substring(0, importName.length() - 1))))) {
      dynamicImport.setName(requestedPackage);
    }
    try
    {
      if (!requestedPackage.equals(dynamicImport.getName())) {
        return null;
      }
      if (resolveImport(dynamicImport, new ArrayList()))
      {
        groupingChecker.populateRoots(dynamicImport.getBundle());
        while (dynamicImport.getSelectedSupplier() != null) {
          if (groupingChecker.isDynamicConsistent(dynamicImport.getBundle(), (ResolverExport)dynamicImport.getSelectedSupplier()) != null)
          {
            dynamicImport.selectNextSupplier();
          }
          else
          {
            if (DEBUG_IMPORTS) {
              log("Resolved dynamic import: " + dynamicImport.getBundle() + ":" + dynamicImport.getName() + " -> " + ((ResolverExport)dynamicImport.getSelectedSupplier()).getExporter() + ":" + requestedPackage);
            }
            ResolverExport export = (ResolverExport)dynamicImport.getSelectedSupplier();
            groupingChecker.populateRoots(dynamicImport.getBundle(), export);
            
            ExportPackageDescription supplier = export.getExportPackageDescription();
            if (supplier != null) {
              addStateWire(dynamicImport.getBundleDescription(), dynamicImport.getVersionConstraint(), supplier.getExporter(), supplier);
            }
            return supplier;
          }
        }
        dynamicImport.clearPossibleSuppliers();
      }
    }
    finally
    {
      if (importName.endsWith("*")) {
        dynamicImport.clearPossibleSuppliers();
      }
      dynamicImport.setName(null);
    }
    if (importName.endsWith("*")) {
      dynamicImport.clearPossibleSuppliers();
    }
    dynamicImport.setName(null);
    
    return null;
  }
  
  public void bundleAdded(BundleDescription bundle)
  {
    if (!initialized) {
      return;
    }
    if (bundleMapping.get(bundle) != null) {
      return;
    }
    ResolverBundle rb = new ResolverBundle(bundle, this);
    bundleMapping.put(bundle, rb);
    unresolvedBundles.add(rb);
    resolverExports.put(rb.getExportPackages());
    resolverBundles.put(rb.getName(), rb);
    addGenerics(rb.getGenericCapabilities());
    if ((hook != null) && (rb.isFragment())) {
      attachFragment0(rb);
    }
  }
  
  public void bundleRemoved(BundleDescription bundle, boolean pending)
  {
    ResolverBundle rb = initialized ? (ResolverBundle)bundleMapping.get(bundle) : null;
    if (rb != null) {
      rb.setUninstalled();
    }
    internalBundleRemoved(bundle, pending);
  }
  
  private void internalBundleRemoved(BundleDescription bundle, boolean pending)
  {
    if (pending) {
      removalPending.put(new Long(bundle.getBundleId()), bundle);
    }
    if (!initialized) {
      return;
    }
    ResolverBundle rb = (ResolverBundle)bundleMapping.get(bundle);
    if (rb == null) {
      return;
    }
    if (!pending)
    {
      bundleMapping.remove(bundle);
      groupingChecker.clear(rb);
    }
    if ((!pending) || (!bundle.isResolved()))
    {
      resolverExports.remove(rb.getExportPackages());
      resolverBundles.remove(rb);
      removeGenerics(rb.getGenericCapabilities());
    }
    unresolvedBundles.remove(rb);
  }
  
  private void unresolveBundle(ResolverBundle bundle, boolean removed)
  {
    if (bundle == null) {
      return;
    }
    List<BundleDescription> removedBundles = removalPending.remove(new Long(bundle.getBundleDescription().getBundleId()));
    for (Iterator localIterator = removedBundles.iterator(); localIterator.hasNext();)
    {
      BundleDescription removedDesc = (BundleDescription)localIterator.next();
      ResolverBundle re = (ResolverBundle)bundleMapping.get(removedDesc);
      unresolveBundle(re, true);
      state.removeBundleComplete(removedDesc);
      resolverExports.remove(re.getExportPackages());
      resolverBundles.remove(re);
      removeGenerics(re.getGenericCapabilities());
      bundleMapping.remove(removedDesc);
      groupingChecker.clear(re);
      if (removedDesc == bundle.getBundleDescription()) {
        removed = true;
      }
    }
    if ((!bundle.getBundleDescription().isResolved()) && (!developmentMode)) {
      return;
    }
    CompositeResolveHelperRegistry currentLinks = compositeHelpers;
    if (currentLinks != null)
    {
      CompositeResolveHelper helper = currentLinks.getCompositeResolveHelper(bundle.getBundleDescription());
      if (helper != null) {
        helper.giveExports(null);
      }
    }
    setBundleUnresolved(bundle, removed, false);
    
    BundleDescription[] dependents = bundle.getBundleDescription().getDependents();
    state.resolveBundle(bundle.getBundleDescription(), false, null, null, null, null, null, null, null, null);
    for (int i = 0; i < dependents.length; i++) {
      unresolveBundle((ResolverBundle)bundleMapping.get(dependents[i]), false);
    }
  }
  
  public void bundleUpdated(BundleDescription newDescription, BundleDescription existingDescription, boolean pending)
  {
    internalBundleRemoved(existingDescription, pending);
    bundleAdded(newDescription);
  }
  
  public void flush()
  {
    resolverExports = null;
    resolverBundles = null;
    resolverGenerics = null;
    unresolvedBundles = null;
    bundleMapping = null;
    List<BundleDescription> removed = removalPending.getAllValues();
    for (Iterator localIterator = removed.iterator(); localIterator.hasNext();)
    {
      BundleDescription removedDesc = (BundleDescription)localIterator.next();
      state.removeBundleComplete(removedDesc);
    }
    removalPending.clear();
    initialized = false;
  }
  
  public State getState()
  {
    return state;
  }
  
  public void setState(State newState)
  {
    if (state != null) {
      throw new IllegalStateException("Cannot change the State of a Resolver");
    }
    state = newState;
    flush();
  }
  
  private void setDebugOptions()
  {
    FrameworkDebugOptions options = FrameworkDebugOptions.getDefault();
    if (options == null) {
      return;
    }
    DEBUG = options.getBooleanOption("org.eclipse.osgi/resolver/debug", false);
    DEBUG_WIRING = options.getBooleanOption("org.eclipse.osgi/resolver/wiring", false);
    DEBUG_IMPORTS = options.getBooleanOption("org.eclipse.osgi/resolver/imports", false);
    DEBUG_REQUIRES = options.getBooleanOption("org.eclipse.osgi/resolver/requires", false);
    DEBUG_GENERICS = options.getBooleanOption("org.eclipse.osgi/resolver/generics", false);
    DEBUG_USES = options.getBooleanOption("org.eclipse.osgi/resolver/uses", false);
    DEBUG_CYCLES = options.getBooleanOption("org.eclipse.osgi/resolver/cycles", false);
  }
  
  private void printWirings()
  {
    log("****** Result Wirings ******");
    List<ResolverBundle> bundles = resolverBundles.getAllValues();
    for (Iterator localIterator = bundles.iterator(); localIterator.hasNext();)
    {
      ResolverBundle rb = (ResolverBundle)localIterator.next();
      if (!rb.getBundleDescription().isResolved())
      {
        log("    * WIRING for " + rb);
        
        BundleConstraint[] requireBundles = rb.getRequires();
        if (requireBundles.length == 0) {
          log("        (r) no requires");
        } else {
          for (int i = 0; i < requireBundles.length; i++) {
            if (requireBundles[i].getSelectedSupplier() == null) {
              log("        (r) " + rb.getBundleDescription() + " -> NULL!!!");
            } else {
              log("        (r) " + rb.getBundleDescription() + " -> " + requireBundles[i].getSelectedSupplier());
            }
          }
        }
        BundleConstraint hostSpec = rb.getHost();
        if (hostSpec != null)
        {
          VersionSupplier[] hosts = hostSpec.getPossibleSuppliers();
          if (hosts != null) {
            for (int i = 0; i < hosts.length; i++) {
              log("        (h) " + rb.getBundleDescription() + " -> " + hosts[i].getBundleDescription());
            }
          }
        }
        ResolverImport[] imports = rb.getImportPackages();
        if (imports.length == 0) {
          log("        (w) no imports");
        } else {
          for (int i = 0; i < imports.length; i++) {
            if ((imports[i].isDynamic()) && (imports[i].getSelectedSupplier() == null)) {
              log("        (w) " + imports[i].getBundle() + ":" + imports[i].getName() + " -> DYNAMIC");
            } else if ((imports[i].isOptional()) && (imports[i].getSelectedSupplier() == null)) {
              log("        (w) " + imports[i].getBundle() + ":" + imports[i].getName() + " -> OPTIONAL (could not be wired)");
            } else if (imports[i].getSelectedSupplier() == null) {
              log("        (w) " + imports[i].getBundle() + ":" + imports[i].getName() + " -> NULL!!!");
            } else {
              log(
                "        (w) " + imports[i].getBundle() + ":" + imports[i].getName() + " -> " + ((ResolverExport)imports[i].getSelectedSupplier()).getExporter() + ":" + imports[i].getSelectedSupplier().getName());
            }
          }
        }
      }
    }
  }
  
  static void log(String message)
  {
    Debug.println(message);
  }
  
  VersionHashMap<ResolverExport> getResolverExports()
  {
    return resolverExports;
  }
  
  public void setSelectionPolicy(Comparator<BaseDescription> selectionPolicy)
  {
    this.selectionPolicy = selectionPolicy;
  }
  
  public Comparator<BaseDescription> getSelectionPolicy()
  {
    return selectionPolicy;
  }
  
  public void setCompositeResolveHelperRegistry(CompositeResolveHelperRegistry compositeHelpers)
  {
    this.compositeHelpers = compositeHelpers;
  }
  
  CompositeResolveHelperRegistry getCompositeHelpers()
  {
    return compositeHelpers;
  }
  
  private void reorderGenerics()
  {
    for (Iterator localIterator = resolverGenerics.values().iterator(); localIterator.hasNext();)
    {
      VersionHashMap<GenericCapability> namespace = (VersionHashMap)localIterator.next();
      namespace.reorder();
    }
  }
  
  void removeGenerics(GenericCapability[] generics)
  {
    GenericCapability[] arrayOfGenericCapability;
    int j = (arrayOfGenericCapability = generics).length;
    for (int i = 0; i < j; i++)
    {
      GenericCapability capability = arrayOfGenericCapability[i];
      VersionHashMap<GenericCapability> namespace = (VersionHashMap)resolverGenerics.get(capability.getGenericDescription().getType());
      if (namespace != null) {
        namespace.remove(capability);
      }
    }
  }
  
  void addGenerics(GenericCapability[] generics)
  {
    GenericCapability[] arrayOfGenericCapability;
    int j = (arrayOfGenericCapability = generics).length;
    for (int i = 0; i < j; i++)
    {
      GenericCapability capability = arrayOfGenericCapability[i];
      if (capability.isEffective())
      {
        String type = capability.getGenericDescription().getType();
        VersionHashMap<GenericCapability> namespace = (VersionHashMap)resolverGenerics.get(type);
        if (namespace == null)
        {
          namespace = new VersionHashMap(this);
          resolverGenerics.put(type, namespace);
        }
        namespace.put(capability.getName(), capability);
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.module.ResolverImpl
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.module;

import org.eclipse.osgi.service.resolver.ImportPackageSpecification;

public class ResolverImport
  extends ResolverConstraint
{
  private String name;
  
  ResolverImport(ResolverBundle bundle, ImportPackageSpecification ips)
  {
    super(bundle, ips);
  }
  
  boolean isOptional()
  {
    return "optional".equals(((ImportPackageSpecification)constraint).getDirective("resolution"));
  }
  
  boolean isDynamic()
  {
    return "dynamic".equals(((ImportPackageSpecification)constraint).getDirective("resolution"));
  }
  
  public String getName()
  {
    if (name != null) {
      return name;
    }
    return super.getName();
  }
  
  void setName(String requestedPackage)
  {
    name = requestedPackage;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.module.ResolverImport
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.module;

import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.State;
import org.osgi.framework.Version;

public class VersionHashMap<V extends VersionSupplier>
  extends MappedList<String, V>
  implements Comparator<V>
{
  private final ResolverImpl resolver;
  private final boolean preferSystemPackages;
  
  public VersionHashMap(ResolverImpl resolver)
  {
    this.resolver = resolver;
    Dictionary[] allProperties = resolver.getState().getPlatformProperties();
    Object preferSystem = allProperties.length == 0 ? "true" : allProperties[0].get("osgi.resolver.preferSystemPackages");
    if (preferSystem == null) {
      preferSystem = "true";
    }
    preferSystemPackages = Boolean.valueOf(preferSystem.toString()).booleanValue();
  }
  
  protected int insertionIndex(List<V> existing, V value)
  {
    int index = existing.size();
    if (compare((VersionSupplier)existing.get(existing.size() - 1), value) > 0)
    {
      index = Collections.binarySearch(existing, value, this);
      if (index < 0) {
        index = -index - 1;
      }
    }
    return index;
  }
  
  public void put(V[] versionSuppliers)
  {
    for (int i = 0; i < versionSuppliers.length; i++) {
      put(versionSuppliers[i].getName(), versionSuppliers[i]);
    }
  }
  
  public boolean contains(V vs)
  {
    return contains(vs, false) != null;
  }
  
  private V contains(V vs, boolean remove)
  {
    List<V> existing = (List)internal.get(vs.getName());
    if (existing == null) {
      return null;
    }
    int index = existing.indexOf(vs);
    if (index >= 0)
    {
      if (remove)
      {
        existing.remove(index);
        if (existing.size() == 0) {
          internal.remove(vs.getName());
        }
      }
      return vs;
    }
    return null;
  }
  
  public V remove(V toBeRemoved)
  {
    return contains(toBeRemoved, true);
  }
  
  public void remove(V[] versionSuppliers)
  {
    for (int i = 0; i < versionSuppliers.length; i++) {
      remove(versionSuppliers[i]);
    }
  }
  
  void reorder()
  {
    for (Iterator<List<V>> it = internal.values().iterator(); it.hasNext();)
    {
      List<V> existing = (List)it.next();
      if (existing.size() > 1) {
        Collections.sort(existing, this);
      }
    }
  }
  
  public int compare(V vs1, V vs2)
  {
    if (resolver.getSelectionPolicy() != null) {
      return resolver.getSelectionPolicy().compare(vs1.getBaseDescription(), vs2.getBaseDescription());
    }
    if (preferSystemPackages)
    {
      String systemBundle = resolver.getSystemBundle();
      if ((systemBundle.equals(vs1.getBundleDescription().getSymbolicName())) && (!systemBundle.equals(vs2.getBundleDescription().getSymbolicName()))) {
        return -1;
      }
      if ((!systemBundle.equals(vs1.getBundleDescription().getSymbolicName())) && (systemBundle.equals(vs2.getBundleDescription().getSymbolicName()))) {
        return 1;
      }
    }
    if (vs1.getBundleDescription().isResolved() != vs2.getBundleDescription().isResolved()) {
      return vs1.getBundleDescription().isResolved() ? -1 : 1;
    }
    int versionCompare = -vs1.getVersion().compareTo(vs2.getVersion());
    if (versionCompare != 0) {
      return versionCompare;
    }
    return vs1.getBundleDescription().getBundleId() <= vs2.getBundleDescription().getBundleId() ? -1 : 1;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.module.VersionHashMap
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.module;

import org.eclipse.osgi.service.resolver.BaseDescription;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.osgi.framework.Version;
import org.osgi.framework.wiring.BundleCapability;

public abstract class VersionSupplier
{
  protected final BaseDescription base;
  private final BundleCapability capability;
  private VersionSupplier substitute;
  
  VersionSupplier(BaseDescription base)
  {
    this.base = base;
    capability = base.getCapability();
  }
  
  public Version getVersion()
  {
    return base.getVersion();
  }
  
  public String getName()
  {
    return base.getName();
  }
  
  public BaseDescription getBaseDescription()
  {
    return base;
  }
  
  VersionSupplier getSubstitute()
  {
    return substitute;
  }
  
  void setSubstitute(VersionSupplier substitute)
  {
    this.substitute = substitute;
  }
  
  public abstract BundleDescription getBundleDescription();
  
  abstract ResolverBundle getResolverBundle();
  
  public String toString()
  {
    return base.toString();
  }
  
  BundleCapability getCapability()
  {
    return capability;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.module.VersionSupplier
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.permadmin;

import java.security.Permission;
import java.util.Enumeration;
import java.util.NoSuchElementException;

class BundlePermissions$1
  implements Enumeration<Permission>
{
  public boolean hasMoreElements()
  {
    return false;
  }
  
  public Permission nextElement()
  {
    throw new NoSuchElementException();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.permadmin.BundlePermissions.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.permadmin;

import java.security.Permission;
import java.security.PermissionCollection;
import java.util.Enumeration;
import java.util.NoSuchElementException;
import org.osgi.framework.Bundle;

public final class BundlePermissions
  extends PermissionCollection
{
  private static final long serialVersionUID = -5443618108312606612L;
  static final Enumeration<Permission> EMPTY_ENUMERATION = new Enumeration()
  {
    public boolean hasMoreElements()
    {
      return false;
    }
    
    public Permission nextElement()
    {
      throw new NoSuchElementException();
    }
  };
  private final Bundle bundle;
  private final SecurityAdmin securityAdmin;
  private final PermissionInfoCollection impliedPermissions;
  private final PermissionInfoCollection restrictedPermissions;
  
  public BundlePermissions(Bundle bundle, SecurityAdmin securityAdmin, PermissionInfoCollection impliedPermissions, PermissionInfoCollection restrictedPermissions)
  {
    this.bundle = bundle;
    this.securityAdmin = securityAdmin;
    this.impliedPermissions = impliedPermissions;
    this.restrictedPermissions = restrictedPermissions;
    setReadOnly();
  }
  
  public void add(Permission permission)
  {
    throw new SecurityException();
  }
  
  public Enumeration<Permission> elements()
  {
    return EMPTY_ENUMERATION;
  }
  
  public boolean implies(Permission permission)
  {
    if ((impliedPermissions != null) && (impliedPermissions.implies(permission))) {
      return true;
    }
    if ((restrictedPermissions != null) && (!restrictedPermissions.implies(permission))) {
      return false;
    }
    return securityAdmin.checkPermission(permission, this);
  }
  
  public Bundle getBundle()
  {
    return bundle;
  }
  
  void clearPermissionCache()
  {
    if (impliedPermissions != null) {
      impliedPermissions.clearPermissionCache();
    }
    if (restrictedPermissions != null) {
      restrictedPermissions.clearPermissionCache();
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.permadmin.BundlePermissions
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.permadmin;

import java.security.AccessControlContext;
import java.util.ArrayList;
import java.util.List;

class EquinoxSecurityManager$CheckContext
{
  List<List<SecurityRow.Decision[]>> depthCondSets = new ArrayList(2);
  List<AccessControlContext> accs = new ArrayList(2);
  List<Class<?>> CondClassSet;
  
  public int getDepth()
  {
    return depthCondSets.size() - 1;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.permadmin.EquinoxSecurityManager.CheckContext
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.permadmin;

import java.security.Permission;
import java.security.PrivilegedAction;

class EquinoxSecurityManager$CheckPermissionAction
  implements PrivilegedAction<Object>
{
  Permission perm;
  Object context;
  EquinoxSecurityManager fsm;
  
  EquinoxSecurityManager$CheckPermissionAction(EquinoxSecurityManager fsm, Permission perm, Object context)
  {
    this.fsm = fsm;
    this.perm = perm;
    this.context = context;
  }
  
  public Object run()
  {
    fsm.internalCheckPermission(perm, context);
    return null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.permadmin.EquinoxSecurityManager.CheckPermissionAction
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.permadmin;

import java.security.AccessContr
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd