org.eclipse.osgi_3.7.2.v20120110-1415

("version");
        if (versionString != null) {
          attrs.put("version", Version.parseVersion(versionString));
        }
        desc.setAttributes(attrs);
        results.add(desc);
      }
    }
    return results;
  }
  
  private static NativeCodeSpecification createNativeCode(ManifestElement[] nativeCode)
    throws BundleException
  {
    if (nativeCode == null) {
      return null;
    }
    NativeCodeSpecificationImpl result = new NativeCodeSpecificationImpl();
    result.setName("Bundle-NativeCode");
    int length = nativeCode.length;
    if ((length > 0) && (nativeCode[(length - 1)].getValue().equals("*")))
    {
      result.setOptional(true);
      length--;
    }
    NativeCodeDescriptionImpl[] suppliers = new NativeCodeDescriptionImpl[length];
    for (int i = 0; i < length; i++) {
      suppliers[i] = createNativeCodeDescription(nativeCode[i]);
    }
    result.setPossibleSuppliers(suppliers);
    return result;
  }
  
  private static NativeCodeDescriptionImpl createNativeCodeDescription(ManifestElement manifestElement)
    throws BundleException
  {
    NativeCodeDescriptionImpl result = new NativeCodeDescriptionImpl();
    result.setName("Bundle-NativeCode");
    result.setNativePaths(manifestElement.getValueComponents());
    result.setOSNames(manifestElement.getAttributes("osname"));
    result.setProcessors(manifestElement.getAttributes("processor"));
    result.setOSVersions(createVersionRanges(manifestElement.getAttributes("osversion")));
    result.setLanguages(manifestElement.getAttributes("language"));
    try
    {
      result.setFilter(manifestElement.getAttribute("selection-filter"));
    }
    catch (InvalidSyntaxException e)
    {
      String message = NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, "Bundle-NativeCode", manifestElement.toString());
      throw new BundleException(message + " : " + "selection-filter", 3, e);
    }
    return result;
  }
  
  private static VersionRange[] createVersionRanges(String[] ranges)
  {
    if (ranges == null) {
      return null;
    }
    VersionRange[] result = new VersionRange[ranges.length];
    for (int i = 0; i < result.length; i++) {
      result[i] = new VersionRange(ranges[i]);
    }
    return result;
  }
  
  private static VersionRange getVersionRange(String versionRange)
  {
    if (versionRange == null) {
      return null;
    }
    return new VersionRange(versionRange);
  }
  
  public static void checkImportExportSyntax(String headerKey, ManifestElement[] elements, boolean export, boolean dynamic, boolean jreBundle)
    throws BundleException
  {
    if (elements == null) {
      return;
    }
    int length = elements.length;
    Set<String> packages = new HashSet(length);
    for (int i = 0; i < length; i++)
    {
      String[] packageNames = elements[i].getValueComponents();
      for (int j = 0; j < packageNames.length; j++)
      {
        if ((!export) && (!dynamic) && (packages.contains(packageNames[j])))
        {
          String message = NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, headerKey, elements[i].toString());
          throw new BundleException(message + " : " + NLS.bind(StateMsg.HEADER_PACKAGE_DUPLICATES, packageNames[j]), 3);
        }
        if ((!jreBundle) && (packageNames[j].startsWith("java.")))
        {
          String message = NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, headerKey, elements[i].toString());
          throw new BundleException(message + " : " + NLS.bind(StateMsg.HEADER_PACKAGE_JAVA, packageNames[j]), 3);
        }
        packages.add(packageNames[j]);
      }
      String version = elements[i].getAttribute("version");
      if (version != null)
      {
        String specVersion = elements[i].getAttribute("specification-version");
        if ((specVersion != null) && (!specVersion.equals(version))) {
          throw new BundleException(NLS.bind(StateMsg.HEADER_VERSION_ERROR, "version", "specification-version"), 3);
        }
      }
      if (export)
      {
        if (elements[i].getAttribute("bundle-symbolic-name") != null)
        {
          String message = NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, headerKey, elements[i].toString());
          throw new BundleException(message + " : " + NLS.bind(StateMsg.HEADER_EXPORT_ATTR_ERROR, "bundle-symbolic-name", "Export-Package"), 3);
        }
        if (elements[i].getAttribute("bundle-version") != null)
        {
          String message = NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, headerKey, elements[i].toString());
          throw new BundleException(NLS.bind(message + " : " + StateMsg.HEADER_EXPORT_ATTR_ERROR, "bundle-version", "Export-Package"), 3);
        }
      }
    }
  }
  
  private static void checkForDuplicateDirectivesAttributes(String headerKey, ManifestElement[] elements)
    throws BundleException
  {
    for (int i = 0; i < elements.length; i++)
    {
      Enumeration<String> directiveKeys = elements[i].getDirectiveKeys();
      if (directiveKeys != null) {
        while (directiveKeys.hasMoreElements())
        {
          String key = (String)directiveKeys.nextElement();
          String[] directives = elements[i].getDirectives(key);
          if (directives.length > 1)
          {
            String message = NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, headerKey, elements[i].toString());
            throw new BundleException(NLS.bind(message + " : " + StateMsg.HEADER_DIRECTIVE_DUPLICATES, key), 3);
          }
        }
      }
      Enumeration<String> attrKeys = elements[i].getKeys();
      if (attrKeys != null) {
        while (attrKeys.hasMoreElements())
        {
          String key = (String)attrKeys.nextElement();
          String[] attrs = elements[i].getAttributes(key);
          if (attrs.length > 1)
          {
            String message = NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, headerKey, elements[i].toString());
            throw new BundleException(message + " : " + NLS.bind(StateMsg.HEADER_ATTRIBUTE_DUPLICATES, key), 3);
          }
        }
      }
    }
  }
  
  private static void checkExtensionBundle(String headerKey, ManifestElement[] elements)
    throws BundleException
  {
    if ((elements.length == 0) || (elements[0].getDirective("extension") == null)) {
      return;
    }
    String hostName = elements[0].getValue();
    if ((!hostName.equals("system.bundle")) && (!hostName.equals(Constants.getInternalSymbolicName())))
    {
      String message = NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, headerKey, elements[0].toString());
      throw new BundleException(message + " : " + NLS.bind(StateMsg.HEADER_EXTENSION_ERROR, hostName), 3);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.resolver.StateBuilder
 * 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.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.eclipse.osgi.service.resolver.BundleDelta;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.ResolverHookException;
import org.eclipse.osgi.service.resolver.State;
import org.eclipse.osgi.service.resolver.StateDelta;

final class StateDeltaImpl
  implements StateDelta
{
  private final State state;
  private final Map<BundleDescription, BundleDelta> changes = new HashMap();
  private ResolverHookException error;
  
  public StateDeltaImpl(State state)
  {
    this.state = state;
  }
  
  /* Error */
  public BundleDelta[] getChanges()
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 120	org/eclipse/osgi/internal/resolver/StateDeltaImpl:changes	Ljava/util/Map;
    //   4: dup
    //   5: astore_1
    //   6: monitorenter
    //   7: aload_0
    //   8: getfield 120	org/eclipse/osgi/internal/resolver/StateDeltaImpl:changes	Ljava/util/Map;
    //   11: invokeinterface 139 1 0
    //   16: aload_0
    //   17: getfield 120	org/eclipse/osgi/internal/resolver/StateDeltaImpl:changes	Ljava/util/Map;
    //   20: invokeinterface 138 1 0
    //   25: anewarray 70	org/eclipse/osgi/service/resolver/BundleDelta
    //   28: invokeinterface 132 2 0
    //   33: checkcast 59	[Lorg/eclipse/osgi/service/resolver/BundleDelta;
    //   36: aload_1
    //   37: monitorexit
    //   38: areturn
    //   39: aload_1
    //   40: monitorexit
    //   41: athrow
    // Line number table:
    //   Java source line #33	-> byte code offset #0
    //   Java source line #34	-> byte code offset #7
    //   Java source line #33	-> byte code offset #39
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	42	0	this	StateDeltaImpl
    //   5	35	1	Ljava/lang/Object;	Object
    // Exception table:
    //   from	to	target	type
    //   7	38	39	finally
    //   39	41	39	finally
  }
  
  public BundleDelta[] getChanges(int mask, boolean exact)
  {
    synchronized (changes)
    {
      List<BundleDelta> result = new ArrayList();
      for (Iterator<BundleDelta> changesIter = changes.values().iterator(); changesIter.hasNext();)
      {
        BundleDelta change = (BundleDelta)changesIter.next();
        if ((mask == change.getType()) || ((!exact) && ((change.getType() & mask) != 0))) {
          result.add(change);
        }
      }
      return (BundleDelta[])result.toArray(new BundleDelta[result.size()]);
    }
  }
  
  public State getState()
  {
    return state;
  }
  
  public ResolverHookException getResovlerHookException()
  {
    return error;
  }
  
  void setResolverHookException(ResolverHookException error)
  {
    this.error = error;
  }
  
  void recordBundleAdded(BundleDescriptionImpl added)
  {
    synchronized (changes)
    {
      BundleDeltaImpl change = (BundleDeltaImpl)changes.get(added);
      if (change == null)
      {
        changes.put(added, new BundleDeltaImpl(added, 1));
        return;
      }
      if (change.getType() == 2)
      {
        changes.remove(added);
        return;
      }
      int newType = change.getType();
      if ((newType & 0x2) != 0) {
        newType &= 0xFFFFFFFD;
      }
      change.setType(newType | 0x1);
      change.setBundle(added);
    }
  }
  
  void recordBundleUpdated(BundleDescriptionImpl updated)
  {
    synchronized (changes)
    {
      BundleDeltaImpl change = (BundleDeltaImpl)changes.get(updated);
      if (change == null)
      {
        changes.put(updated, new BundleDeltaImpl(updated, 4));
        return;
      }
      if ((change.getType() & 0x3) != 0) {
        return;
      }
      change.setType(change.getType() | 0x4);
      change.setBundle(updated);
    }
  }
  
  void recordBundleRemoved(BundleDescriptionImpl removed)
  {
    synchronized (changes)
    {
      BundleDeltaImpl change = (BundleDeltaImpl)changes.get(removed);
      if (change == null)
      {
        changes.put(removed, new BundleDeltaImpl(removed, 2));
        return;
      }
      if (change.getType() == 1)
      {
        changes.remove(removed);
        return;
      }
      int newType = change.getType();
      if ((newType & 0x1) != 0) {
        newType &= 0xFFFFFFFE;
      }
      change.setType(newType | 0x2);
    }
  }
  
  void recordBundleRemovalPending(BundleDescriptionImpl removed)
  {
    synchronized (changes)
    {
      BundleDeltaImpl change = (BundleDeltaImpl)changes.get(removed);
      if (change == null)
      {
        changes.put(removed, new BundleDeltaImpl(removed, 128));
        return;
      }
      int newType = change.getType();
      if ((newType & 0x100) != 0) {
        newType &= 0xFEFF;
      }
      change.setType(newType | 0x80);
    }
  }
  
  void recordBundleRemovalComplete(BundleDescriptionImpl removed)
  {
    synchronized (changes)
    {
      BundleDeltaImpl change = (BundleDeltaImpl)changes.get(removed);
      if (change == null)
      {
        changes.put(removed, new BundleDeltaImpl(removed, 256));
        return;
      }
      int newType = change.getType();
      if ((newType & 0x80) != 0) {
        newType &= 0xFF7F;
      }
      change.setType(newType | 0x100);
    }
  }
  
  void recordBundleResolved(BundleDescriptionImpl resolved, boolean result)
  {
    synchronized (changes)
    {
      if (resolved.isResolved() == result) {
        return;
      }
      BundleDeltaImpl change = (BundleDeltaImpl)changes.get(resolved);
      int newType = result ? 8 : 16;
      if (change == null)
      {
        change = new BundleDeltaImpl(resolved, newType);
        changes.put(resolved, change);
        return;
      }
      newType |= change.getType() & 0xFFFFFFE7;
      change.setType(newType);
      change.setBundle(resolved);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.resolver.StateDeltaImpl
 * 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.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.osgi.internal.baseadaptor.ArrayMap;
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.NativeCodeSpecification;
import org.eclipse.osgi.service.resolver.State;
import org.eclipse.osgi.service.resolver.StateHelper;
import org.eclipse.osgi.service.resolver.VersionConstraint;
import org.osgi.framework.hooks.resolver.ResolverHook;
import org.osgi.framework.hooks.resolver.ResolverHookFactory;
import org.osgi.framework.wiring.BundleCapability;
import org.osgi.framework.wiring.BundleRevision;

public final class StateHelperImpl
  implements StateHelper
{
  private static final StateHelper instance = new StateHelperImpl();
  
  public BundleDescription[] getDependentBundles(BundleDescription[] bundles)
  {
    if ((bundles == null) || (bundles.length == 0)) {
      return new BundleDescription[0];
    }
    Set<BundleDescription> reachable = new HashSet(bundles.length);
    for (int i = 0; i < bundles.length; i++) {
      if (bundles[i].isResolved()) {
        addDependentBundles(bundles[i], reachable);
      }
    }
    return (BundleDescription[])reachable.toArray(new BundleDescription[reachable.size()]);
  }
  
  private void addDependentBundles(BundleDescription bundle, Set<BundleDescription> reachable)
  {
    if (reachable.contains(bundle)) {
      return;
    }
    reachable.add(bundle);
    BundleDescription[] dependents = bundle.getDependents();
    for (int i = 0; i < dependents.length; i++) {
      addDependentBundles(dependents[i], reachable);
    }
  }
  
  public BundleDescription[] getPrerequisites(BundleDescription[] bundles)
  {
    if ((bundles == null) || (bundles.length == 0)) {
      return new BundleDescription[0];
    }
    Set<BundleDescription> reachable = new HashSet(bundles.length);
    for (int i = 0; i < bundles.length; i++) {
      addPrerequisites(bundles[i], reachable);
    }
    return (BundleDescription[])reachable.toArray(new BundleDescription[reachable.size()]);
  }
  
  private void addPrerequisites(BundleDescription bundle, Set<BundleDescription> reachable)
  {
    if (reachable.contains(bundle)) {
      return;
    }
    reachable.add(bundle);
    List<BundleDescription> depList = ((BundleDescriptionImpl)bundle).getBundleDependencies();
    BundleDescription[] dependencies = (BundleDescription[])depList.toArray(new BundleDescription[depList.size()]);
    for (int i = 0; i < dependencies.length; i++) {
      addPrerequisites(dependencies[i], reachable);
    }
  }
  
  private Map<String, List<ExportPackageDescription>> getExportedPackageMap(State state)
  {
    Map<String, List<ExportPackageDescription>> result = new HashMap();
    BundleDescription[] bundles = state.getBundles();
    for (int i = 0; i < bundles.length; i++)
    {
      ExportPackageDescription[] packages = bundles[i].getExportPackages();
      for (int j = 0; j < packages.length; j++)
      {
        ExportPackageDescription description = packages[j];
        List<ExportPackageDescription> exports = (List)result.get(description.getName());
        if (exports == null)
        {
          exports = new ArrayList();
          result.put(description.getName(), exports);
        }
        exports.add(description);
      }
    }
    return result;
  }
  
  private Map<String, List<GenericDescription>> getGenericsMap(State state, boolean resolved)
  {
    Map<String, List<GenericDescription>> result = new HashMap();
    BundleDescription[] bundles = state.getBundles();
    for (int i = 0; i < bundles.length; i++) {
      if ((!resolved) || (bundles[i].isResolved()))
      {
        GenericDescription[] generics = bundles[i].getGenericCapabilities();
        for (int j = 0; j < generics.length; j++)
        {
          GenericDescription description = generics[j];
          List<GenericDescription> genericList = (List)result.get(description.getName());
          if (genericList == null)
          {
            genericList = new ArrayList(1);
            result.put(description.getName(), genericList);
          }
          genericList.add(description);
        }
      }
    }
    return result;
  }
  
  private VersionConstraint[] getUnsatisfiedLeaves(State state, BundleDescription[] bundles, ResolverHook hook)
  {
    Map<String, List<ExportPackageDescription>> packages = getExportedPackageMap(state);
    Map<String, List<GenericDescription>> generics = getGenericsMap(state, false);
    Set<VersionConstraint> result = new HashSet();
    List<BundleDescription> bundleList = new ArrayList(bundles.length);
    for (int i = 0; i < bundles.length; i++) {
      bundleList.add(bundles[i]);
    }
    for (int i = 0; i < bundleList.size(); i++)
    {
      BundleDescription description = (BundleDescription)bundleList.get(i);
      VersionConstraint[] constraints = getUnsatisfiedConstraints(description, hook);
      for (int j = 0; j < constraints.length; j++)
      {
        VersionConstraint constraint = constraints[j];
        Collection<BaseDescription> satisfied = null;
        if (((constraint instanceof BundleSpecification)) || ((constraint instanceof HostSpecification)))
        {
          BundleDescription[] suppliers = state.getBundles(constraint.getName());
          satisfied = getPossibleCandidates(constraint, suppliers, (constraint instanceof HostSpecification) ? "osgi.wiring.host" : null, hook, false);
        }
        else if ((constraint instanceof ImportPackageSpecification))
        {
          List<ExportPackageDescription> exports = (List)packages.get(constraint.getName());
          if (exports != null) {
            satisfied = getPossibleCandidates(constraint, (BaseDescription[])exports.toArray(new BaseDescription[exports.size()]), null, hook, false);
          }
        }
        else if ((constraint instanceof GenericSpecification))
        {
          List<GenericDescription> genericSet = (List)generics.get(constraint.getName());
          if (genericSet != null) {
            satisfied = getPossibleCandidates(constraint, (BaseDescription[])genericSet.toArray(new BaseDescription[genericSet.size()]), null, hook, false);
          }
        }
        if ((satisfied == null) || (satisfied.isEmpty())) {
          result.add(constraint);
        } else {
          for (Iterator localIterator = satisfied.iterator(); localIterator.hasNext();)
          {
            BaseDescription baseDescription = (BaseDescription)localIterator.next();
            if ((!baseDescription.getSupplier().isResolved()) && (!bundleList.contains(baseDescription.getSupplier())))
            {
              bundleList.add(baseDescription.getSupplier());
              
              break;
            }
          }
        }
      }
    }
    return (VersionConstraint[])result.toArray(new VersionConstraint[result.size()]);
  }
  
  public VersionConstraint[] getUnsatisfiedLeaves(BundleDescription[] bundles)
  {
    if (bundles.length == 0) {
      return new VersionConstraint[0];
    }
    State state = bundles[0].getContainingState();
    ResolverHook hook = beginHook(state, Arrays.asList(bundles));
    try
    {
      return getUnsatisfiedLeaves(state, bundles, hook);
    }
    finally
    {
      if (hook != null) {
        hook.end();
      }
    }
  }
  
  private ResolverHook beginHook(State state, Collection<BundleRevision> triggers)
  {
    if (!(state instanceof StateImpl)) {
      return null;
    }
    ResolverHookFactory hookFactory = ((StateImpl)state).getResolverHookFactory();
    return hookFactory == null ? null : hookFactory.begin(triggers);
  }
  
  public VersionConstraint[] getUnsatisfiedConstraints(BundleDescription bundle)
  {
    ResolverHook hook = beginHook(bundle.getContainingState(), Arrays.asList(new BundleRevision[] { bundle }));
    try
    {
      return getUnsatisfiedConstraints(bundle, hook);
    }
    finally
    {
      if (hook != null) {
        hook.end();
      }
    }
  }
  
  private VersionConstraint[] getUnsatisfiedConstraints(BundleDescription bundle, ResolverHook hook)
  {
    State containingState = bundle.getContainingState();
    if (containingState == null) {
      throw new IllegalStateException("Does not belong to a state");
    }
    List<VersionConstraint> unsatisfied = new ArrayList();
    HostSpecification host = bundle.getHost();
    if ((host != null) && 
      (!host.isResolved()) && (!isBundleConstraintResolvable(host, "osgi.wiring.host", hook))) {
      unsatisfied.add(host);
    }
    BundleSpecification[] requiredBundles = bundle.getRequiredBundles();
    for (int i = 0; i < requiredBundles.length; i++) {
      if ((!requiredBundles[i].isResolved()) && (!isBundleConstraintResolvable(requiredBundles[i], null, hook))) {
        unsatisfied.add(requiredBundles[i]);
      }
    }
    ImportPackageSpecification[] packages = bundle.getImportPackages();
    for (int i = 0; i < packages.length; i++) {
      if ((!packages[i].isResolved()) && (!isResolvable(packages[i], hook)) && (
        (!bundle.isResolved()) || 
        
        ("optional".equals(packages[i].getDirective("resolution"))))) {
        unsatisfied.add(packages[i]);
      }
    }
    GenericSpecification[] generics = bundle.getGenericRequires();
    for (int i = 0; i < generics.length; i++) {
      if ((!generics[i].isResolved()) && (!isResolvable(generics[i], hook))) {
        unsatisfied.add(generics[i]);
      }
    }
    NativeCodeSpecification nativeCode = bundle.getNativeCodeSpecification();
    if ((nativeCode != null) && (!nativeCode.isResolved())) {
      unsatisfied.add(nativeCode);
    }
    return (VersionConstraint[])unsatisfied.toArray(new VersionConstraint[unsatisfied.size()]);
  }
  
  private ArrayMap<BundleCapability, BaseDescription> asArrayMap(List<BaseDescription> descriptions, String namespace)
  {
    List<BundleCapability> capabilities = new ArrayList(descriptions.size());
    for (Iterator localIterator = descriptions.iterator(); localIterator.hasNext();)
    {
      BaseDescription description = (BaseDescription)localIterator.next();
      capabilities.add(((BaseDescriptionImpl)description).getCapability(namespace));
    }
    return new ArrayMap(capabilities, descriptions);
  }
  
  private List<BaseDescription> getPossibleCandidates(VersionConstraint constraint, BaseDescription[] descriptions, String namespace, ResolverHook hook, boolean resolved)
  {
    List<BaseDescription> candidates = new ArrayList();
    for (int i = 0; i < descriptions.length; i++) {
      if (((!resolved) || (descriptions[i].getSupplier().isResolved())) && (constraint.isSatisfiedBy(descriptions[i]))) {
        candidates.add(descriptions[i]);
      }
    }
    if (hook != null) {
      hook.filterMatches(constraint.getRequirement(), asArrayMap(candidates, namespace));
    }
    return candidates;
  }
  
  public boolean isResolvable(ImportPackageSpecification constraint)
  {
    ResolverHook hook = beginHook(constraint.getBundle().getContainingState(), Arrays.asList(new BundleRevision[] { constraint.getBundle() }));
    try
    {
      return isResolvable(constraint, hook);
    }
    finally
    {
      if (hook != null) {
        hook.end();
      }
    }
  }
  
  private boolean isResolvable(ImportPackageSpecification constraint, ResolverHook hook)
  {
    ExportPackageDescription[] exports = constraint.getBundle().getContainingState().getExportedPackages();
    return getPossibleCandidates(constraint, exports, null, hook, true).size() > 0;
  }
  
  private boolean isResolvable(GenericSpecification constraint, ResolverHook hook)
  {
    Map<String, List<GenericDescription>> genericCapabilities = getGenericsMap(constraint.getBundle().getContainingState(), true);
    List<GenericDescription> genericList = (List)genericCapabilities.get(constraint.getName());
    if (genericList == null) {
      return false;
    }
    return getPossibleCandidates(constraint, (BaseDescription[])genericList.toArray(new BaseDescription[genericList.size()]), null, hook, true).size() > 0;
  }
  
  public boolean isResolvable(BundleSpecification specification)
  {
    return isBundleConstraintResolvable(specification, null);
  }
  
  public boolean isResolvable(HostSpecification specification)
  {
    return isBundleConstraintResolvable(specification, "osgi.wiring.host");
  }
  
  private boolean isBundleConstraintResolvable(VersionConstraint constraint, String namespace)
  {
    ResolverHook hook = beginHook(constraint.getBundle().getContainingState(), Arrays.asList(new BundleRevision[] { constraint.getBundle() }));
    try
    {
      return isBundleConstraintResolvable(constraint, namespace, hook);
    }
    finally
    {
      if (hook != null) {
        hook.end();
      }
    }
  }
  
  private boolean isBundleConstraintResolvable(VersionConstraint constraint, String namespace, ResolverHook hook)
  {
    BundleDescription[] availableBundles = constraint.getBundle().getContainingState().getBundles(constraint.getName());
    return getPossibleCandidates(constraint, availableBundles, namespace, hook, true).size() > 0;
  }
  
  public Object[][] sortBundles(BundleDescription[] toSort)
  {
    List<Object[]> references = new ArrayList(toSort.length);
    for (int i = 0; i < toSort.length; i++) {
      if (toSort[i].isResolved()) {
        buildReferences(toSort[i], references);
      }
    }
    Object[][] cycles = ComputeNodeOrder.computeNodeOrder(toSort, (Object[][])references.toArray(new Object[references.size()][]));
    if (cycles.length == 0) {
      return cycles;
    }
    for (int i = 0; i < cycles.length; i++) {
      for (int j = 0; j < cycles[i].length; j++)
      {
        BundleDescription fragment = (BundleDescription)cycles[i][j];
        if (fragment.getHost() != null)
        {
          BundleDescription host = (BundleDescription)fragment.getHost().getSupplier();
          if (host != null) {
            fixFragmentOrder(host, fragment, toSort);
          }
        }
      }
    }
    return cycles;
  }
  
  private void fixFragmentOrder(BundleDescription host, BundleDescription fragment, BundleDescription[] toSort)
  {
    int hostIndex = -1;
    int fragIndex = -1;
    for (int i = 0; (i < toSort.length) && ((hostIndex == -1) || (fragIndex == -1)); i++) {
      if (toSort[i] == host) {
        hostIndex = i;
      } else if (toSort[i] == fragment) {
        fragIndex = i;
      }
    }
    if ((fragIndex > -1) && (fragIndex < hostIndex))
    {
      for (int i = fragIndex; i < hostIndex; i++) {
        toSort[i] = toSort[(i + 1)];
      }
      toSort[hostIndex] = fragment;
    }
  }
  
  private void buildReferences(BundleDescription description, List<Object[]> references)
  {
    HostSpecification host = description.getHost();
    if (host != null)
    {
      if (host.getHosts() != null)
      {
        BundleDescription[] hosts = host.getHosts();
        for (int i = 0; i < hosts.length; i++) {
          if (hosts[i] != description) {
            references.add(new Object[] { description, hosts[i] });
          }
        }
      }
    }
    else {
      buildReferences(description, ((BundleDescriptionImpl)description).getBundleDependencies(), references);
    }
  }
  
  private void buildReferences(BundleDescription description, List<BundleDescription> dependencies, List<Object[]> references)
  {
    for (Iterator<BundleDescription> iter = dependencies.iterator(); iter.hasNext();) {
      addReference(description, (BundleDescription)iter.next(), references);
    }
  }
  
  private void addReference(BundleDescription description, BundleDescription reference, List<Object[]> references)
  {
    if ((description == reference) || (reference == null)) {
      return;
    }
    BundleDescription[] fragments = reference.getFragments();
    for (int i = 0; i < fragments.length; i++) {
      if (fragments[i].isResolved())
      {
        ExportPackageDescription[] exports = fragments[i].getExportPackages();
        if (exports.length > 0) {
          references.add(new Object[] { description, fragments[i] });
        }
      }
    }
    references.add(new Object[] { description, reference });
  }
  
  public ExportPackageDescription[] getVisiblePackages(BundleDescription bundle)
  {
    return getVisiblePackages(bundle, 0);
  }
  
  public ExportPackageDescription[] getVisiblePackages(BundleDescription bundle, int options)
  {
    StateImpl state = (StateImpl)bundle.getContainingState();
    boolean strict = false;
    if (state != null) {
      strict = state.inStrictMode();
    }
    BundleDescription host = (BundleDescription)(bundle.getHost() == null ? bundle : bundle.getHost().getSupplier());
    List<ExportPackageDescription> orderedPkgList = new ArrayList();
    Set<ExportPackageDescription> pkgSet = new HashSet();
    Set<String> importList = new HashSet();
    
    ImportsHolder imports = new ImportsHolder(bundle, options);
    for (int i = 0; i < imports.getSize(); i++)
    {
      ExportPackageDescription pkgSupplier = imports.getSupplier(i);
      if ((pkgSupplier != null) && (pkgSupplier.getExporter() != host))
      {
        if ((!isSystemExport(pkgSupplier, options)) && (!pkgSet.contains(pkgSupplier)))
        {
          orderedPkgList.add(pkgSupplier);
          pkgSet.add(pkgSupplier);
        }
        BundleSpecification[] requires = pkgSupplier.getExporter().getRequiredBundles();
        Set<BundleDescription> visited = new HashSet();
        visited.add(bundle);
        Set<String> importNames = new HashSet(1);
        importNames.add(imports.getName(i));
        for (int j = 0; j < requires.length; j++)
        {
          BundleDescription bundleSupplier = (BundleDescription)requires[j].getSupplier();
          if (bundleSupplier != null) {
            getPackages(bundleSupplier, bundle.getSymbolicName(), importList, orderedPkgList, pkgSet, visited, strict, importNames, options);
          }
        }
        importList.add(imports.getName(i));
      }
    }
    RequiresHolder requires = new RequiresHolder(bundle, options);
    Set<BundleDescription> visited = new HashSet(requires.getSize());
    visited.add(bundle);
    for (int i = 0; i < requires.getSize(); i++)
    {
      BundleDescription bundleSupplier = requires.getSupplier(i);
      if (bundleSupplier != null) {
        getPackages(bundleSupplier, bundle.getSymbolicName(), importList, orderedPkgList, pkgSet, visited, strict, null, options);
      }
    }
    return (ExportPackageDescription[])orderedPkgList.toArray(new ExportPackageDescription[orderedPkgList.size()]);
  }
  
  private void getPackages(BundleDescription requiredBundle, String symbolicName, Set<String> importList, List<ExportPackageDescription> orderedPkgList, Set<ExportPackageDescription> pkgSet, Set<BundleDescription> visited, boolean strict, Set<String> pkgNames, int options)
  {
    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.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];
  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 KeyedHashS
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

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