org.eclipse.osgi_3.8.2.v20130124-134944

   if (visited.contains(requiredBundle)) {
      return;
    }
    visited.add(requiredBundle);
    
    ExportPackageDescription[] substitutedExports = requiredBundle.getSubstitutedExports();
    ExportPackageDescription[] imports = requiredBundle.getResolvedImports();
    Set<String> substituteNames = null;
    for (int i = 0; i < substitutedExports.length; i++) {
      if ((pkgNames == null) || (pkgNames.contains(substitutedExports[i].getName()))) {
        for (int j = 0; j < imports.length; j++) {
          if ((substitutedExports[i].getName().equals(imports[j].getName())) && (!pkgSet.contains(imports[j])))
          {
            if (substituteNames == null) {
              substituteNames = new HashSet(1);
            } else {
              substituteNames.clear();
            }
            substituteNames.add(substitutedExports[i].getName());
            getPackages(imports[j].getSupplier(), symbolicName, importList, orderedPkgList, pkgSet, new HashSet(0), strict, substituteNames, options);
          }
        }
      }
    }
    importList = substitutedExports.length == 0 ? importList : new HashSet(importList);
    for (int i = 0; i < substitutedExports.length; i++) {
      importList.add(substitutedExports[i].getName());
    }
    ExportPackageDescription[] exports = requiredBundle.getSelectedExports();
    HashSet<String> exportNames = new HashSet(exports.length);
    for (int i = 0; i < exports.length; i++) {
      if (((pkgNames == null) || (pkgNames.contains(exports[i].getName()))) && (!isSystemExport(exports[i], options)) && (isFriend(symbolicName, exports[i], strict)) && (!importList.contains(exports[i].getName())) && (!pkgSet.contains(exports[i])) && 
        (!exportNames.contains(exports[i].getName())))
      {
        orderedPkgList.add(exports[i]);
        pkgSet.add(exports[i]);
        exportNames.add(exports[i].getName());
      }
    }
    RequiresHolder requiredBundles = new RequiresHolder(requiredBundle, options);
    for (int i = 0; i < requiredBundles.getSize(); i++) {
      if (requiredBundles.getSupplier(i) != null) {
        if (requiredBundles.isExported(i))
        {
          getPackages(requiredBundles.getSupplier(i), symbolicName, importList, orderedPkgList, pkgSet, visited, strict, pkgNames, options);
        }
        else if (exportNames.size() > 0)
        {
          Set<BundleDescription> tmpVisited = new HashSet();
          getPackages(requiredBundles.getSupplier(i), symbolicName, importList, orderedPkgList, pkgSet, tmpVisited, strict, exportNames, options);
        }
      }
    }
  }
  
  private boolean isSystemExport(ExportPackageDescription export, int options)
  {
    if ((options & 0x1) != 0) {
      return false;
    }
    return ((Integer)export.getDirective("x-equinox-ee")).intValue() >= 0;
  }
  
  private boolean isFriend(String consumerBSN, ExportPackageDescription export, boolean strict)
  {
    if (!strict) {
      return true;
    }
    String[] friends = (String[])export.getDirective("x-friends");
    if (friends == null) {
      return true;
    }
    for (int i = 0; i < friends.length; i++) {
      if (friends[i].equals(consumerBSN)) {
        return true;
      }
    }
    return false;
  }
  
  public int getAccessCode(BundleDescription bundle, ExportPackageDescription export)
  {
    if (((Boolean)export.getDirective("x-internal")).booleanValue()) {
      return 2;
    }
    if (!isFriend(bundle.getSymbolicName(), export, true)) {
      return 2;
    }
    return 1;
  }
  
  public static StateHelper getInstance()
  {
    return instance;
  }
}

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

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedList;
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.Headers;
import org.eclipse.osgi.framework.util.KeyedElement;
import org.eclipse.osgi.framework.util.KeyedHashSet;
import org.eclipse.osgi.internal.baseadaptor.StateManager;
import org.eclipse.osgi.internal.loader.BundleLoaderProxy;
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.ResolverError;
import org.eclipse.osgi.service.resolver.ResolverHookException;
import org.eclipse.osgi.service.resolver.State;
import org.eclipse.osgi.service.resolver.StateDelta;
import org.eclipse.osgi.service.resolver.StateHelper;
import org.eclipse.osgi.service.resolver.StateObjectFactory;
import org.eclipse.osgi.service.resolver.StateWire;
import org.eclipse.osgi.service.resolver.VersionConstraint;
import org.eclipse.osgi.util.ManifestElement;
import org.eclipse.osgi.util.NLS;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.Version;
import org.osgi.framework.hooks.resolver.ResolverHook;
import org.osgi.framework.hooks.resolver.ResolverHookFactory;
import org.osgi.framework.wiring.BundleRevision;

public abstract class StateImpl
  implements State
{
  private static final String OSGI_OS = "osgi.os";
  private static final String OSGI_WS = "osgi.ws";
  private static final String OSGI_NL = "osgi.nl";
  private static final String OSGI_ARCH = "osgi.arch";
  public static final String[] PROPS = { "osgi.os", "osgi.ws", "osgi.nl", "osgi.arch", "org.osgi.framework.system.packages", "org.osgi.framework.system.packages.extra", "osgi.resolverMode", "org.osgi.framework.executionenvironment", "osgi.resolveOptional", "osgi.genericAliases", "org.osgi.framework.os.name", "org.osgi.framework.os.version", "org.osgi.framework.processor", "org.osgi.framework.language", "osgi.system.bundle", "org.osgi.framework.system.capabilities", "org.osgi.framework.system.capabilities.extra" };
  private static final DisabledInfo[] EMPTY_DISABLEDINFOS = new DisabledInfo[0];
  public static final String OSGI_EE_NAMESPACE = "osgi.ee";
  private transient Resolver resolver;
  private transient StateDeltaImpl changes;
  private transient boolean resolving = false;
  private transient LinkedList<BundleDescription> removalPendings = new LinkedList();
  private boolean resolved = true;
  private long timeStamp = System.currentTimeMillis();
  private final KeyedHashSet bundleDescriptions = new KeyedHashSet(false);
  private final Map<BundleDescription, List<ResolverError>> resolverErrors = new HashMap();
  private StateObjectFactory factory;
  private final KeyedHashSet resolvedBundles = new KeyedHashSet();
  private final Map<BundleDescription, List<DisabledInfo>> disabledBundles = new HashMap();
  private boolean fullyLoaded = false;
  private boolean dynamicCacheChanged = false;
  private StateReader reader;
  private Dictionary<Object, Object>[] platformProperties = { new Hashtable(PROPS.length) };
  private long highestBundleId = -1L;
  private final Set<String> platformPropertyKeys = new HashSet(PROPS.length);
  private ResolverHookFactory hookFactory;
  private ResolverHook hook;
  private boolean developmentMode = false;
  private static long cumulativeTime;
  final Object monitor = new Object();
  
  protected StateImpl()
  {
    addPlatformPropertyKeys(PROPS);
  }
  
  public boolean addBundle(BundleDescription description)
  {
    synchronized (monitor)
    {
      if (!basicAddBundle(description)) {
        return false;
      }
      String platformFilter = description.getPlatformFilter();
      if (platformFilter != null) {
        try
        {
          FilterImpl filter = FilterImpl.newInstance(platformFilter);
          addPlatformPropertyKeys(filter.getAttributes());
        }
        catch (InvalidSyntaxException localInvalidSyntaxException) {}
      }
      NativeCodeSpecification nativeCode = description.getNativeCodeSpecification();
      if (nativeCode != null)
      {
        NativeCodeDescription[] suppliers = nativeCode.getPossibleSuppliers();
        for (int i = 0; i < suppliers.length; i++)
        {
          FilterImpl filter = (FilterImpl)suppliers[i].getFilter();
          if (filter != null) {
            addPlatformPropertyKeys(filter.getAttributes());
          }
        }
      }
      resolved = false;
      getDelta().recordBundleAdded((BundleDescriptionImpl)description);
      if (getSystemBundle().equals(description.getSymbolicName())) {
        resetAllSystemCapabilities();
      }
      if (resolver != null) {
        resolver.bundleAdded(description);
      }
      updateTimeStamp();
      return true;
    }
  }
  
  public boolean updateBundle(BundleDescription newDescription)
  {
    synchronized (monitor)
    {
      BundleDescriptionImpl existing = (BundleDescriptionImpl)bundleDescriptions.get((BundleDescriptionImpl)newDescription);
      if (existing == null) {
        return false;
      }
      if (!bundleDescriptions.remove(existing)) {
        return false;
      }
      resolvedBundles.remove(existing);
      List<DisabledInfo> infos = (List)disabledBundles.remove(existing);
      if (infos != null)
      {
        List<DisabledInfo> newInfos = new ArrayList(infos.size());
        for (iInfos = infos.iterator(); iInfos.hasNext();)
        {
          DisabledInfo info = (DisabledInfo)iInfos.next();
          newInfos.add(new DisabledInfo(info.getPolicyName(), info.getMessage(), newDescription));
        }
        disabledBundles.put(newDescription, newInfos);
      }
      existing.setStateBit(4, true);
      if (!basicAddBundle(newDescription)) {
        return false;
      }
      resolved = false;
      getDelta().recordBundleUpdated((BundleDescriptionImpl)newDescription);
      if (getSystemBundle().equals(newDescription.getSymbolicName())) {
        resetAllSystemCapabilities();
      }
      if (resolver != null)
      {
        boolean pending = isInUse(existing);
        resolver.bundleUpdated(newDescription, existing, pending);
        if (pending)
        {
          getDelta().recordBundleRemovalPending(existing);
          addRemovalPending(existing);
        }
        else
        {
          try
          {
            resolving = true;
            resolverErrors.remove(existing);
            resolveBundle(existing, false, null, null, null, null, null, null, null, null);
          }
          finally
          {
            resolving = false;
          }
        }
      }
      updateTimeStamp();
      return true;
    }
  }
  
  public BundleDescription removeBundle(long bundleId)
  {
    synchronized (monitor)
    {
      BundleDescription toRemove = getBundle(bundleId);
      if ((toRemove == null) || (!removeBundle(toRemove))) {
        return null;
      }
      return toRemove;
    }
  }
  
  /* Error */
  public boolean removeBundle(BundleDescription toRemove)
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 1028	org/eclipse/osgi/internal/resolver/StateImpl:monitor	Ljava/lang/Object;
    //   4: dup
    //   5: astore_2
    //   6: monitorenter
    //   7: aload_0
    //   8: getfield 1035	org/eclipse/osgi/internal/resolver/StateImpl:bundleDescriptions	Lorg/eclipse/osgi/framework/util/KeyedHashSet;
    //   11: aload_1
    //   12: checkcast 556	org/eclipse/osgi/framework/util/KeyedElement
    //   15: invokevirtual 1107	org/eclipse/osgi/framework/util/KeyedHashSet:get	(Lorg/eclipse/osgi/framework/util/KeyedElement;)Lorg/eclipse/osgi/framework/util/KeyedElement;
    //   18: checkcast 577	org/eclipse/osgi/service/resolver/BundleDescription
    //   21: astore_1
    //   22: aload_1
    //   23: ifnull +17 -> 40
    //   26: aload_0
    //   27: getfield 1035	org/eclipse/osgi/internal/resolver/StateImpl:bundleDescriptions	Lorg/eclipse/osgi/framework/util/KeyedHashSet;
    //   30: aload_1
    //   31: checkcast 556	org/eclipse/osgi/framework/util/KeyedElement
    //   34: invokevirtual 1104	org/eclipse/osgi/framework/util/KeyedHashSet:remove	(Lorg/eclipse/osgi/framework/util/KeyedElement;)Z
    //   37: ifne +7 -> 44
    //   40: aload_2
    //   41: monitorexit
    //   42: iconst_0
    //   43: ireturn
    //   44: aload_0
    //   45: getfield 1036	org/eclipse/osgi/internal/resolver/StateImpl:resolvedBundles	Lorg/eclipse/osgi/framework/util/KeyedHashSet;
    //   48: aload_1
    //   49: checkcast 556	org/eclipse/osgi/framework/util/KeyedElement
    //   52: invokevirtual 1104	org/eclipse/osgi/framework/util/KeyedHashSet:remove	(Lorg/eclipse/osgi/framework/util/KeyedElement;)Z
    //   55: pop
    //   56: aload_0
    //   57: getfield 1032	org/eclipse/osgi/internal/resolver/StateImpl:disabledBundles	Ljava/util/Map;
    //   60: aload_1
    //   61: invokeinterface 1241 2 0
    //   66: pop
    //   67: aload_0
    //   68: iconst_0
    //   69: putfield 1026	org/eclipse/osgi/internal/resolver/StateImpl:resolved	Z
    //   72: aload_0
    //   73: invokespecial 1181	org/eclipse/osgi/internal/resolver/StateImpl:getDelta	()Lorg/eclipse/osgi/internal/resolver/StateDeltaImpl;
    //   76: aload_1
    //   77: checkcast 560	org/eclipse/osgi/internal/resolver/BundleDescriptionImpl
    //   80: invokevirtual 1154	org/eclipse/osgi/internal/resolver/StateDeltaImpl:recordBundleRemoved	(Lorg/eclipse/osgi/internal/resolver/BundleDescriptionImpl;)V
    //   83: aload_1
    //   84: checkcast 560	org/eclipse/osgi/internal/resolver/BundleDescriptionImpl
    //   87: iconst_4
    //   88: iconst_1
    //   89: invokevirtual 1112	org/eclipse/osgi/internal/resolver/BundleDescriptionImpl:setStateBit	(IZ)V
    //   92: aload_0
    //   93: getfield 1040	org/eclipse/osgi/internal/resolver/StateImpl:resolver	Lorg/eclipse/osgi/service/resolver/Resolver;
    //   96: ifnull +88 -> 184
    //   99: aload_0
    //   100: aload_1
    //   101: invokespecial 1188	org/eclipse/osgi/internal/resolver/StateImpl:isInUse	(Lorg/eclipse/osgi/service/resolver/BundleDescription;)Z
    //   104: istore_3
    //   105: aload_0
    //   106: getfield 1040	org/eclipse/osgi/internal/resolver/StateImpl:resolver	Lorg/eclipse/osgi/service/resolver/Resolver;
    //   109: aload_1
    //   110: iload_3
    //   111: invokeinterface 1274 3 0
    //   116: iload_3
    //   117: ifeq +22 -> 139
    //   120: aload_0
    //   121: invokespecial 1181	org/eclipse/osgi/internal/resolver/StateImpl:getDelta	()Lorg/eclipse/osgi/internal/resolver/StateDeltaImpl;
    //   124: aload_1
    //   125: checkcast 560	org/eclipse/osgi/internal/resolver/BundleDescriptionImpl
    //   128: invokevirtual 1153	org/eclipse/osgi/internal/resolver/StateDeltaImpl:recordBundleRemovalPending	(Lorg/eclipse/osgi/internal/resolver/BundleDescriptionImpl;)V
    //   131: aload_0
    //   132: aload_1
    //   133: invokespecial 1186	org/eclipse/osgi/internal/resolver/StateImpl:addRemovalPending	(Lorg/eclipse/osgi/service/resolver/BundleDescription;)V
    //   136: goto +48 -> 184
    //   139: aload_0
    //   140: iconst_1
    //   141: putfield 1027	org/eclipse/osgi/internal/resolver/StateImpl:resolving	Z
    //   144: aload_0
    //   145: getfield 1033	org/eclipse/osgi/internal/resolver/StateImpl:resolverErrors	Ljava/util/Map;
    //   148: aload_1
    //   149: invokeinterface 1241 2 0
    //   154: pop
    //   155: aload_0
    //   156: aload_1
    //   157: iconst_0
    //   158: aconst_null
    //   159: aconst_null
    //   160: aconst_null
    //   161: aconst_null
    //   162: aconst_null
    //   163: invokevirtual 1203	org/eclipse/osgi/internal/resolver/StateImpl:resolveBundle	(Lorg/eclipse/osgi/service/resolver/BundleDescription;Z[Lorg/eclipse/osgi/service/resolver/BundleDescription;[Lorg/eclipse/osgi/service/resolver/ExportPackageDescription;[Lorg/eclipse/osgi/service/resolver/ExportPackageDescription;[Lorg/eclipse/osgi/service/resolver/BundleDescription;[Lorg/eclipse/osgi/service/resolver/ExportPackageDescription;)V
    //   166: goto +13 -> 179
    //   169: astore 4
    //   171: aload_0
    //   172: iconst_0
    //   173: putfield 1027	org/eclipse/osgi/internal/resolver/StateImpl:resolving	Z
    //   176: aload 4
    //   178: athrow
    //   179: aload_0
    //   180: iconst_0
    //   181: putfield 1027	org/eclipse/osgi/internal/resolver/StateImpl:resolving	Z
    //   184: aload_0
    //   185: invokespecial 1167	org/eclipse/osgi/internal/resolver/StateImpl:updateTimeStamp	()V
    //   188: aload_2
    //   189: monitorexit
    //   190: iconst_1
    //   191: ireturn
    //   192: aload_2
    //   193: monitorexit
    //   194: athrow
    // Line number table:
    //   Java source line #164	-> byte code offset #0
    //   Java source line #165	-> byte code offset #7
    //   Java source line #166	-> byte code offset #22
    //   Java source line #167	-> byte code offset #40
    //   Java source line #168	-> byte code offset #44
    //   Java source line #169	-> byte code offset #56
    //   Java source line #170	-> byte code offset #67
    //   Java source line #171	-> byte code offset #72
    //   Java source line #172	-> byte code offset #83
    //   Java source line #173	-> byte code offset #92
    //   Java source line #174	-> byte code offset #99
    //   Java source line #175	-> byte code offset #105
    //   Java source line #176	-> byte code offset #116
    //   Java source line #177	-> byte code offset #120
    //   Java source line #178	-> byte code offset #131
    //   Java source line #179	-> byte code offset #136
    //   Java source line #182	-> byte code offset #139
    //   Java source line #183	-> byte code offset #144
    //   Java source line #184	-> byte code offset #155
    //   Java source line #185	-> byte code offset #166
    //   Java source line #186	-> byte code offset #171
    //   Java source line #187	-> byte code offset #176
    //   Java source line #186	-> byte code offset #179
    //   Java source line #190	-> byte code offset #184
    //   Java source line #191	-> byte code offset #188
    //   Java source line #164	-> byte code offset #192
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	195	0	this	StateImpl
    //   0	195	1	toRemove	BundleDescription
    //   5	188	2	Ljava/lang/Object;	Object
    //   104	13	3	pending	boolean
    //   169	8	4	localObject1	Object
    // Exception table:
    //   from	to	target	type
    //   139	169	169	finally
    //   7	42	192	finally
    //   44	190	192	finally
    //   192	194	192	finally
  }
  
  private boolean isInUse(BundleDescription bundle)
  {
    Object userObject = bundle.getUserObject();
    if ((userObject instanceof BundleLoaderProxy)) {
      return ((BundleLoaderProxy)userObject).inUse();
    }
    return bundle.getDependents().length > 0;
  }
  
  /* Error */
  public StateDelta getChanges()
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 1028	org/eclipse/osgi/internal/resolver/StateImpl:monitor	Ljava/lang/Object;
    //   4: dup
    //   5: astore_1
    //   6: monitorenter
    //   7: aload_0
    //   8: invokespecial 1181	org/eclipse/osgi/internal/resolver/StateImpl:getDelta	()Lorg/eclipse/osgi/internal/resolver/StateDeltaImpl;
    //   11: aload_1
    //   12: monitorexit
    //   13: areturn
    //   14: aload_1
    //   15: monitorexit
    //   16: athrow
    // Line number table:
    //   Java source line #203	-> byte code offset #0
    //   Java source line #204	-> byte code offset #7
    //   Java source line #203	-> byte code offset #14
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	17	0	this	StateImpl
    //   5	10	1	Ljava/lang/Object;	Object
    // Exception table:
    //   from	to	target	type
    //   7	13	14	finally
    //   14	16	14	finally
  }
  
  private StateDeltaImpl getDelta()
  {
    if (changes == null) {
      changes = new StateDeltaImpl(this);
    }
    return changes;
  }
  
  public BundleDescription[] getBundles(String symbolicName)
  {
    synchronized (monitor)
    {
      if ("system.bundle".equals(symbolicName)) {
        symbolicName = getSystemBundle();
      }
      List<BundleDescription> bundles = new ArrayList();
      for (Iterator<KeyedElement> iter = bundleDescriptions.iterator(); iter.hasNext();)
      {
        BundleDescription bundle = (BundleDescription)iter.next();
        if (symbolicName.equals(bundle.getSymbolicName())) {
          bundles.add(bundle);
        }
      }
      return (BundleDescription[])bundles.toArray(new BundleDescription[bundles.size()]);
    }
  }
  
  /* Error */
  public BundleDescription[] getBundles()
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 1028	org/eclipse/osgi/internal/resolver/StateImpl:monitor	Ljava/lang/Object;
    //   4: dup
    //   5: astore_1
    //   6: monitorenter
    //   7: aload_0
    //   8: getfield 1035	org/eclipse/osgi/internal/resolver/StateImpl:bundleDescriptions	Lorg/eclipse/osgi/framework/util/KeyedHashSet;
    //   11: aload_0
    //   12: getfield 1035	org/eclipse/osgi/internal/resolver/StateImpl:bundleDescriptions	Lorg/eclipse/osgi/framework/util/KeyedHashSet;
    //   15: invokevirtual 1097	org/eclipse/osgi/framework/util/KeyedHashSet:size	()I
    //   18: anewarray 577	org/eclipse/osgi/service/resolver/BundleDescription
    //   21: invokevirtual 1105	org/eclipse/osgi/framework/util/KeyedHashSet:elements	([Ljava/lang/Object;)[Ljava/lang/Object;
    //   24: checkcast 521	[Lorg/eclipse/osgi/service/resolver/BundleDescription;
    //   27: aload_1
    //   28: monitorexit
    //   29: areturn
    //   30: aload_1
    //   31: monitorexit
    //   32: athrow
    // Line number table:
    //   Java source line #229	-> byte code offset #0
    //   Java source line #230	-> byte code offset #7
    //   Java source line #229	-> byte code offset #30
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	33	0	this	StateImpl
    //   5	26	1	Ljava/lang/Object;	Object
    // Exception table:
    //   from	to	target	type
    //   7	29	30	finally
    //   30	32	30	finally
  }
  
  public BundleDescription getBundle(long id)
  {
    synchronized (monitor)
    {
      BundleDescription result = (BundleDescription)bundleDescriptions.getByKey(new Long(id));
      if (result != null) {
        return result;
      }
      for (Iterator<BundleDescription> iter = removalPendings.iterator(); iter.hasNext();)
      {
        BundleDescription removedBundle = (BundleDescription)iter.next();
        if (removedBundle.getBundleId() == id) {
          return removedBundle;
        }
      }
      return null;
    }
  }
  
  public BundleDescription getBundle(String name, Version version)
  {
    synchronized (monitor)
    {
      BundleDescription[] allBundles = getBundles(name);
      if (allBundles.length == 1) {
        return (version == null) || (allBundles[0].getVersion().equals(version)) ? allBundles[0] : null;
      }
      if (allBundles.length == 0) {
        return null;
      }
      BundleDescription unresolvedFound = null;
      BundleDescription resolvedFound = null;
      for (int i = 0; i < allBundles.length; i++)
      {
        BundleDescription current = allBundles[i];
        BundleDescription base;
        BundleDescription base;
        if (current.isResolved()) {
          base = resolvedFound;
        } else {
          base = unresolvedFound;
        }
        if ((version == null) || (current.getVersion().equals(version))) {
          if ((base != null) && ((base.getVersion().compareTo(current.getVersion()) <= 0) || (base.getBundleId() > current.getBundleId())))
          {
            if (base == resolvedFound) {
              resolvedFound = current;
            } else {
              unresolvedFound = current;
            }
          }
          else if (current.isResolved()) {
            resolvedFound = current;
          } else {
            unresolvedFound = current;
          }
        }
      }
      if (resolvedFound != null) {
        return resolvedFound;
      }
      return unresolvedFound;
    }
  }
  
  /* Error */
  public long getTimeStamp()
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 1028	org/eclipse/osgi/internal/resolver/StateImpl:monitor	Ljava/lang/Object;
    //   4: dup
    //   5: astore_1
    //   6: monitorenter
    //   7: aload_0
    //   8: getfield 1022	org/eclipse/osgi/internal/resolver/StateImpl:timeStamp	J
    //   11: aload_1
    //   12: monitorexit
    //   13: lreturn
    //   14: aload_1
    //   15: monitorexit
    //   16: athrow
    // Line number table:
    //   Java source line #289	-> byte code offset #0
    //   Java source line #290	-> byte code offset #7
    //   Java source line #289	-> byte code offset #14
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	17	0	this	StateImpl
    //   5	10	1	Ljava/lang/Object;	Object
    // Exception table:
    //   from	to	target	type
    //   7	13	14	finally
    //   14	16	14	finally
  }
  
  public boolean isResolved()
  {
    synchronized (monitor)
    {
      return (resolved) || (isEmpty());
    }
  }
  
  public void resolveConstraint(VersionConstraint constraint, BaseDescription supplier)
  {
    ((VersionConstraintImpl)constraint).setSupplier(supplier);
  }
  
  /**
   * @deprecated
   */
  public void resolveBundle(BundleDescription bundle, boolean status, BundleDescription[] hosts, ExportPackageDescription[] selectedExports, BundleDescription[] resolvedRequires, ExportPackageDescription[] resolvedImports)
  {
    resolveBundle(bundle, status, hosts, selectedExports, null, resolvedRequires, resolvedImports);
  }
  
  /**
   * @deprecated
   */
  public void resolveBundle(BundleDescription bundle, boolean status, BundleDescription[] hosts, ExportPackageDescription[] selectedExports, ExportPackageDescription[] substitutedExports, BundleDescription[] resolvedRequires, ExportPackageDescription[] resolvedImports)
  {
    resolveBundle(bundle, status, hosts, selectedExports, substitutedExports, null, resolvedRequires, resolvedImports, null, null);
  }
  
  public void resolveBundle(BundleDescription bundle, boolean status, BundleDescription[] hosts, ExportPackageDescription[] selectedExports, ExportPackageDescription[] substitutedExports, GenericDescription[] selectedCapabilities, BundleDescription[] resolvedRequires, ExportPackageDescription[] resolvedImports, GenericDescription[] resolvedCapabilities, Map<String, List<StateWire>> resolvedWires)
  {
    synchronized (monitor)
    {
      if (!resolving) {
        throw new IllegalStateException();
      }
      BundleDescriptionImpl modifiable = (BundleDescriptionImpl)bundle;
      
      getDelta().recordBundleResolved(modifiable, status);
      
      modifiable.setLazyLoaded(false);
      modifiable.setStateBit(1, status);
      if (status)
      {
        resolverErrors.remove(modifiable);
        resolvedBundles.add(modifiable);
      }
      else
      {
        resolvedBundles.remove(modifiable);
        modifiable.removeDependencies();
      }
      if ((selectedExports == null) || (resolvedRequires == null) || (resolvedImports == null)) {
        unresolveConstraints(modifiable);
      } else {
        resolveConstraints(modifiable, hosts, selectedExports, substitutedExports, selectedCapabilities, resolvedRequires, resolvedImports, resolvedCapabilities, resolvedWires);
      }
    }
  }
  
  public void removeBundleComplete(BundleDescription bundle)
  {
    synchronized (monitor)
    {
      if (!resolving) {
        throw new IllegalStateException();
      }
      getDelta().recordBundleRemovalComplete((BundleDescriptionImpl)bundle);
      removalPendings.remove(bundle);
    }
  }
  
  private void resolveConstraints(BundleDescriptionImpl bundle, BundleDescription[] hosts, ExportPackageDescription[] selectedExports, ExportPackageDescription[] substitutedExports, GenericDescription[] selectedCapabilities, BundleDescription[] resolvedRequires, ExportPackageDescription[] resolvedImports, GenericDescription[] resolvedCapabilities, Map<String, List<StateWire>> resolvedWires)
  {
    HostSpecificationImpl hostSpec = (HostSpecificationImpl)bundle.getHost();
    if ((hostSpec != null) && 
      (hosts != null))
    {
      hostSpec.setHosts(hosts);
      for (int i = 0; i < hosts.length; i++)
      {
        ((BundleDescriptionImpl)hosts[i]).addDependency(bundle, true);
        checkHostForSubstitutedExports((BundleDescriptionImpl)hosts[i], bundle);
      }
    }
    bundle.setSelectedExports(selectedExports);
    bundle.setResolvedRequires(resolvedRequires);
    bundle.setResolvedImports(resolvedImports);
    bundle.setSubstitutedExports(substitutedExports);
    bundle.setSelectedCapabilities(selectedCapabilities);
    bundle.setResolvedCapabilities(resolvedCapabilities);
    bundle.setStateWires(resolvedWires);
    
    bundle.addDependencies(hosts, true);
    bundle.addDependencies(resolvedRequires, true);
    bundle.addDependencies(resolvedImports, true);
    bundle.addDependencies(resolvedCapabilities, true);
  }
  
  private void checkHostForSubstitutedExports(BundleDescriptionImpl host, BundleDescriptionImpl fragment) {}
  
  private void unresolveConstraints(BundleDescriptionImpl bundle)
  {
    HostSpecificationImpl host = (HostSpecificationImpl)bundle.getHost();
    if (host != null) {
      host.setHosts(null);
    }
    bundle.setSelectedExports(null);
    bundle.setResolvedImports(null);
    bundle.setResolvedRequires(null);
    bundle.setSubstitutedExports(null);
    bundle.setSelectedCapabilities(null);
    bundle.setResolvedCapabilities(null);
    bundle.setStateWires(null);
    bundle.clearAddedDynamicImportPackages();
    
    NativeCodeSpecificationImpl nativeCode = (NativeCodeSpecificationImpl)bundle.getNativeCodeSpecification();
    if (nativeCode != null) {
      nativeCode.setSupplier(null);
    }
    ImportPackageSpecification[] imports = bundle.getImportPackages();
    for (int i = 0; i < imports.length; i++) {
      ((ImportPackageSpecificationImpl)imports[i]).setSupplier(null);
    }
    BundleSpecification[] requires = bundle.getRequiredBundles();
    for (int i = 0; i < requires.length; i++) {
      ((BundleSpecificationImpl)requires[i]).setSupplier(null);
    }
    GenericSpecification[] genericRequires = bundle.getGenericRequires();
    if (genericRequires.length > 0) {
      for (int i = 0; i < genericRequires.length; i++) {
        ((GenericSpecificationImpl)genericRequires[i]).setSupplers(null);
      }
    }
    bundle.removeDependencies();
  }
  
  private StateDelta resolve(boolean incremental, BundleDescription[] reResolve, BundleDescription[] triggers)
  {
    fullyLoad();
    synchronized (monitor)
    {
      if (resolver == null) {
        throw new IllegalStateException("no resolver set");
      }
      if (resolving) {
        throw new IllegalStateException("An attempt to start a nested resolve process has been detected.");
      }
      try
      {
        resolving = true;
        long start = 0L;
        if (StateManager.DEBUG_PLATFORM_ADMIN_RESOLVER) {
          start = System.currentTimeMillis();
        }
        if (!incremental)
        {
          resolved = false;
          reResolve = getBundles();
          if (removalPendings.size() > 0)
          {
            BundleDescription[] removed = internalGetRemovalPending();
            reResolve = mergeBundles(reResolve, removed);
          }
          flush(reResolve);
        }
        else
        {
          if ((resolved) && (reResolve == null))
          {
            localStateDeltaImpl1 = new StateDeltaImpl(this);
            
            resolving = false;return localStateDeltaImpl1;
          }
          if (developmentMode) {
            if (removalPendings.size() > 0)
            {
              BundleDescription[] removed = internalGetRemovalPending();
              reResolve = mergeBundles(reResolve, removed);
            }
          }
          if (reResolve == null) {
            reResolve = internalGetRemovalPending();
          }
          if (triggers == null)
          {
            Set<BundleDescription> triggerSet = new HashSet();
            Collection<BundleDescription> closure = getDependencyClosure(Arrays.asList(reResolve));
            for (Iterator localIterator = closure.iterator(); localIterator.hasNext();)
            {
              BundleDescription toRefresh = (BundleDescription)localIterator.next();
              Bundle bundle = toRefresh.getBundle();
              if ((bundle != null) && ((bundle.getState() & 0x7) == 0)) {
                triggerSet.add(toRefresh);
              }
            }
            triggers = (BundleDescription[])triggerSet.toArray(new BundleDescription[triggerSet.size()]);
          }
        }
        Headers[] tmpPlatformProperties = new Headers[platformProperties.length];
        for (int i = 0; i < platformProperties.length; i++)
        {
          tmpPlatformProperties[i] = new Headers(platformProperties[i].size());
          for (Enumeration<Object> keys = platformProperties[i].keys(); keys.hasMoreElements();)
          {
            Object key = keys.nextElement();
            tmpPlatformProperties[i].put(key, platformProperties[i].get(key));
          }
        }
        ResolverHookFactory currentFactory = hookFactory;
        if (currentFactory != null)
        {
          Collection<BundleRevision> triggerRevisions = Collections.unmodifiableCollection(triggers == null ? Collections.EMPTY_LIST : Arrays.asList(triggers));
          begin(triggerRevisions);
        }
        ResolverHookException error = null;
        try
        {
          resolver.resolve(reResolve, tmpPlatformProperties);
        }
        catch (ResolverHookException e)
        {
          error = e;
          resolverErrors.clear();
        }
        resolved = (removalPendings.size() == 0);
        
        StateDeltaImpl savedChanges = changes == null ? new StateDeltaImpl(this) : changes;
        savedChanges.setResolverHookException(error);
        changes = new StateDeltaImpl(this);
        if (StateManager.DEBUG_PLATFORM_ADMIN_RESOLVER)
        {
          long time = System.currentTimeMillis() - start;
          Debug.println("Time spent resolving: " + time);
          cumulativeTime += time;
          FrameworkDebugOptions.getDefault().setOption("org.eclipse.core.runtime.adaptor/resolver/timing/value", Long.toString(cumulativeTime));
        }
        if (savedChanges.getChanges().length > 0) {
          updateTimeStamp();
        }
        StateDeltaImpl localStateDeltaImpl1 = savedChanges;
        
        resolving = false;return localStateDeltaImpl1;
      }
      finally
      {
        resolving = false;
      }
    }
  }
  
  private BundleDescription[] mergeBundles(BundleDescription[] reResolve, BundleDescription[] removed)
  {
    if (reResolve == null) {
      return removed;
    }
    if (reResolve.length == 0) {
      return reResolve;
    }
    List<BundleDescription> result = new ArrayList(reResolve.length + removed.length);
    for (int i = 0; i < reResolve.length; i++) {
      result.add(reResolve[i]);
    }
    for (int i = 0; i < removed.length; i++)
    {
      boolean found = false;
      for (int j = 0; j < reResolve.length; j++) {
        if (removed[i] == reResolve[j])
        {
          found = true;
          break;
        }
      }
      if (!found) {
        result.add(removed[i]);
      }
    }
    return (BundleDescription[])result.toArray(new BundleDescription[result.size()]);
  }
  
  private void flush(BundleDescription[] bundles)
  {
    resolver.flush();
    resolved = false;
    resolverErrors.clear();
    if (resolvedBundles.isEmpty()) {
      return;
    }
    for (int i = 0; i < bundles.length; i++) {
      resolveBundle(bundles[i], false, null, null, null, null, null);
    }
    resolvedBundles.clear();
  }
  
  public StateDelta resolve()
  {
    return resolve(true, null, null);
  }
  
  public StateDelta resolve(boolean incremental)
  {
    return resolve(incremental, null, null);
  }
  
  public StateDelta resolve(BundleDescription[] reResolve)
  {
    return resolve(true, reResolve, null);
  }
  
  public StateDelta resolve(BundleDescription[] resolve, boolean discard)
  {
    BundleDescription[] reResolve = discard ? resolve : new BundleDescription[0];
    BundleDescription[] triggers = discard ? null : resolve;
    return resolve(true, reResolve, triggers);
  }
  
  public void setOverrides(Object value)
  {
    throw new UnsupportedOperationException();
  }
  
  public void setResolverHookFactory(ResolverHookFactory hookFactory)
  {
    synchronized (monitor)
    {
      if (this.hookFactory != null) {
        throw new IllegalStateException("Resolver hook factory is already set.");
      }
      this.hookFactory = hookFactory;
    }
  }
  
  private ResolverHook begin(Collection<BundleRevision> triggers)
  {
    ResolverHookFactory current;
    synchronized (monitor)
    {
      current = hookFactory;
    }
    ResolverHookFactory current;
    ResolverHook newHook = current.begin(triggers);
    synchronized (monitor)
    {
      hook = newHook;
    }
    return newHook;
  }
  
  /* Error */
  ResolverHookFactory getResolverHookFactory()
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 1028	org/eclipse/osgi/internal/resolver/StateImpl:monitor	Ljava/lang/Object;
    //   4: dup
    //   5: astore_1
    //   6: monitorenter
    //   7: aload_0
    //   8: getfield 1043	org/eclipse/osgi/internal/resolver/StateImpl:hookFactory	Lorg/osgi/framework/hooks/resolver/ResolverHookFactory;
    //   11: aload_1
    //   12: monitorexit
    //   13: areturn
    //   14: aload_1
    //   15: monitorexit
    //   16: athrow
    // Line number table:
    //   Java source line #586	-> byte code offset #0
    //   Java source line #587	-> byte code offset #7
    //   Java source line #586	-> byte code offset #14
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	17	0	this	StateImpl
    //   5	10	1	Ljava/lang/Object;	Object
    // Exception table:
    //   from	to	target	type
    //   7	13	14	finally
    //   14	16	14	finally
  }
  
  /* Error */
  public ResolverHook getResolverHook()
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 1028	org/eclipse/osgi/internal/resolver/StateImpl:monitor	Ljava/lang/Object;
    //   4: dup
    //   5: astore_1
    //   6: monitorenter
    //   7: aload_0
    //   8: getfield 1042	org/eclipse/osgi/internal/resolver/StateImpl:hook	Lorg/osgi/framework/hooks/resolver/ResolverHook;
    //   11: aload_1
    //   12: monitorexit
    //   13: areturn
    //   14: aload_1
    //   15: monitorexit
    //   16: athrow
    // Line number table:
    //   Java source line #592	-> byte code offset #0
    //   Java source line #593	-> byte code offset #7
    //   Java source line #592	-> byte code offset #14
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	17	0	this	State
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