org.eclipse.osgi_3.8.2.v20130124-134944

.eclipse.osgi.service.resolver.GenericDescription;
import org.eclipse.osgi.util.ManifestElement;

public class GenericCapability
  extends VersionSupplier
{
  final ResolverBundle resolverBundle;
  final String[] uses;
  final boolean effective;
  
  GenericCapability(ResolverBundle resolverBundle, GenericDescription base)
  {
    super(base);
    this.resolverBundle = resolverBundle;
    String usesDirective = (String)base.getDeclaredDirectives().get("uses");
    uses = ManifestElement.getArrayFromList(usesDirective);
    String effectiveDirective = (String)base.getDeclaredDirectives().get("effective");
    effective = ((effectiveDirective == null) || ("resolve".equals(effectiveDirective)));
  }
  
  public BundleDescription getBundleDescription()
  {
    return getBaseDescription().getSupplier();
  }
  
  GenericDescription getGenericDescription()
  {
    return (GenericDescription)getBaseDescription();
  }
  
  public ResolverBundle getResolverBundle()
  {
    return resolverBundle;
  }
  
  String[] getUsesDirective()
  {
    return uses;
  }
  
  boolean isEffective()
  {
    return effective;
  }
}

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

import java.util.Map;
import org.eclipse.osgi.service.resolver.GenericSpecification;
import org.osgi.framework.wiring.BundleRequirement;

public class GenericConstraint
  extends ResolverConstraint
{
  private final boolean effective;
  private boolean supplierHasUses;
  
  GenericConstraint(ResolverBundle bundle, GenericSpecification constraint)
  {
    super(bundle, constraint);
    String effectiveDirective = (String)constraint.getRequirement().getDirectives().get("effective");
    effective = ((effectiveDirective == null) || ("resolve".equals(effectiveDirective)));
  }
  
  boolean isOptional()
  {
    return (((GenericSpecification)constraint).getResolution() & 0x1) != 0;
  }
  
  boolean isFromRequiredEE()
  {
    return (((GenericSpecification)constraint).getResolution() & 0x4) != 0;
  }
  
  boolean isMultiple()
  {
    return (!supplierHasUses) && ((((GenericSpecification)constraint).getResolution() & 0x2) != 0);
  }
  
  boolean isEffective()
  {
    return effective;
  }
  
  public String getNameSpace()
  {
    return ((GenericSpecification)getVersionConstraint()).getType();
  }
  
  public VersionSupplier[] getMatchingCapabilities()
  {
    if (isMultiple()) {
      return getPossibleSuppliers();
    }
    VersionSupplier supplier = getSelectedSupplier();
    return new VersionSupplier[] { supplier == null ? null : supplier };
  }
  
  void addPossibleSupplier(VersionSupplier supplier)
  {
    supplierHasUses |= ((GenericCapability)supplier).getUsesDirective() != null;
    super.addPossibleSupplier(supplier);
  }
  
  void clearPossibleSuppliers()
  {
    super.clearPossibleSuppliers();
    supplierHasUses = false;
  }
  
  boolean supplierHasUses()
  {
    return supplierHasUses;
  }
}

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

import java.util.ArrayList;
import java.util.List;

class GroupingChecker$PackageRoots
{
  private String name;
  private ResolverExport[] roots;
  final GroupingChecker this$0;
  
  GroupingChecker$PackageRoots(GroupingChecker paramGroupingChecker, String name)
  {
    this.name = name;
  }
  
  public boolean hasRoots()
  {
    return (roots != null) && (roots.length > 0);
  }
  
  public void addRoot(ResolverExport export)
  {
    if (roots == null)
    {
      roots = new ResolverExport[] { export };
      return;
    }
    String exportBSN = export.getExporter().getName();
    if (exportBSN != null) {
      for (int i = 0; i < roots.length; i++) {
        if ((export.getExporter() != roots[i].getExporter()) && (exportBSN.equals(roots[i].getExporter().getName()))) {
          return;
        }
      }
    }
    if (!contains(export, roots))
    {
      ResolverExport[] newRoots = new ResolverExport[roots.length + 1];
      System.arraycopy(roots, 0, newRoots, 0, roots.length);
      newRoots[roots.length] = export;
      roots = newRoots;
    }
  }
  
  private boolean contains(ResolverExport export, ResolverExport[] exports)
  {
    for (int i = 0; i < exports.length; i++) {
      if (exports[i] == export) {
        return true;
      }
    }
    return false;
  }
  
  public void merge(PackageRoots packageRoots)
  {
    if ((packageRoots == null) || (roots == null)) {
      return;
    }
    int size = roots.length;
    for (int i = 0; i < size; i++) {
      addRoot(roots[i]);
    }
  }
  
  public List<PackageRoots[]> isConsistentClassSpace(ResolverBundle importingBundle, List<PackageRoots> visited, List<PackageRoots[]> results)
  {
    if (roots == null) {
      return results;
    }
    if (visited == null) {
      visited = new ArrayList(1);
    }
    if (visited.contains(this)) {
      return results;
    }
    visited.add(this);
    int size = roots.length;
    for (int i = 0; i < size; i++)
    {
      ResolverExport root = roots[i];
      String[] uses = root.getUsesDirective();
      if (uses != null) {
        for (int j = 0; j < uses.length; j++) {
          if (!uses[j].equals(root.getName()))
          {
            PackageRoots thisUsedRoots = this$0.getPackageRoots(root.getExporter(), uses[j], null);
            PackageRoots importingUsedRoots = this$0.getPackageRoots(importingBundle, uses[j], null);
            if (thisUsedRoots != importingUsedRoots)
            {
              if ((thisUsedRoots != this$0.nullPackageRoots) && (importingUsedRoots != this$0.nullPackageRoots) && 
                (!subSet(roots, roots)) && (!subSet(roots, roots)))
              {
                if (results == null) {
                  results = new ArrayList(1);
                }
                results.add(new PackageRoots[] { this, importingUsedRoots });
              }
              results = thisUsedRoots.isConsistentClassSpace(importingBundle, visited, results);
            }
          }
        }
      }
    }
    return results;
  }
  
  public List<PackageRoots[]> isConsistentClassSpace(PackageRoots exportingRoots, ResolverBundle exporter, List<PackageRoots> visited, List<PackageRoots[]> results)
  {
    if (roots == null) {
      return results;
    }
    int size = roots.length;
    for (int i = 0; i < size; i++)
    {
      ResolverExport root = roots[i];
      String[] uses = root.getUsesDirective();
      if (uses != null)
      {
        if (visited == null) {
          visited = new ArrayList(1);
        }
        if (visited.contains(this)) {
          return results;
        }
        visited.add(this);
        for (int j = 0; j < uses.length; j++) {
          if ((!uses[j].equals(root.getName())) && (uses[j].equals(name)))
          {
            PackageRoots thisUsedRoots = this$0.getPackageRoots(root.getExporter(), uses[j], null);
            PackageRoots exportingUsedRoots = this$0.getPackageRoots(exporter, uses[j], null);
            if (thisUsedRoots == exportingRoots) {
              return results;
            }
            if ((thisUsedRoots != this$0.nullPackageRoots) && (exportingUsedRoots != this$0.nullPackageRoots) && 
              (!subSet(roots, roots)) && (!subSet(roots, roots)))
            {
              if (results == null) {
                results = new ArrayList(1);
              }
              results.add(new PackageRoots[] { this, exportingUsedRoots });
            }
            results = thisUsedRoots.isConsistentClassSpace(exportingRoots, exporter, visited, results);
          }
        }
      }
    }
    return results;
  }
  
  List<PackageRoots[]> addConflicts(ResolverBundle bundle, String usedPackage, List<PackageRoots> visited, List<PackageRoots[]> results)
  {
    PackageRoots bundleUsedRoots = this$0.getPackageRoots(bundle, usedPackage, null);
    if (this == bundleUsedRoots) {
      return results;
    }
    if ((this != this$0.nullPackageRoots) && (bundleUsedRoots != this$0.nullPackageRoots) && 
      (!subSet(roots, roots)) && (!subSet(roots, roots)))
    {
      if (results == null) {
        results = new ArrayList(1);
      }
      results.add(new PackageRoots[] { this, bundleUsedRoots });
    }
    return isConsistentClassSpace(bundleUsedRoots, bundle, visited, results);
  }
  
  private boolean subSet(ResolverExport[] superSet, ResolverExport[] subSet)
  {
    for (int i = 0; i < subSet.length; i++)
    {
      boolean found = false;
      for (int j = 0; j < superSet.length; j++) {
        if (subSet[i].getExporter() == superSet[j].getExporter())
        {
          found = true;
          break;
        }
      }
      if (!found) {
        return false;
      }
    }
    return true;
  }
  
  public boolean superSet(PackageRoots subSet)
  {
    return subSet(roots, roots);
  }
  
  public String getName()
  {
    return name;
  }
  
  public ResolverExport[] getRoots()
  {
    return roots;
  }
}

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

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.BundleSpecification;
import org.eclipse.osgi.service.resolver.ExportPackageDescription;

public class GroupingChecker
{
  final PackageRoots nullPackageRoots = new PackageRoots(null);
  private Map<ResolverBundle, Map<String, PackageRoots>> bundles = new HashMap();
  
  public void populateRoots(ResolverBundle bundle)
  {
    if (bundles.containsKey(bundle)) {
      return;
    }
    BundleConstraint[] requires = bundle.getRequires();
    for (int j = 0; j < requires.length; j++)
    {
      ResolverBundle selectedSupplier = (ResolverBundle)requires[j].getSelectedSupplier();
      if (selectedSupplier != null) {
        isConsistentInternal(bundle, selectedSupplier, new ArrayList(1), true, null);
      }
    }
    ExportPackageDescription[] imports = bundle.getBundleDescription().getResolvedImports();
    ExportPackageDescription[] arrayOfExportPackageDescription1;
    int j = (arrayOfExportPackageDescription1 = imports).length;
    for (int i = 0; i < j; i++)
    {
      ExportPackageDescription importPkg = arrayOfExportPackageDescription1[i];
      List<ResolverExport> exports = bundle.getResolver().getResolverExports().get(importPkg.getName());
      for (Iterator localIterator = exports.iterator(); localIterator.hasNext();)
      {
        ResolverExport export = (ResolverExport)localIterator.next();
        if (export.getExportPackageDescription() == importPkg) {
          isConsistentInternal(bundle, export, true, null);
        }
      }
    }
  }
  
  public void populateRoots(ResolverBundle importingBundle, ResolverExport export)
  {
    Map<String, PackageRoots> packageRoots = (Map)bundles.get(importingBundle);
    if (packageRoots != null) {
      packageRoots.remove(export.getName());
    }
    PackageRoots roots = getPackageRoots(export.getExporter(), export.getName(), null);
    packageRoots.put(export.getName(), roots);
  }
  
  public PackageRoots[][] isConsistent(ResolverBundle requiringBundle, ResolverBundle matchingBundle)
  {
    List<PackageRoots[]> results = isConsistentInternal(requiringBundle, matchingBundle, new ArrayList(1), false, null);
    return results == null ? null : (PackageRoots[][])results.toArray(new PackageRoots[results.size()][]);
  }
  
  private List<PackageRoots[]> isConsistentInternal(ResolverBundle requiringBundle, ResolverBundle matchingBundle, List<ResolverBundle> visited, boolean dynamicImport, List<PackageRoots[]> results)
  {
    if (visited.contains(matchingBundle)) {
      return results;
    }
    visited.add(matchingBundle);
    
    ResolverExport[] matchingExports = matchingBundle.getExportPackages();
    for (int i = 0; i < matchingExports.length; i++)
    {
      ResolverExport matchingExport = matchingExports[i];
      if (matchingExports[i].getSubstitute() != null) {
        matchingExport = (ResolverExport)matchingExports[i].getSubstitute();
      }
      results = isConsistentInternal(requiringBundle, matchingExport, dynamicImport, results);
    }
    BundleConstraint[] supplierRequires = matchingBundle.getRequires();
    for (int j = 0; j < supplierRequires.length; j++)
    {
      ResolverBundle reexported = (ResolverBundle)supplierRequires[j].getSelectedSupplier();
      if ((reexported != null) && (((BundleSpecification)supplierRequires[j].getVersionConstraint()).isExported())) {
        results = isConsistentInternal(requiringBundle, reexported, visited, dynamicImport, results);
      }
    }
    return results;
  }
  
  public PackageRoots[][] isConsistent(ResolverBundle importingBundle, ResolverExport matchingExport)
  {
    List<PackageRoots[]> results = isConsistentInternal(importingBundle, matchingExport, false, null);
    return results == null ? null : (PackageRoots[][])results.toArray(new PackageRoots[results.size()][]);
  }
  
  public PackageRoots[][] isConsistent(ResolverBundle requiringBundle, GenericCapability matchingCapability)
  {
    String[] uses = matchingCapability.getUsesDirective();
    if (uses == null) {
      return null;
    }
    ArrayList<PackageRoots[]> results = new ArrayList(0);
    String[] arrayOfString1;
    int j = (arrayOfString1 = uses).length;
    for (int i = 0; i < j; i++)
    {
      String usedPackage = arrayOfString1[i];
      PackageRoots providingRoots = getPackageRoots(matchingCapability.getResolverBundle(), usedPackage, null);
      providingRoots.addConflicts(requiringBundle, usedPackage, null, results);
    }
    return results.size() == 0 ? null : (PackageRoots[][])results.toArray(new PackageRoots[results.size()][]);
  }
  
  public PackageRoots[][] isDynamicConsistent(ResolverBundle importingBundle, ResolverExport matchingExport)
  {
    List<PackageRoots[]> results = isConsistentInternal(importingBundle, matchingExport, true, null);
    return results == null ? null : (PackageRoots[][])results.toArray(new PackageRoots[results.size()][]);
  }
  
  private List<PackageRoots[]> isConsistentInternal(ResolverBundle importingBundle, ResolverExport matchingExport, boolean dyanamicImport, List<PackageRoots[]> results)
  {
    PackageRoots exportingRoots = getPackageRoots(matchingExport.getExporter(), matchingExport.getName(), null);
    
    results = exportingRoots.isConsistentClassSpace(importingBundle, null, results);
    if (!dyanamicImport) {
      return results;
    }
    PackageRoots importingRoots = getPackageRoots(importingBundle, matchingExport.getName(), null);
    Map<String, PackageRoots> importingPackages = (Map)bundles.get(importingBundle);
    if (importingPackages != null) {
      for (Iterator<PackageRoots> allImportingPackages = importingPackages.values().iterator(); allImportingPackages.hasNext();)
      {
        PackageRoots roots = (PackageRoots)allImportingPackages.next();
        if (roots != importingRoots) {
          results = roots.isConsistentClassSpace(exportingRoots, matchingExport.getExporter(), null, results);
        }
      }
    }
    GenericConstraint[] genericRequires = importingBundle.getGenericRequires();
    GenericConstraint[] arrayOfGenericConstraint1;
    int j = (arrayOfGenericConstraint1 = genericRequires).length;
    for (int i = 0; i < j; i++)
    {
      GenericConstraint constraint = arrayOfGenericConstraint1[i];
      if (constraint.supplierHasUses())
      {
        GenericCapability supplier = (GenericCapability)constraint.getSelectedSupplier();
        String[] uses = supplier.getUsesDirective();
        if (uses != null)
        {
          String[] arrayOfString1;
          int m = (arrayOfString1 = uses).length;
          for (int k = 0; k < m; k++)
          {
            String usedPackage = arrayOfString1[k];
            if (usedPackage.equals(matchingExport.getName())) {
              results = exportingRoots.addConflicts(supplier.getResolverBundle(), usedPackage, null, results);
            }
          }
        }
      }
    }
    return results;
  }
  
  PackageRoots getPackageRoots(ResolverBundle bundle, String packageName, List<ResolverBundle> visited)
  {
    Map<String, PackageRoots> packages = (Map)bundles.get(bundle);
    if (packages == null)
    {
      packages = new HashMap(5);
      bundles.put(bundle, packages);
    }
    PackageRoots packageRoots = (PackageRoots)packages.get(packageName);
    if (packageRoots == null)
    {
      packageRoots = createPackageRoots(bundle, packageName, visited == null ? new ArrayList(1) : visited);
      packages.put(packageName, packageRoots);
    }
    return packageRoots != null ? packageRoots : nullPackageRoots;
  }
  
  private PackageRoots createPackageRoots(ResolverBundle bundle, String packageName, List<ResolverBundle> visited)
  {
    if (visited.contains(bundle)) {
      return null;
    }
    visited.add(bundle);
    if (bundle.getBundleDescription().isResolved())
    {
      ExportPackageDescription[] imports = bundle.getBundleDescription().getResolvedImports();
      ExportPackageDescription[] arrayOfExportPackageDescription1;
      int j = (arrayOfExportPackageDescription1 = imports).length;
      for (int i = 0; i < j; i++)
      {
        ExportPackageDescription importPkg = arrayOfExportPackageDescription1[i];
        if ((importPkg.getExporter() != bundle.getBundleDescription()) && (importPkg.getName().equals(packageName)))
        {
          List<ResolverExport> exports = bundle.getResolver().getResolverExports().get(packageName);
          for (Iterator localIterator = exports.iterator(); localIterator.hasNext();)
          {
            ResolverExport export = (ResolverExport)localIterator.next();
            if (export.getExportPackageDescription() == importPkg) {
              return getPackageRoots(export.getExporter(), packageName, visited);
            }
          }
        }
      }
    }
    else
    {
      ResolverImport imported = bundle.getImport(packageName);
      if ((imported != null) && (imported.getSelectedSupplier() != null))
      {
        ResolverExport selectedExport = (ResolverExport)imported.getSelectedSupplier();
        if (selectedExport.getExporter() != bundle) {
          return getPackageRoots(selectedExport.getExporter(), packageName, visited);
        }
      }
    }
    ResolverExport[] exports = bundle.getExports(packageName);
    List<PackageRoots> roots = new ArrayList(0);
    
    BundleConstraint[] requires = bundle.getRequires();
    for (int i = 0; i < requires.length; i++)
    {
      ResolverBundle supplier = (ResolverBundle)requires[i].getSelectedSupplier();
      if (supplier != null) {
        if (supplier.getExport(packageName) != null)
        {
          PackageRoots requiredRoots = getPackageRoots(supplier, packageName, visited);
          if (requiredRoots != nullPackageRoots) {
            roots.add(requiredRoots);
          }
        }
        else
        {
          BundleConstraint[] supplierRequires = supplier.getRequires();
          for (int j = 0; j < supplierRequires.length; j++)
          {
            ResolverBundle reexported = (ResolverBundle)supplierRequires[j].getSelectedSupplier();
            if ((reexported != null) && (((BundleSpecification)supplierRequires[j].getVersionConstraint()).isExported())) {
              if (reexported.getExport(packageName) != null)
              {
                PackageRoots reExportedRoots = getPackageRoots(reexported, packageName, visited);
                if (reExportedRoots != nullPackageRoots) {
                  roots.add(reExportedRoots);
                }
              }
            }
          }
        }
      }
    }
    if ((exports.length > 0) || (roots.size() > 1))
    {
      PackageRoots[] requiredRoots = (PackageRoots[])roots.toArray(new PackageRoots[roots.size()]);
      if (exports.length == 0)
      {
        PackageRoots superSet = requiredRoots[0];
        for (int i = 1; i < requiredRoots.length; i++) {
          if (requiredRoots[i].superSet(superSet))
          {
            superSet = requiredRoots[i];
          }
          else if (!superSet.superSet(requiredRoots[i]))
          {
            superSet = null;
            break;
          }
        }
        if (superSet != null) {
          return superSet;
        }
      }
      PackageRoots result = new PackageRoots(packageName);
      for (int i = 0; i < requiredRoots.length; i++) {
        result.merge(requiredRoots[i]);
      }
      for (int i = 0; i < exports.length; i++) {
        result.addRoot(exports[i]);
      }
      return result;
    }
    return roots.size() == 0 ? nullPackageRoots : (PackageRoots)roots.get(0);
  }
  
  public void clear()
  {
    bundles.clear();
  }
  
  public void clear(ResolverBundle rb)
  {
    bundles.remove(rb);
  }
  
  class PackageRoots
  {
    private String name;
    private ResolverExport[] roots;
    
    PackageRoots(String name)
    {
      this.name = name;
    }
    
    public boolean hasRoots()
    {
      return (roots != null) && (roots.length > 0);
    }
    
    public void addRoot(ResolverExport export)
    {
      if (roots == null)
      {
        roots = new ResolverExport[] { export };
        return;
      }
      String exportBSN = export.getExporter().getName();
      if (exportBSN != null) {
        for (int i = 0; i < roots.length; i++) {
          if ((export.getExporter() != roots[i].getExporter()) && (exportBSN.equals(roots[i].getExporter().getName()))) {
            return;
          }
        }
      }
      if (!contains(export, roots))
      {
        ResolverExport[] newRoots = new ResolverExport[roots.length + 1];
        System.arraycopy(roots, 0, newRoots, 0, roots.length);
        newRoots[roots.length] = export;
        roots = newRoots;
      }
    }
    
    private boolean contains(ResolverExport export, ResolverExport[] exports)
    {
      for (int i = 0; i < exports.length; i++) {
        if (exports[i] == export) {
          return true;
        }
      }
      return false;
    }
    
    public void merge(PackageRoots packageRoots)
    {
      if ((packageRoots == null) || (roots == null)) {
        return;
      }
      int size = roots.length;
      for (int i = 0; i < size; i++) {
        addRoot(roots[i]);
      }
    }
    
    public List<PackageRoots[]> isConsistentClassSpace(ResolverBundle importingBundle, List<PackageRoots> visited, List<PackageRoots[]> results)
    {
      if (roots == null) {
        return results;
      }
      if (visited == null) {
        visited = new ArrayList(1);
      }
      if (visited.contains(this)) {
        return results;
      }
      visited.add(this);
      int size = roots.length;
      for (int i = 0; i < size; i++)
      {
        ResolverExport root = roots[i];
        String[] uses = root.getUsesDirective();
        if (uses != null) {
          for (int j = 0; j < uses.length; j++) {
            if (!uses[j].equals(root.getName()))
            {
              PackageRoots thisUsedRoots = getPackageRoots(root.getExporter(), uses[j], null);
              PackageRoots importingUsedRoots = getPackageRoots(importingBundle, uses[j], null);
              if (thisUsedRoots != importingUsedRoots)
              {
                if ((thisUsedRoots != nullPackageRoots) && (importingUsedRoots != nullPackageRoots) && 
                  (!subSet(roots, roots)) && (!subSet(roots, roots)))
                {
                  if (results == null) {
                    results = new ArrayList(1);
                  }
                  results.add(new PackageRoots[] { this, importingUsedRoots });
                }
                results = thisUsedRoots.isConsistentClassSpace(importingBundle, visited, results);
              }
            }
          }
        }
      }
      return results;
    }
    
    public List<PackageRoots[]> isConsistentClassSpace(PackageRoots exportingRoots, ResolverBundle exporter, List<PackageRoots> visited, List<PackageRoots[]> results)
    {
      if (roots == null) {
        return results;
      }
      int size = roots.length;
      for (int i = 0; i < size; i++)
      {
        ResolverExport root = roots[i];
        String[] uses = root.getUsesDirective();
        if (uses != null)
        {
          if (visited == null) {
            visited = new ArrayList(1);
          }
          if (visited.contains(this)) {
            return results;
          }
          visited.add(this);
          for (int j = 0; j < uses.length; j++) {
            if ((!uses[j].equals(root.getName())) && (uses[j].equals(name)))
            {
              PackageRoots thisUsedRoots = getPackageRoots(root.getExporter(), uses[j], null);
              PackageRoots exportingUsedRoots = getPackageRoots(exporter, uses[j], null);
              if (thisUsedRoots == exportingRoots) {
                return results;
              }
              if ((thisUsedRoots != nullPackageRoots) && (exportingUsedRoots != nullPackageRoots) && 
                (!subSet(roots, roots)) && (!subSet(roots, roots)))
              {
                if (results == null) {
                  results = new ArrayList(1);
                }
                results.add(new PackageRoots[] { this, exportingUsedRoots });
              }
              results = thisUsedRoots.isConsistentClassSpace(exportingRoots, exporter, visited, results);
            }
          }
        }
      }
      return results;
    }
    
    List<PackageRoots[]> addConflicts(ResolverBundle bundle, String usedPackage, List<PackageRoots> visited, List<PackageRoots[]> results)
    {
      PackageRoots bundleUsedRoots = getPackageRoots(bundle, usedPackage, null);
      if (this == bundleUsedRoots) {
        return results;
      }
      if ((this != nullPackageRoots) && (bundleUsedRoots != nullPackageRoots) && 
        (!subSet(roots, roots)) && (!subSet(roots, roots)))
      {
        if (results == null) {
          results = new ArrayList(1);
        }
        results.add(new PackageRoots[] { this, bundleUsedRoots });
      }
      return isConsistentClassSpace(bundleUsedRoots, bundle, visited, results);
    }
    
    private boolean subSet(ResolverExport[] superSet, ResolverExport[] subSet)
    {
      for (int i = 0; i < subSet.length; i++)
      {
        boolean found = false;
        for (int j = 0; j < superSet.length; j++) {
          if (subSet[i].getExporter() == superSet[j].getExporter())
          {
            found = true;
            break;
          }
        }
        if (!found) {
          return false;
        }
      }
      return true;
    }
    
    public boolean superSet(PackageRoots subSet)
    {
      return subSet(roots, roots);
    }
    
    public String getName()
    {
      return name;
    }
    
    public ResolverExport[] getRoots()
    {
      return roots;
    }
  }
}

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

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

public class MappedList<K, V>
{
  protected final HashMap<K, List<V>> internal = new HashMap();
  protected final List<V> empty = Collections.EMPTY_LIST;
  
  public void put(K key, V value)
  {
    List<V> existing = (List)internal.get(key);
    if (existing == null)
    {
      existing = new ArrayList(1);
      existing.add(value);
      internal.put(key, existing);
      return;
    }
    int index = insertionIndex(existing, value);
    existing.add(index, value);
  }
  
  protected int insertionIndex(List<V> existing, V value)
  {
    return existing.size();
  }
  
  public List<V> remove(K key)
  {
    return get(key, true);
  }
  
  public List<V> get(K key)
  {
    return get(key, false);
  }
  
  private List<V> get(K key, boolean remove)
  {
    List<V> result = remove ? (List)internal.remove(key) : (List)internal.get(key);
    return result == null ? empty : result;
  }
  
  public int getSize()
  {
    return internal.size();
  }
  
  public List<V> getAllValues()
  {
    if (getSize() == 0) {
      return empty;
    }
    ArrayList<V> results = new ArrayList(getSize());
    Iterator<List<V>> iter = internal.values().iterator();
    while (iter.hasNext()) {
      results.addAll((Collection)iter.next());
    }
    return results;
  }
  
  public void clear()
  {
    internal.clear();
  }
}

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

import java.security.Permission;
import org.eclipse.osgi.service.resolver.BaseDescription;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.BundleSpecification;
import org.eclipse.osgi.service.resolver.ExportPackageDescription;
import org.eclipse.osgi.service.resolver.GenericDescription;
import org.eclipse.osgi.service.resolver.GenericSpecification;
import org.eclipse.osgi.service.resolver.HostSpecification;
import org.eclipse.osgi.service.resolver.ImportPackageSpecification;
import org.eclipse.osgi.service.resolver.State;
import org.eclipse.osgi.service.resolver.VersionConstraint;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundlePermission;
import org.osgi.framework.CapabilityPermission;
import org.osgi.framework.PackagePermission;

public class PermissionChecker
{
  private boolean checkPermissions = false;
  private ResolverImpl resolver;
  
  public PermissionChecker(boolean checkPermissions, ResolverImpl resolver)
  {
    this.checkPermissions = checkPermissions;
    this.resolver = resolver;
  }
  
  public boolean checkPermission(VersionConstraint vc, BaseDescription bd)
  {
    if (!checkPermissions) {
      return true;
    }
    boolean success = false;
    Permission producerPermission = null;Permission consumerPermission = null;
    Bundle consumer = null;
    Bundle producer = bd.getSupplier().getBundle();
    int errorType = 0;
    if ((vc instanceof ImportPackageSpecification))
    {
      errorType = 128;
      producerPermission = new PackagePermission(bd.getName(), "exportonly");
      consumerPermission = producer != null ? new PackagePermission(vc.getName(), producer, "import") : new PackagePermission(vc.getName(), "import");
    }
    else if (((vc instanceof BundleSpecification)) || ((vc instanceof HostSpecification)))
    {
      boolean requireBundle = vc instanceof BundleSpecification;
      errorType = requireBundle ? 512 : 4096;
      producerPermission = new BundlePermission(bd.getName(), requireBundle ? "provide" : "host");
      consumerPermission = new BundlePermission(vc.getName(), requireBundle ? "require" : "fragment");
    }
    else if ((vc instanceof GenericSpecification))
    {
      errorType = 524288;
      GenericDescription gd = (GenericDescription)bd;
      producerPermission = new CapabilityPermission(gd.getType(), "provide");
      consumerPermission = new CapabilityPermission(gd.getType(), gd.getDeclaredAttributes(), producer, "require");
    }
    consumer = vc.getBundle().getBundle();
    if ((producer != null) && ((producer.getState() & 0x1) == 0))
    {
      success = producer.hasPermission(producerPermission);
      if (!success)
      {
        switch (errorType)
        {
        case 128: 
          errorType = 256;
          break;
        case 512: 
        case 4096: 
          errorType = errorType == 512 ? 1024 : 2048;
          break;
        case 524288: 
          errorType = 1024;
        }
        resolver.getState().addResolverError(vc.getBundle(), errorType, producerPermission.toString(), vc);
      }
    }
    if ((success) && (consumer != null) && ((consumer.getState() & 0x1) == 0))
    {
      success = consumer.hasPermission(consumerPermission);
      if (!success) {
        resolver.getState().addResolverError(vc.getBundle(), errorType, consumerPermission.toString(), vc);
      }
    }
    return success;
  }
  
  boolean checkPackagePermission(ExportPackageDescription export)
  {
    if (!checkPermissions) {
      return true;
    }
    export.getSupplier().getBundle();
    Bundle bundle = export.getSupplier().getBundle();
    return bundle == null ? false : bundle.hasPermission(new PackagePermission(export.getName(), "exportonly"));
  }
  
  boolean checkCapabilityPermission(GenericDescription capability)
  {
    if (!checkPermissions) {
      return true;
    }
    Bundle bundle = capability.getSupplier().getBundle();
    return bundle == null ? false : bundle.hasPermission(new CapabilityPermission(capability.getType(), "provide"));
  }
}

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

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.eclipse.osgi.internal.resolver.ExportPackageDescriptionImpl;
import org.eclipse.osgi.internal.resolver.GenericDescriptionImpl;
import org.eclipse.osgi.internal.resolver.ImportPackageSpecificationImpl;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.BundleSpecification;
import org.eclipse.osgi.service.resolver.ExportPackageDescription;
import org.eclipse.osgi.service.resolver.GenericDescription;
import org.eclipse.osgi.service.resolver.GenericSpecification;
import org.eclipse.osgi.service.resolver.HostSpecification;
import org.eclipse.osgi.service.resolver.ImportPackageSpecification;
import org.eclipse.osgi.service.resolver.State;
import org.eclipse.osgi.service.resolver.VersionConstraint;
import org.osgi.framework.Version;

public class ResolverBundle
  extends VersionSupplier
  implements Comparable<ResolverBundle>
{
  public static final int UNRESOLVED = 0;
  public static final int RESOLVING = 1;
  public static final int RESOLVED = 2;
  private final Long bundleID;
  private BundleConstraint host;
  private ResolverImport[] imports;
  private ResolverExport[] exports;
  private BundleConstraint[] requires;
  private GenericCapability[] genericCapabilities;
  private GenericConstraint[] genericReqiures;
  private ArrayList<ResolverBundle> fragments;
  private HashMap<Long, List<ResolverExport>> fragmentExports;
  private HashMap<Long, List<ResolverImport>> fragmentImports;
  private HashMap<Long, List<BundleConstraint>> fragmentRequires;
  private HashMap<Long, List<GenericCapability>> fragmentGenericCapabilities;
  private HashMap<Long, List<GenericConstraint>> fragmentGenericRequires;
  private boolean resolvable = true;
  private int state = 0;
  private boolean uninstalled = false;
  private final ResolverImpl resolver;
  private boolean newFragmentExports;
  private boolean newFragmentCapabilities;
  
  ResolverBundle(BundleDescription bundle, ResolverImpl resolver)
  {
    super(bundle);
    bundleID = new Long(bundle.getBundleId());
    this.resolver = resolver;
    initialize(bundle.isResolved());
  }
  
  void initialize(boolean useSelectedExports)
  {
    if (getBundleDescription().getHost() != null)
    {
      host = new BundleConstraint(this, getBundleDescription().getHost());
      exports = new ResolverExport[0];
      imports = new ResolverImport[0];
      requires = new BundleConstraint[0];
      GenericSpecification[] requirements = getBundleDescription().getGenericRequires();
      List<GenericConstraint> constraints = new ArrayList();
      GenericSpecification[] arrayOfGenericSpecification1;
      int j = (arrayOfGenericSpecification1 = requirements).length;
      for (int i = 0; i < j; i++)
      {
        GenericSpecification requirement = arrayOfGenericSpecification1[i];
        if ("osgi.ee".equals(requirement.getType())) {
          constraints.add(new GenericConstraint(this, requirement));
        }
      }
      genericReqiures = ((GenericConstraint[])constraints.toArray(new GenericConstraint[constraints.size()]));
      GenericDescription[] capabilities = getBundleDescription().getGenericCapabilities();
      GenericCapability identity = null;
      GenericDescription[] arrayOfGenericDescription1;
      int m = (arrayOfGenericDescription1 = capabilities).length;
      for (int k = 0; k < m; k++)
      {
        GenericDescription capability = arrayOfGenericDescription1[k];
        if ("osgi.identity".equals(capability.getType()))
        {
          identity = new GenericCapability(this, capability);
          break;
        }
      }
      genericCapabilities = new GenericCapability[] { identity == null ? new GenericCapability[0] : identity };
      return;
    }
    ImportPackageSpecification[] actualImports = getBundleDescription().getImportPackages();
    
    List<ResolverImport> importList = new ArrayList(actualImports.length);
    for (int i = actualImports.length - 1; i >= 0; i--) {
      if ("optional".equals(actualImports[i].getDirective("resolution"))) {
        importList.add(new ResolverImport(this, actualImports[i]));
      } else {
        importList.add(0, new ResolverImport(this, actualImports[i]));
      }
    }
    imports = ((ResolverImport[])importList.toArray(new ResolverImport[importList.size()]));
    
    ExportPackageDescription[] actualExports = useSelectedExports ? getBundleDescription().getSelectedExports() : getBundleDescription().getExportPackages();
    exports = new ResolverExport[actualExports.length];
    for (int i = 0; i < actualExports.length; i++) {
      exports[i] = new ResolverExport(this, actualExports[i]);
    }
    BundleSpecification[] actualRequires = getBundleDescription().getRequiredBundles();
    requires = new BundleConstraint[actualRequires.length];
    for (int i = 0; i < requires.length; i++) {
      requires[i] = new BundleConstraint(this, actualRequires[i]);
    }
    GenericSpecification[] actualGenericRequires = getBundleDescription().getGenericRequires();
    genericReqiures = new GenericConstraint[actualGenericRequires.length];
    for (int i = 0; i < genericReqiures.length; i++) {
      genericReqiures[i] = new GenericConstraint(this, actualGenericRequires[i]);
    }
    GenericDescription[] actualCapabilities = useSelectedExports ? getBundleDescription().getSelectedGenericCapabilities() : getBundleDescription().getGenericCapabilities();
    genericCapabilities = new GenericCapability[actualCapabilities.length];
    for (int i = 0; i < genericCapabilities.length; i++) {
      genericCapabilities[i] = new GenericCapability(this, actualCapabilities[i]);
    }
    fragments = null;
    fragmentExports = null;
    fragmentImports = null;
    fragmentRequires = null;
    fragmentGenericCapabilities = null;
    fragmentGenericRequires = null;
  }
  
  ResolverExport getExport(String name)
  {
    ResolverExport[] allExports = getExports(name);
    return allExports.length == 0 ? null : allExports[0];
  }
  
  ResolverExport[] getExports(String name)
  {
    List<ResolverExport> results = new ArrayList(1);
    
    List<ResolverExport> resolverExports = resolver.getResolverExports().get(name);
    for (Iterator localIterator = resolverExports.iterator(); localIterator.hasNext();)
    {
      ResolverExport export = (ResolverExport)localIterator.next();
      if (export.getExporter() == this) {
        results.add(export);
      }
    }
    return (R
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