org.eclipse.osgi_3.8.2.v20130124-134944

esolverExport[])results.toArray(new ResolverExport[results.size()]);
  }
  
  void clearWires()
  {
    ResolverImport[] allImports = getImportPackages();
    for (int i = 0; i < allImports.length; i++) {
      allImports[i].clearPossibleSuppliers();
    }
    if (host != null) {
      host.clearPossibleSuppliers();
    }
    BundleConstraint[] allRequires = getRequires();
    for (int i = 0; i < allRequires.length; i++) {
      allRequires[i].clearPossibleSuppliers();
    }
    GenericConstraint[] allGenericRequires = getGenericRequires();
    for (int i = 0; i < allGenericRequires.length; i++) {
      allGenericRequires[i].clearPossibleSuppliers();
    }
    ResolverExport[] allExports = getExportPackages();
    for (int i = 0; i < allExports.length; i++) {
      allExports[i].setSubstitute(null);
    }
  }
  
  boolean isResolved()
  {
    return getState() == 2;
  }
  
  boolean isFragment()
  {
    return host != null;
  }
  
  int getState()
  {
    return state;
  }
  
  void setState(int state)
  {
    this.state = state;
  }
  
  private <T> List<T> getAll(T[] hostEntries, Map<Long, List<T>> fragmentMap)
  {
    List<T> result = new ArrayList(hostEntries.length);
    Object[] arrayOfObject;
    int j = (arrayOfObject = hostEntries).length;
    for (int i = 0; i < j; i++)
    {
      T entry = arrayOfObject[i];
      result.add(entry);
    }
    for (Iterator localIterator = fragments.iterator(); localIterator.hasNext();)
    {
      ResolverBundle fragment = (ResolverBundle)localIterator.next();
      Object fragEntries = (List)fragmentMap.get(bundleID);
      if (fragEntries != null) {
        result.addAll((Collection)fragEntries);
      }
    }
    return result;
  }
  
  ResolverImport[] getImportPackages()
  {
    if ((isFragment()) || (fragments == null) || (fragments.size() == 0)) {
      return imports;
    }
    List<ResolverImport> result = getAll(imports, fragmentImports);
    return (ResolverImport[])result.toArray(new ResolverImport[result.size()]);
  }
  
  ResolverExport[] getExportPackages()
  {
    if ((isFragment()) || (fragments == null) || (fragments.size() == 0)) {
      return exports;
    }
    List<ResolverExport> result = getAll(exports, fragmentExports);
    return (ResolverExport[])result.toArray(new ResolverExport[result.size()]);
  }
  
  ResolverExport[] getSelectedExports()
  {
    return getExports(true);
  }
  
  ResolverExport[] getSubstitutedExports()
  {
    return getExports(false);
  }
  
  private ResolverExport[] getExports(boolean selected)
  {
    ResolverExport[] results = getExportPackages();
    int removedExports = 0;
    for (int i = 0; i < results.length; i++) {
      if (selected ? results[i].getSubstitute() != null : results[i].getSubstitute() == null) {
        removedExports++;
      }
    }
    if (removedExports == 0) {
      return results;
    }
    ResolverExport[] selectedExports = new ResolverExport[results.length - removedExports];
    int index = 0;
    for (int i = 0; i < results.length; i++) {
      if (selected ? results[i].getSubstitute() == null : results[i].getSubstitute() != null)
      {
        selectedExports[index] = results[i];
        index++;
      }
    }
    return selectedExports;
  }
  
  BundleConstraint getHost()
  {
    return host;
  }
  
  GenericCapability[] getGenericCapabilities()
  {
    if ((isFragment()) || (fragments == null) || (fragments.size() == 0)) {
      return genericCapabilities;
    }
    List<GenericCapability> result = getAll(genericCapabilities, fragmentGenericCapabilities);
    return (GenericCapability[])result.toArray(new GenericCapability[result.size()]);
  }
  
  BundleConstraint[] getRequires()
  {
    if ((isFragment()) || (fragments == null) || (fragments.size() == 0)) {
      return requires;
    }
    List<BundleConstraint> result = getAll(requires, fragmentRequires);
    return (BundleConstraint[])result.toArray(new BundleConstraint[result.size()]);
  }
  
  GenericConstraint[] getGenericRequires()
  {
    if ((isFragment()) || (fragments == null) || (fragments.size() == 0)) {
      return genericReqiures;
    }
    List<GenericConstraint> result = getAll(genericReqiures, fragmentGenericRequires);
    return (GenericConstraint[])result.toArray(new GenericConstraint[result.size()]);
  }
  
  BundleConstraint getRequire(String name)
  {
    BundleConstraint[] allRequires = getRequires();
    for (int i = 0; i < allRequires.length; i++) {
      if (allRequires[i].getVersionConstraint().getName().equals(name)) {
        return allRequires[i];
      }
    }
    return null;
  }
  
  public BundleDescription getBundleDescription()
  {
    return (BundleDescription)getBaseDescription();
  }
  
  public ResolverBundle getResolverBundle()
  {
    return this;
  }
  
  ResolverImport getImport(String name)
  {
    ResolverImport[] allImports = getImportPackages();
    for (int i = 0; i < allImports.length; i++) {
      if (allImports[i].getName().equals(name)) {
        return allImports[i];
      }
    }
    return null;
  }
  
  public String toString()
  {
    return "[" + getBundleDescription() + "]";
  }
  
  private void initFragments()
  {
    if (fragments == null) {
      fragments = new ArrayList(1);
    }
    if (fragmentExports == null) {
      fragmentExports = new HashMap(1);
    }
    if (fragmentImports == null) {
      fragmentImports = new HashMap(1);
    }
    if (fragmentRequires == null) {
      fragmentRequires = new HashMap(1);
    }
    if (fragmentGenericCapabilities == null) {
      fragmentGenericCapabilities = new HashMap(1);
    }
    if (fragmentGenericRequires == null) {
      fragmentGenericRequires = new HashMap(1);
    }
  }
  
  private boolean isImported(String packageName)
  {
    ResolverImport[] allImports = getImportPackages();
    for (int i = 0; i < allImports.length; i++) {
      if (packageName.equals(allImports[i].getName())) {
        return true;
      }
    }
    return false;
  }
  
  private boolean isRequired(String bundleName)
  {
    return getRequire(bundleName) != null;
  }
  
  void attachFragment(ResolverBundle fragment, boolean dynamicAttach)
  {
    if (isFragment()) {
      return;
    }
    if ((!getBundleDescription().attachFragments()) || ((isResolved()) && (!getBundleDescription().dynamicFragments()))) {
      return;
    }
    if ((fragment.getHost().getNumPossibleSuppliers() > 0) && (!((HostSpecification)fragment.getHost().getVersionConstraint()).isMultiHost())) {
      return;
    }
    ImportPackageSpecification[] newImports = fragment.getBundleDescription().getImportPackages();
    BundleSpecification[] newRequires = fragment.getBundleDescription().getRequiredBundles();
    ExportPackageDescription[] newExports = fragment.getBundleDescription().getExportPackages();
    GenericDescription[] newGenericCapabilities = fragment.getBundleDescription().getGenericCapabilities();
    GenericSpecification[] newGenericRequires = fragment.getBundleDescription().getGenericRequires();
    if ((dynamicAttach) && (constraintsConflict(fragment.getBundleDescription(), newImports, newRequires, newGenericRequires))) {
      return;
    }
    if ((isResolved()) && (newExports.length > 0)) {
      fragment.setNewFragmentExports(true);
    }
    initFragments();
    for (Iterator<ResolverBundle> iFragments = fragments.iterator(); iFragments.hasNext();)
    {
      ResolverBundle existingFragment = (ResolverBundle)iFragments.next();
      String bsn = existingFragment.getName();
      if ((bsn != null) && (bsn.equals(fragment.getName()))) {
        return;
      }
    }
    if (fragments.contains(fragment)) {
      return;
    }
    fragments.add(fragment);
    fragment.getHost().addPossibleSupplier(this);
    if (newImports.length > 0)
    {
      ArrayList<ResolverImport> hostImports = new ArrayList(newImports.length);
      for (int i = 0; i < newImports.length; i++) {
        if (!isImported(newImports[i].getName())) {
          hostImports.add(new ResolverImport(this, newImports[i]));
        }
      }
      fragmentImports.put(bundleID, hostImports);
    }
    if (newRequires.length > 0)
    {
      ArrayList<BundleConstraint> hostRequires = new ArrayList(newRequires.length);
      for (int i = 0; i < newRequires.length; i++) {
        if (!isRequired(newRequires[i].getName())) {
          hostRequires.add(new BundleConstraint(this, newRequires[i]));
        }
      }
      fragmentRequires.put(bundleID, hostRequires);
    }
    if (newGenericRequires.length > 0)
    {
      ArrayList<GenericConstraint> hostGenericRequires = new ArrayList(newGenericRequires.length);
      for (int i = 0; i < newGenericRequires.length; i++) {
        if (!"osgi.ee".equals(newGenericRequires[i].getType())) {
          hostGenericRequires.add(new GenericConstraint(this, newGenericRequires[i]));
        }
      }
      if (!hostGenericRequires.isEmpty()) {
        fragmentGenericRequires.put(bundleID, hostGenericRequires);
      }
    }
    ArrayList<ResolverExport> hostExports = new ArrayList(newExports.length);
    boolean foundEquivalent;
    ExportPackageDescription hostExport;
    if ((newExports.length > 0) && (dynamicAttach))
    {
      for (int i = 0; i < newExports.length; i++)
      {
        ResolverExport[] currentExports = getExports(newExports[i].getName());
        foundEquivalent = false;
        for (int j = 0; (j < currentExports.length) && (!foundEquivalent); j++) {
          if (equivalentExports(currentExports[j], newExports[i])) {
            foundEquivalent = true;
          }
        }
        if (!foundEquivalent)
        {
          hostExport = new ExportPackageDescriptionImpl(getBundleDescription(), newExports[i]);
          hostExports.add(new ResolverExport(this, hostExport));
        }
      }
      fragmentExports.put(bundleID, hostExports);
    }
    List<GenericCapability> hostCapabilities = new ArrayList(newGenericCapabilities.length);
    if ((newGenericCapabilities.length > 0) && (dynamicAttach))
    {
      GenericDescription[] arrayOfGenericDescription1;
      hostExport = (arrayOfGenericDescription1 = newGenericCapabilities).length;
      for (foundEquivalent = false; foundEquivalent < hostExport; foundEquivalent++)
      {
        GenericDescription capability = arrayOfGenericDescription1[foundEquivalent];
        if (!"osgi.identity".equals(capability.getType()))
        {
          GenericDescription hostCapabililty = new GenericDescriptionImpl(getBundleDescription(), capability);
          hostCapabilities.add(new GenericCapability(this, hostCapabililty));
        }
      }
      if (hostCapabilities.size() > 0)
      {
        fragmentGenericCapabilities.put(bundleID, hostCapabilities);
        if (isResolved()) {
          fragment.setNewFragmentCapabilities(true);
        }
      }
    }
    if (dynamicAttach)
    {
      resolver.getResolverExports().put((ResolverExport[])hostExports.toArray(new ResolverExport[hostExports.size()]));
      resolver.addGenerics((GenericCapability[])hostCapabilities.toArray(new GenericCapability[hostCapabilities.size()]));
    }
  }
  
  private boolean equivalentExports(ResolverExport existingExport, ExportPackageDescription newDescription)
  {
    ExportPackageDescription existingDescription = existingExport.getExportPackageDescription();
    if (!existingDescription.getName().equals(newDescription.getName())) {
      return false;
    }
    if (!existingDescription.getVersion().equals(newDescription.getVersion())) {
      return false;
    }
    if (!equivalentMaps(existingDescription.getAttributes(), newDescription.getAttributes(), true)) {
      return false;
    }
    if (!equivalentMaps(existingDescription.getDirectives(), newDescription.getDirectives(), true)) {
      return false;
    }
    return true;
  }
  
  public static boolean equivalentMaps(Map<String, Object> existingDirectives, Map<String, Object> newDirectives, boolean exactMatch)
  {
    if ((existingDirectives == null) && (newDirectives == null)) {
      return true;
    }
    if (existingDirectives == null ? newDirectives != null : newDirectives == null) {
      return false;
    }
    if ((exactMatch) && (existingDirectives.size() != newDirectives.size())) {
      return false;
    }
    for (Iterator<Map.Entry<String, Object>> entries = existingDirectives.entrySet().iterator(); entries.hasNext();)
    {
      Map.Entry<String, Object> entry = (Map.Entry)entries.next();
      Object newValue = newDirectives.get(entry.getKey());
      if ((newValue == null) || (entry.getValue().getClass() != newValue.getClass())) {
        return false;
      }
      if ((newValue instanceof String[]))
      {
        if (!Arrays.equals((Object[])entry.getValue(), (Object[])newValue)) {
          return false;
        }
      }
      else if (!entry.getValue().equals(newValue)) {
        return false;
      }
    }
    return true;
  }
  
  boolean constraintsConflict(BundleDescription fragment, ImportPackageSpecification[] newImports, BundleSpecification[] newRequires, GenericSpecification[] newGenericRequires)
  {
    boolean result = false;
    for (int i = 0; i < newImports.length; i++)
    {
      ResolverImport hostImport = getImport(newImports[i].getName());
      ResolverExport resolvedExport = (ResolverExport)(hostImport == null ? null : hostImport.getSelectedSupplier());
      if (importPackageConflict(resolvedExport, newImports[i]))
      {
        result = true;
        resolver.getState().addResolverError(fragment, 16, newImports[i].toString(), newImports[i]);
      }
    }
    BundleConstraint hostRequire;
    ResolverBundle resolvedRequire;
    for (int i = 0; i < newRequires.length; i++)
    {
      hostRequire = getRequire(newRequires[i].getName());
      resolvedRequire = (ResolverBundle)(hostRequire == null ? null : hostRequire.getSelectedSupplier());
      if (((resolvedRequire == null) && (isResolved())) || ((resolvedRequire != null) && (!newRequires[i].isSatisfiedBy(resolvedRequire.getBundleDescription()))))
      {
        result = true;
        resolver.getState().addResolverError(fragment, 16, newRequires[i].toString(), newRequires[i]);
      }
    }
    if ((isResolved()) && (newGenericRequires != null))
    {
      GenericSpecification[] arrayOfGenericSpecification;
      resolvedRequire = (arrayOfGenericSpecification = newGenericRequires).length;
      for (hostRequire = 0; hostRequire < resolvedRequire; hostRequire++)
      {
        GenericSpecification genericSpecification = arrayOfGenericSpecification[hostRequire];
        if (!"osgi.ee".equals(genericSpecification.getType()))
        {
          result = true;
          resolver.getState().addResolverError(fragment, 16, genericSpecification.toString(), genericSpecification);
        }
      }
    }
    return result;
  }
  
  private boolean importPackageConflict(ResolverExport resolvedExport, ImportPackageSpecification newImport)
  {
    if (resolvedExport == null) {
      return isResolved();
    }
    return !((ImportPackageSpecificationImpl)newImport).isSatisfiedBy(resolvedExport.getExportPackageDescription(), false);
  }
  
  private void setNewFragmentExports(boolean newFragmentExports)
  {
    this.newFragmentExports = newFragmentExports;
  }
  
  boolean isNewFragmentExports()
  {
    return newFragmentExports;
  }
  
  private void setNewFragmentCapabilities(boolean newFragmentCapabilities)
  {
    this.newFragmentCapabilities = newFragmentCapabilities;
  }
  
  boolean isNewFragmentCapabilities()
  {
    return newFragmentCapabilities;
  }
  
  public void detachFromHosts()
  {
    if (!isFragment()) {
      return;
    }
    VersionSupplier[] hosts = getHost().getPossibleSuppliers();
    if (hosts == null) {
      return;
    }
    VersionSupplier[] arrayOfVersionSupplier1;
    int j = (arrayOfVersionSupplier1 = hosts).length;
    for (int i = 0; i < j; i++)
    {
      VersionSupplier possibleHost = arrayOfVersionSupplier1[i];
      ((ResolverBundle)possibleHost).detachFragment(this, null);
    }
  }
  
  void detachFragment(ResolverBundle fragment, ResolverConstraint reason)
  {
    if (isFragment()) {
      return;
    }
    initFragments();
    
    ResolverImport[] oldImports = getImportPackages();
    BundleConstraint[] oldRequires = getRequires();
    if (!fragments.remove(fragment)) {
      return;
    }
    fragment.setNewFragmentExports(false);
    fragment.setNewFragmentCapabilities(false);
    fragment.getHost().removePossibleSupplier(this);
    fragmentImports.remove(bundleID);
    fragmentRequires.remove(bundleID);
    List<ResolverExport> removedExports = (List)fragmentExports.remove(bundleID);
    fragmentGenericRequires.remove(bundleID);
    List<GenericCapability> removedCapabilities = (List)fragmentGenericCapabilities.remove(bundleID);
    if (reason != null)
    {
      ResolverBundle[] remainingFrags = (ResolverBundle[])fragments.toArray(new ResolverBundle[fragments.size()]);
      ResolverBundle[] arrayOfResolverBundle1;
      int j = (arrayOfResolverBundle1 = remainingFrags).length;
      for (int i = 0; i < j; i++)
      {
        ResolverBundle remainingFrag = arrayOfResolverBundle1[i];
        List<ResolverImport> additionalImports = new ArrayList(0);
        List<BundleConstraint> additionalRequires = new ArrayList(0);
        if (!hasUnresolvedConstraint(reason, fragment, remainingFrag, oldImports, oldRequires, additionalImports, additionalRequires))
        {
          if (additionalImports.size() > 0)
          {
            List<ResolverImport> remainingImports = (List)fragmentImports.get(bundleID);
            if (remainingImports == null) {
              fragmentImports.put(bundleID, additionalImports);
            } else {
              remainingImports.addAll(additionalImports);
            }
          }
          if (additionalRequires.size() > 0)
          {
            List<BundleConstraint> remainingRequires = (List)fragmentRequires.get(bundleID);
            if (remainingRequires == null) {
              fragmentRequires.put(bundleID, additionalRequires);
            } else {
              remainingRequires.addAll(additionalRequires);
            }
          }
        }
      }
    }
    ResolverExport[] results = removedExports == null ? new ResolverExport[0] : (ResolverExport[])removedExports.toArray(new ResolverExport[removedExports.size()]);
    for (int i = 0; i < results.length; i++) {
      results[i].setSubstitute(results[i]);
    }
    resolver.getResolverExports().remove(results);
    if (removedCapabilities != null) {
      resolver.removeGenerics((GenericCapability[])removedCapabilities.toArray(new GenericCapability[removedCapabilities.size()]));
    }
  }
  
  private boolean hasUnresolvedConstraint(ResolverConstraint reason, ResolverBundle detachedFragment, ResolverBundle remainingFragment, ResolverImport[] oldImports, BundleConstraint[] oldRequires, List<ResolverImport> additionalImports, List<BundleConstraint> additionalRequires)
  {
    ImportPackageSpecification[] remainingFragImports = remainingFragment.getBundleDescription().getImportPackages();
    BundleSpecification[] remainingFragRequires = remainingFragment.getBundleDescription().getRequiredBundles();
    VersionConstraint[] constraints;
    VersionConstraint[] constraints;
    if ((reason instanceof ResolverImport)) {
      constraints = remainingFragImports;
    } else {
      constraints = remainingFragRequires;
    }
    for (int i = 0; i < constraints.length; i++) {
      if (reason.getName().equals(constraints[i].getName()))
      {
        detachFragment(remainingFragment, reason);
        return true;
      }
    }
    for (int i = 0; i < oldImports.length; i++) {
      if (oldImports[i].getVersionConstraint().getBundle() == detachedFragment.getBundleDescription()) {
        for (int j = 0; j < remainingFragImports.length; j++) {
          if (oldImports[i].getName().equals(remainingFragImports[j].getName()))
          {
            additionalImports.add(oldImports[i]);
            oldImports[i].setVersionConstraint(remainingFragImports[j]);
            break;
          }
        }
      }
    }
    for (int i = 0; i < oldRequires.length; i++) {
      if (oldRequires[i].getVersionConstraint().getBundle() == detachedFragment.getBundleDescription()) {
        for (int j = 0; j < remainingFragRequires.length; j++) {
          if (oldRequires[i].getName().equals(remainingFragRequires[j].getName()))
          {
            additionalRequires.add(oldRequires[i]);
            oldRequires[i].setVersionConstraint(remainingFragRequires[j]);
            break;
          }
        }
      }
    }
    return false;
  }
  
  void detachAllFragments()
  {
    if (fragments == null) {
      return;
    }
    ResolverBundle[] allFragments = (ResolverBundle[])fragments.toArray(new ResolverBundle[fragments.size()]);
    for (int i = 0; i < allFragments.length; i++) {
      detachFragment(allFragments[i], null);
    }
    fragments = null;
  }
  
  boolean isResolvable()
  {
    return resolvable;
  }
  
  void setResolvable(boolean resolvable)
  {
    this.resolvable = resolvable;
  }
  
  void addExport(ResolverExport re)
  {
    ResolverExport[] newExports = new ResolverExport[exports.length + 1];
    for (int i = 0; i < exports.length; i++) {
      newExports[i] = exports[i];
    }
    newExports[exports.length] = re;
    exports = newExports;
  }
  
  ResolverImpl getResolver()
  {
    return resolver;
  }
  
  ResolverBundle[] getFragments()
  {
    return fragments == null ? new ResolverBundle[0] : (ResolverBundle[])fragments.toArray(new ResolverBundle[fragments.size()]);
  }
  
  public int compareTo(ResolverBundle o)
  {
    String bsn = getName();
    String otherBsn = o.getName();
    if (bsn == null) {
      return otherBsn == null ? 0 : 1;
    }
    return otherBsn == null ? -1 : bsn.compareTo(otherBsn);
  }
  
  void setUninstalled()
  {
    uninstalled = true;
  }
  
  boolean isUninstalled()
  {
    return uninstalled;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.module.ResolverBundle
 * 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.BundleDescription;
import org.eclipse.osgi.service.resolver.VersionConstraint;
import org.osgi.framework.wiring.BundleRequirement;

public abstract class ResolverConstraint
{
  protected final ResolverBundle bundle;
  protected VersionConstraint constraint;
  private BundleRequirement requrement;
  private VersionSupplier[] possibleSuppliers;
  private int selectedSupplierIndex = 0;
  
  ResolverConstraint(ResolverBundle bundle, VersionConstraint constraint)
  {
    this.bundle = bundle;
    this.constraint = constraint;
    requrement = constraint.getRequirement();
  }
  
  ResolverBundle getBundle()
  {
    return bundle;
  }
  
  BundleDescription getBundleDescription()
  {
    return bundle.getBundleDescription();
  }
  
  boolean isFromFragment()
  {
    return constraint.getBundle().getHost() != null;
  }
  
  boolean isSatisfiedBy(VersionSupplier vs)
  {
    if ((vs.getResolverBundle().isUninstalled()) || (!bundle.getResolver().getPermissionChecker().checkPermission(constraint, vs.getBaseDescription()))) {
      return false;
    }
    return (vs.getSubstitute() == null) && (constraint.isSatisfiedBy(vs.getBaseDescription()));
  }
  
  VersionConstraint getVersionConstraint()
  {
    return constraint;
  }
  
  public String getName()
  {
    return constraint.getName();
  }
  
  public String toString()
  {
    return constraint.toString();
  }
  
  abstract boolean isOptional();
  
  void addPossibleSupplier(VersionSupplier supplier)
  {
    if (supplier == null) {
      return;
    }
    if (possibleSuppliers == null)
    {
      possibleSuppliers = new VersionSupplier[] { supplier };
      return;
    }
    VersionSupplier[] newSuppliers = new VersionSupplier[possibleSuppliers.length + 1];
    System.arraycopy(possibleSuppliers, 0, newSuppliers, 0, possibleSuppliers.length);
    newSuppliers[possibleSuppliers.length] = supplier;
    possibleSuppliers = newSuppliers;
  }
  
  public void removePossibleSupplier(VersionSupplier supplier)
  {
    if ((possibleSuppliers == null) || (supplier == null)) {
      return;
    }
    int index = -1;
    for (int i = 0; i < possibleSuppliers.length; i++) {
      if (possibleSuppliers[i] == supplier)
      {
        index = i;
        break;
      }
    }
    if (index >= 0)
    {
      if (possibleSuppliers.length == 1)
      {
        possibleSuppliers = null;
        return;
      }
      VersionSupplier[] newSuppliers = new VersionSupplier[possibleSuppliers.length - 1];
      System.arraycopy(possibleSuppliers, 0, newSuppliers, 0, index);
      if (index < possibleSuppliers.length - 1) {
        System.arraycopy(possibleSuppliers, index + 1, newSuppliers, index, possibleSuppliers.length - index - 1);
      }
      possibleSuppliers = newSuppliers;
    }
  }
  
  int getNumPossibleSuppliers()
  {
    if (possibleSuppliers == null) {
      return 0;
    }
    return possibleSuppliers.length;
  }
  
  boolean selectNextSupplier()
  {
    if ((possibleSuppliers == null) || (selectedSupplierIndex >= possibleSuppliers.length)) {
      return false;
    }
    selectedSupplierIndex += 1;
    return selectedSupplierIndex < possibleSuppliers.length;
  }
  
  VersionSupplier getSelectedSupplier()
  {
    if ((possibleSuppliers == null) || (selectedSupplierIndex >= possibleSuppliers.length)) {
      return null;
    }
    return possibleSuppliers[selectedSupplierIndex];
  }
  
  void setSelectedSupplier(int selectedSupplier)
  {
    selectedSupplierIndex = selectedSupplier;
  }
  
  int getSelectedSupplierIndex()
  {
    return selectedSupplierIndex;
  }
  
  VersionSupplier[] getPossibleSuppliers()
  {
    return possibleSuppliers;
  }
  
  void clearPossibleSuppliers()
  {
    possibleSuppliers = null;
    selectedSupplierIndex = 0;
  }
  
  void setVersionConstraint(VersionConstraint constraint)
  {
    this.constraint = constraint;
    requrement = constraint.getRequirement();
  }
  
  BundleRequirement getRequirement()
  {
    return requrement;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.module.ResolverConstraint
 * 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.BundleDescription;
import org.eclipse.osgi.service.resolver.ExportPackageDescription;

public class ResolverExport
  extends VersionSupplier
{
  private ResolverBundle resolverBundle;
  
  ResolverExport(ResolverBundle resolverBundle, ExportPackageDescription epd)
  {
    super(epd);
    this.resolverBundle = resolverBundle;
  }
  
  public ExportPackageDescription getExportPackageDescription()
  {
    return (ExportPackageDescription)base;
  }
  
  public BundleDescription getBundleDescription()
  {
    return getExportPackageDescription().getExporter();
  }
  
  ResolverBundle getExporter()
  {
    return resolverBundle;
  }
  
  ResolverBundle getResolverBundle()
  {
    return getExporter();
  }
  
  String[] getUsesDirective()
  {
    return (String[])getExportPackageDescription().getDirective("uses");
  }
}

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

import java.io.PrintStream;
import java.security.AccessController;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.HashSet;
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.framework.debug.Debug;
import org.eclipse.osgi.framework.debug.FrameworkDebugOptions;
import org.eclipse.osgi.framework.internal.core.Constants;
import org.eclipse.osgi.framework.internal.core.FilterImpl;
import org.eclipse.osgi.framework.util.SecureAction;
import org.eclipse.osgi.internal.baseadaptor.ArrayMap;
import org.eclipse.osgi.internal.resolver.BaseDescriptionImpl;
import org.eclipse.osgi.internal.resolver.BundleDescriptionImpl;
import org.eclipse.osgi.internal.resolver.StateImpl;
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.DisabledInfo;
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.NativeCodeDescription;
import org.eclipse.osgi.service.resolver.NativeCodeSpecification;
import org.eclipse.osgi.service.resolver.Resolver;
import org.eclipse.osgi.service.resolver.State;
import org.eclipse.osgi.service.resolver.StateWire;
import org.eclipse.osgi.service.resolver.VersionConstraint;
import org.eclipse.osgi.util.ManifestElement;
import org.osgi.framework.Filter;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.hooks.resolver.ResolverHook;
import org.osgi.framework.wiring.BundleCapability;

public class ResolverImpl
  implements Resolver
{
  private static final String RESOLVER = "org.eclipse.osgi/resolver";
  private static final String OPTION_DEBUG = "org.eclipse.osgi/resolver/debug";
  private static final String OPTION_WIRING = "org.eclipse.osgi/resolver/wiring";
  private static final String OPTION_IMPORTS = "org.eclipse.osgi/resolver/imports";
  private static final String OPTION_REQUIRES = "org.eclipse.osgi/resolver/requires";
  private static final String OPTION_GENERICS = "org.eclipse.osgi/resolver/generics";
  private static final String OPTION_USES = "org.eclipse.osgi/resolver/uses";
  private static final String OPTION_CYCLES = "org.eclipse.osgi/resolver/cycles";
  public static boolean DEBUG = false;
  public static boolean DEBUG_WIRING = false;
  public static boolean DEBUG_IMPORTS = false;
  public static boolean DEBUG_REQUIRES = false;
  public static boolean DEBUG_GENERICS = false;
  public static boolean DEBUG_USES = false;
  public static boolean DEBUG_CYCLES = false;
  private static int MAX_MULTIPLE_SUPPLIERS_MERGE = 10;
  private static int MAX_USES_TIME_BASE = 30000;
  private static int MAX_USES_TIME_LIMIT = 90000;
  private static final String USES_TIMEOUT_PROP = "osgi.usesTimeout";
  private static final String MULTIPLE_SUPPLIERS_LIMIT_PROP = "osgi.usesLimit";
  static final SecureAction secureAction = (SecureAction)AccessController.doPrivileged(SecureAction.createSecureAction());
  private String[][] CURRENT_EES;
  private ResolverHook hook;
  private State state;
  private final PermissionChecker permissionChecker;
  private MappedList<Long, BundleDescription> removalPending = new MappedList();
  private boolean initialized = false;
  private VersionHashMap<ResolverExport> resolverExports = null;
  private VersionHashMap<ResolverBundle> resolverBundles = null;
  private Map<String, VersionHashMap<GenericCapability>> resolverGenerics = null;
  private HashSet<ResolverBundle> unresolvedBundles = null;
  private HashMap<BundleDescription, ResolverBundle> bundleMapping = null;
  private GroupingChecker groupingChecker;
  private Comparator<BaseDescription> selectionPolicy;
  private boolean developmentMode = false;
  private boolean usesCalculationTimeout = false;
  private long usesTimeout = -1L;
  private int usesMultipleSuppliersLimit;
  private volatile CompositeResolveHelperRegistry compositeHelpers;
  
  public ResolverImpl(boolean checkPermissions)
  {
    permissionChecker = new PermissionChecker(checkPermissions, this);
  }
  
  PermissionChecker getPermissionChecker()
  {
    return permissionChecker;
  }
  
  private void initialize()
  {
    resolverExports = new VersionHashMap(this);
    resolverBundles = new VersionHashMap(this);
    resolverGenerics = new HashMap();
    unresolvedBundles = new HashSet();
    bundleMapping = new HashMap();
    BundleDescription[] bundles = state.getBundles();
    groupingChecker = new GroupingChecker();
    
    ArrayList<ResolverBundle> fragmentBundles = new ArrayList();
    for (int i = 0; i < bundles.length; i++) {
      initResolverBundle(bundles[i], fragmentBundles, false);
    }
    List<BundleDescription> removedBundles = removalPending.getAllValues();
    for (Iterator localIterator = removedBundles.iterator(); localIterator.hasNext();)
    {
      BundleDescription removed = (BundleDescription)localIterator.next();
      initResolverBundle(removed, fragmentBundles, true);
    }
    BundleDescription[] hosts;
    int i;
    for (Iterator<ResolverBundle> iter = fragmentBundles.iterator(); iter.hasNext(); i < hosts.length)
    {
      ResolverBundle fragment = (ResolverBundle)iter.next();
      hosts = ((HostSpecification)fragment.getHost().getVersionConstraint()).getHosts();
      i = 0; continue;
      ResolverBundle host = (ResolverBundle)bundleMapping.get(hosts[i]);
      if (host != null) {
        host.attachFragment(fragment, false);
      }
      i++;
    }
    rewireBundles();
    setDebugOptions();
    initialized = true;
  }
  
  private void initResolverBundle(BundleDescription bundleDesc, ArrayList<ResolverBundle> fragmentBundles, boolean pending)
  {
    ResolverBundle bundle = new ResolverBundle(bundleDesc, this);
    bundleMapping.put(bundleDesc, bundle);
    if ((!pending) || (bundleDesc.isResolved()))
    {
      resolverExports.put(bundle.getExportPackages());
      resolverBundles.put(bundle.getName(), bundle);
      addGenerics(bundle.getGenericCapabilities());
    }
    if (bundleDesc.isResolved())
    {
      bundle.setState(2);
      if (bundleDesc.getHost() != null) {
        fragmentBundles.add(bundle);
      }
    }
    else if (!pending)
    {
      unresolvedBundles.add(bundle);
    }
  }
  
  private void rewireBundles()
  {
    List<ResolverBundle> visited = new ArrayList(bundleMapping.size());
    for (Iterator localIterator = bundleMapping.values().iterator(); localIterator.hasNext();)
    {
      ResolverBundle rb = (ResolverBundle)localIterator.next();
      if (rb.getBundleDescription().isResolved()) {
        rewireBundle(rb, visited);
      }
    }
  }
  
  private void rewireBundle(ResolverBundle rb, List<ResolverBundle> visited)
  {
    if (visited.contains(rb)) {
      return;
    }
    visited.add(rb);
    
    BundleConstraint[] requires = rb.getRequires();
    for (int i = 0; i < requires.length; i++) {
      rewireRequire(requires[i], visited);
    }
    ResolverImport[] imports = rb.getImportPackages();
    for (int i = 0; i < imports.length; i++) {
      rewireImport(imports[i], visited);
    }
    GenericConstraint[] genericRequires = rb.getGenericRequires();
    for (int i = 0; i < genericRequires.length; i++) {
      rewireGeneric(genericRequires[i], visited);
    }
  }
  
  private void rewireGeneric(GenericConstraint constraint, List<ResolverBundle> visited)
  {
    if (constraint.getSelectedSupplier() != null) {
      return;
    }
    GenericDescription[] suppliers = ((GenericSpecification)constraint.getVersionConstraint()).getSuppliers();
    if (suppliers == null) {
      return;
    }
    VersionHashMap<GenericCapability> namespace = (VersionHashMap)resolverGenerics.get(constraint.getNameSpace());
    if (namespace == null)
    {
      System.err.println("Could not find matching capability for " + constraint.getVersionConstraint());
      
      return;
    }
    String constraintName = constraint.getName();
    List<GenericCapability> matches = constraintName == null ? namespace.get(constraintName) : namespace.getAllValues();
    int j;
    int i;
    for (Iterator localIterator = matches.iterator(); localIterator.hasNext(); i < j)
    {
      GenericCapability match = (GenericCapability)localIterator.next();
      GenericDescription[] arrayOfGenericDescription1;
      j = (arrayOfGenericDescription1 = suppliers).length;i = 0; continue;GenericDescription supplier = arrayOfGenericDescription1[i];
      if (match.getBaseDescription() == supplier) {
        constraint.addPossibleSupplier(match);
      }
      i++;
    }
    VersionSupplier[] matchingCapabilities = constraint.getPossibleSuppliers();
    if (matchingCapabilities != null) {
      for (int i = 0; i < matchingCapabilities.length; i++) {
        rewireBundle(matchingCapabilities[i].getResolverBundle(), visited);
      }
    }
  }
  
  private void rewireRequire(BundleConstraint req, List<ResolverBundle> visited)
  {
    if (req.getSelectedSupplier() != null) {
      return;
    }
    ResolverBundle matchingBundle = (ResolverBundle)bundleMapping.get(req.getVersionConstraint().getSupplier());
    req.addPossibleSupplier(matchingBundle);
    if ((matchingBundle == null) && (!req.isOptional())) {
      System.err.println("Could not find matching bundle for " + req.getVersionConstraint());
    }
    if (matchingBundle != null) {
      rewireBundle(matchingBundle, visited);
    }
  }
  
  private void rewireImport(ResolverImport imp, List<ResolverBundle> visited)
  {
    if ((imp.isDynamic()) || (imp.getSelectedSupplier() != null)) {
      return;
    }
    ResolverExport matchingExport = null;
    ExportPackageDescription importSupplier = (ExportPackageDescription)imp.getVersionConstraint().getSupplier();
    ResolverBundle exporter = importSupplier == null ? null : (ResolverBundle)bundleMapping.get(importSupplier.getExporter());
    List<ResolverExport> matches = resolverExports.get(imp.getName());
    for (Iterator localIterator = matches.iterator(); localIterator.hasNext();)
    {
      ResolverExport export = (ResolverExport)localIterator.next();
      if ((export.getExporter() == exporter) && (importSupplier == export.getExportPackageDescription()))
      {
        matchingExport = export;
        break;
      }
    }
    imp.addPossibleSupplier(matchingExport);
    if ((imp.getSelectedSupplier() == null) && (!imp.isOptional())) {
      System.err.println("Could not find matching export for " + imp.getVersionConstraint());
    }
    if (imp.getSelectedSupplier() != null) {
      rewireBundle(((ResolverExport)imp.getSelectedSupplier()).getExporter(), visited);
    }
  }
  
  private boolean isResolvable(ResolverBundle bundle, Dictionary<Object, Object>[] platformProperties, Collection<ResolverBundle> hookDisabled)
  {
    BundleDescription bundleDesc = bundle.getBundleDescription();
    if (hookDisabled.contains(bundle))
    {
      state.addResolverError(bundleDesc, 262144, "Resolver hook disabled bundle.", null);
      return false;
    }
    DisabledInfo[] disabledInfos = state.getDisabledInfos(bundleDesc);
    if (disabledInfos.length > 0)
    {
      StringBuffer message = new StringBuffer();
      for (int i = 0; i < disabledInfos.length; i++)
      {
        if (i > 0) {
          message.append(' ');
        }
        message.append('"').append(disabledInfos[i].getPolicyName()).append(':').append(disabledInfos[i].getMessage()).append('"');
      }
      state.addResolverError(bundleDesc, 262144, message.toString(), null);
      return false;
    }
    String[] ees = bundleDesc.getExecutionEnvironments();
    boolean matchedEE = ees.length == 0;
    if (!matchedEE) {
      for (int i = 0; (i < ees.length) && (!matchedEE); i++) {
        for (int j = 0; (j < CURRENT_EES.length) && (!matchedEE); j++) {
          for (int k = 0; (k < CURRENT_EES[j].length) && (!matchedEE); k++) {
            if (CURRENT_EES[j][k].equals(ees[i]))
            {
              ((BundleDescriptionImpl)bundleDesc).setEquinoxEE(j);
              matchedEE = true;
            }
          }
        }
      }
    }
    if (!matchedEE)
    {
      Stri
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-2017. Infinite Loop Ltd