org.eclipse.osgi_3.8.2.v20130124-134944

ctionary[] getPlatformProperties()
  {
    return target.getPlatformProperties();
  }
  
  public ExportPackageDescription linkDynamicImport(BundleDescription importingBundle, String requestedPackage)
  {
    throw new UnsupportedOperationException();
  }
  
  public void setTimeStamp(long timeStamp)
  {
    throw new UnsupportedOperationException();
  }
  
  public ExportPackageDescription[] getSystemPackages()
  {
    return target.getSystemPackages();
  }
  
  public void addResolverError(BundleDescription bundle, int type, String data, VersionConstraint unsatisfied)
  {
    throw new UnsupportedOperationException();
  }
  
  public ResolverError[] getResolverErrors(BundleDescription bundle)
  {
    return target.getResolverErrors(bundle);
  }
  
  public void removeResolverErrors(BundleDescription bundle)
  {
    throw new UnsupportedOperationException();
  }
  
  public StateHelper getStateHelper()
  {
    return StateHelperImpl.getInstance();
  }
  
  public long getHighestBundleId()
  {
    return target.getHighestBundleId();
  }
  
  public void setNativePathsInvalid(NativeCodeDescription nativeCodeDescription, boolean hasInvalidPaths)
  {
    throw new UnsupportedOperationException();
  }
  
  public BundleDescription[] getDisabledBundles()
  {
    return target.getDisabledBundles();
  }
  
  public void addDisabledInfo(DisabledInfo disabledInfo)
  {
    throw new UnsupportedOperationException();
  }
  
  public DisabledInfo[] getDisabledInfos(BundleDescription bundle)
  {
    return target.getDisabledInfos(bundle);
  }
  
  public DisabledInfo getDisabledInfo(BundleDescription bundle, String policyName)
  {
    return target.getDisabledInfo(bundle, policyName);
  }
  
  public void removeDisabledInfo(DisabledInfo disabledInfo)
  {
    throw new UnsupportedOperationException();
  }
  
  public BundleDescription[] getRemovalPending()
  {
    throw new UnsupportedOperationException();
  }
  
  public Collection<BundleDescription> getDependencyClosure(Collection<BundleDescription> bundles)
  {
    return target.getDependencyClosure(bundles);
  }
  
  public void addDynamicImportPackages(BundleDescription importingBundle, ImportPackageSpecification[] dynamicImports)
  {
    throw new UnsupportedOperationException();
  }
  
  public void setResolverHookFactory(ResolverHookFactory hookFactory) {}
}

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

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.BundleSpecification;

class RequiresHolder
{
  private final BundleSpecification[] requiredBundles;
  private final BundleDescription[] resolvedRequires;
  private final boolean isUsingResolved;
  private final Map<BundleDescription, Boolean> resolvedBundlesExported;
  
  RequiresHolder(BundleDescription bundle, int options)
  {
    isUsingResolved = ((options & 0x2) != 0);
    if (isUsingResolved)
    {
      requiredBundles = null;
      resolvedBundlesExported = new HashMap();
      resolvedRequires = bundle.getResolvedRequires();
      determineRequiresVisibility(bundle);
    }
    else
    {
      requiredBundles = bundle.getRequiredBundles();
      resolvedBundlesExported = null;
      resolvedRequires = null;
    }
  }
  
  BundleDescription getSupplier(int index)
  {
    if (isUsingResolved) {
      return resolvedRequires[index];
    }
    return (BundleDescription)requiredBundles[index].getSupplier();
  }
  
  boolean isExported(int index)
  {
    if (isUsingResolved) {
      return ((Boolean)resolvedBundlesExported.get(resolvedRequires[index])).booleanValue();
    }
    return requiredBundles[index].isExported();
  }
  
  int getSize()
  {
    if (isUsingResolved) {
      return resolvedRequires.length;
    }
    return requiredBundles.length;
  }
  
  private void determineRequiresVisibility(BundleDescription bundle)
  {
    BundleSpecification[] required = bundle.getRequiredBundles();
    Set<BundleDescription> resolved = new HashSet();
    for (int i = 0; i < resolvedRequires.length; i++) {
      resolved.add(resolvedRequires[i]);
    }
    for (int i = 0; i < required.length; i++) {
      if (required[i].getSupplier() != null)
      {
        resolvedBundlesExported.put((BundleDescription)required[i].getSupplier(), new Boolean(required[i].isExported()));
        resolved.remove(required[i].getSupplier());
      }
    }
    BundleDescription[] fragments = bundle.getFragments();
    if (resolved.size() > 0) {
      for (int i = 0; i < fragments.length; i++)
      {
        BundleSpecification[] fragmentRequiredBundles = fragments[i].getRequiredBundles();
        for (int j = 0; j < fragmentRequiredBundles.length; j++) {
          if (resolved.contains(fragmentRequiredBundles[j].getSupplier()))
          {
            resolvedBundlesExported.put((BundleDescription)fragmentRequiredBundles[j].getSupplier(), new Boolean(fragmentRequiredBundles[j].isExported()));
            resolved.remove(fragmentRequiredBundles[j].getSupplier());
          }
        }
        if (resolved.size() == 0) {
          break;
        }
      }
    }
  }
}

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

import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.ResolverError;
import org.eclipse.osgi.service.resolver.VersionConstraint;
import org.eclipse.osgi.util.NLS;

public final class ResolverErrorImpl
  implements ResolverError
{
  private final BundleDescriptionImpl bundle;
  private final int type;
  private final String data;
  private final VersionConstraint unsatisfied;
  
  public ResolverErrorImpl(BundleDescriptionImpl bundle, int type, String data, VersionConstraint unsatisfied)
  {
    this.bundle = bundle;
    this.data = data;
    this.type = type;
    this.unsatisfied = unsatisfied;
  }
  
  public BundleDescription getBundle()
  {
    return bundle;
  }
  
  public int getType()
  {
    return type;
  }
  
  public String getData()
  {
    return data;
  }
  
  public VersionConstraint getUnsatisfiedConstraint()
  {
    return unsatisfied;
  }
  
  public String toString()
  {
    switch (getType())
    {
    case 128: 
    case 256: 
    case 512: 
    case 1024: 
    case 2048: 
    case 4096: 
    case 524288: 
    case 1048576: 
      return NLS.bind(StateMsg.RES_ERROR_MISSING_PERMISSION, getData());
    case 1: 
    case 2: 
    case 4: 
    case 16384: 
    case 32768: 
      return NLS.bind(StateMsg.RES_ERROR_MISSING_CONSTRAINT, getData());
    case 16: 
      return NLS.bind(StateMsg.RES_ERROR_FRAGMENT_CONFLICT, getData());
    case 32: 
    case 64: 
      return NLS.bind(StateMsg.RES_ERROR_USES_CONFLICT, getData());
    case 8: 
      return NLS.bind(StateMsg.RES_ERROR_SINGLETON_CONFLICT, getData());
    case 8192: 
      return NLS.bind(StateMsg.RES_ERROR_PLATFORM_FILTER, getData());
    case 65536: 
      return NLS.bind(StateMsg.RES_ERROR_NO_NATIVECODE_MATCH, getData());
    case 131072: 
      return NLS.bind(StateMsg.RES_ERROR_NATIVECODE_PATH_INVALID, getData());
    case 262144: 
      return NLS.bind(StateMsg.RES_ERROR_DISABLEDBUNDLE, getData());
    }
    return StateMsg.RES_ERROR_UNKNOWN;
  }
}

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

import java.lang.reflect.Constructor;
import java.util.ArrayList;
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.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.osgi.framework.internal.core.Constants;
import org.eclipse.osgi.framework.internal.core.FilterImpl;
import org.eclipse.osgi.framework.internal.core.Msg;
import org.eclipse.osgi.framework.internal.core.Tokenizer;
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.VersionRange;
import org.eclipse.osgi.util.ManifestElement;
import org.eclipse.osgi.util.NLS;
import org.osgi.framework.BundleException;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.Version;

public class StateBuilder
{
  private static final String[] DEFINED_EXPORT_PACKAGE_DIRECTIVES = { "uses", "include", "exclude", "x-friends", "x-internal", "mandatory" };
  private static final String[] DEFINED_IMPORT_PACKAGE_DIRECTIVES = { "resolution" };
  private static final String[] DEFINED_PACKAGE_MATCHING_ATTRS = { "bundle-symbolic-name", "bundle-version", "specification-version", "version" };
  private static final String[] DEFINED_REQUIRE_BUNDLE_DIRECTIVES = { "resolution", "visibility" };
  private static final String[] DEFINED_FRAGMENT_HOST_DIRECTIVES = { "extension" };
  static final String[] DEFINED_BSN_DIRECTIVES = { "singleton", "fragment-attachment", "mandatory" };
  static final String[] DEFINED_BSN_MATCHING_ATTRS = { "bundle-version", "optional", "reprovide" };
  private static final String[] DEFINED_REQUIRE_CAPABILITY_DIRECTIVES = { "resolution", "filter", "cardinality" };
  private static final String[] DEFINED_REQUIRE_CAPABILITY_ATTRS = new String[0];
  private static final String[] DEFINED_OSGI_VALIDATE_HEADERS = { "Import-Package", "DynamicImport-Package", "Export-Package", "Fragment-Host", "Bundle-SymbolicName", "Require-Bundle" };
  static final String GENERIC_REQUIRE = "Eclipse-GenericRequire";
  static final String GENERIC_CAPABILITY = "Eclipse-GenericCapability";
  private static final String ATTR_TYPE_STRING = "string";
  private static final String ATTR_TYPE_VERSION = "version";
  private static final String ATTR_TYPE_URI = "uri";
  private static final String ATTR_TYPE_LONG = "long";
  private static final String ATTR_TYPE_DOUBLE = "double";
  private static final String ATTR_TYPE_SET = "set";
  private static final String ATTR_TYPE_LIST = "List";
  private static final String OPTIONAL_ATTR = "optional";
  private static final String MULTIPLE_ATTR = "multiple";
  private static final String TRUE = "true";
  
  static BundleDescription createBundleDescription(StateImpl state, Dictionary<String, String> manifest, String location)
    throws BundleException
  {
    BundleDescriptionImpl result = new BundleDescriptionImpl();
    String manifestVersionHeader = (String)manifest.get("Bundle-ManifestVersion");
    boolean jreBundle = "true".equals(manifest.get("Eclipse-JREBundle"));
    int manifestVersion = 1;
    if (manifestVersionHeader != null) {
      manifestVersion = Integer.parseInt(manifestVersionHeader);
    }
    if (manifestVersion >= 2) {
      validateHeaders(manifest, jreBundle);
    }
    String symbolicNameHeader = (String)manifest.get("Bundle-SymbolicName");
    if (symbolicNameHeader != null)
    {
      ManifestElement[] symbolicNameElements = ManifestElement.parseHeader("Bundle-SymbolicName", symbolicNameHeader);
      if (symbolicNameElements.length > 0)
      {
        ManifestElement bsnElement = symbolicNameElements[0];
        result.setSymbolicName(bsnElement.getValue());
        String singleton = bsnElement.getDirective("singleton");
        if (singleton == null) {
          singleton = bsnElement.getAttribute("singleton");
        }
        result.setStateBit(2, "true".equals(singleton));
        String fragmentAttachment = bsnElement.getDirective("fragment-attachment");
        if (fragmentAttachment != null) {
          if (fragmentAttachment.equals("resolve-time"))
          {
            result.setStateBit(64, true);
            result.setStateBit(128, false);
          }
          else if (fragmentAttachment.equals("never"))
          {
            result.setStateBit(64, false);
            result.setStateBit(128, false);
          }
        }
        result.setDirective("mandatory", ManifestElement.getArrayFromList(bsnElement.getDirective("mandatory")));
        result.setAttributes(getAttributes(bsnElement, DEFINED_BSN_MATCHING_ATTRS));
        result.setArbitraryDirectives(getDirectives(bsnElement, DEFINED_BSN_DIRECTIVES));
      }
    }
    String version = (String)manifest.get("Bundle-Version");
    try
    {
      result.setVersion(version != null ? Version.parseVersion(version) : Version.emptyVersion);
    }
    catch (IllegalArgumentException ex)
    {
      if (manifestVersion >= 2)
      {
        String message = NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, "Bundle-Version", version);
        throw new BundleException(message + " : " + ex.getMessage(), 3, ex);
      }
    }
    result.setLocation(location);
    result.setPlatformFilter((String)manifest.get("Eclipse-PlatformFilter"));
    String[] brees = ManifestElement.getArrayFromList((String)manifest.get("Bundle-RequiredExecutionEnvironment"));
    result.setExecutionEnvironments(brees);
    ManifestElement[] host = ManifestElement.parseHeader("Fragment-Host", (String)manifest.get("Fragment-Host"));
    if (host != null) {
      result.setHost(createHostSpecification(host[0], state));
    }
    ManifestElement[] exports = ManifestElement.parseHeader("Export-Package", (String)manifest.get("Export-Package"));
    ManifestElement[] provides = ManifestElement.parseHeader("Provide-Package", (String)manifest.get("Provide-Package"));
    boolean strict = (state != null) && (state.inStrictMode());
    List<String> providedExports = new ArrayList(provides == null ? 0 : provides.length);
    result.setExportPackages(createExportPackages(exports, provides, providedExports, strict));
    ManifestElement[] imports = ManifestElement.parseHeader("Import-Package", (String)manifest.get("Import-Package"));
    ManifestElement[] dynamicImports = ManifestElement.parseHeader("DynamicImport-Package", (String)manifest.get("DynamicImport-Package"));
    result.setImportPackages(createImportPackages(result.getExportPackages(), providedExports, imports, dynamicImports, manifestVersion));
    ManifestElement[] requires = ManifestElement.parseHeader("Require-Bundle", (String)manifest.get("Require-Bundle"));
    result.setRequiredBundles(createRequiredBundles(requires));
    String[][] genericAliases = getGenericAliases(state);
    ManifestElement[] genericRequires = getGenericRequires(manifest, genericAliases);
    ManifestElement[] osgiRequires = ManifestElement.parseHeader("Require-Capability", (String)manifest.get("Require-Capability"));
    result.setGenericRequires(createGenericRequires(genericRequires, osgiRequires, brees));
    ManifestElement[] genericCapabilities = getGenericCapabilities(manifest, genericAliases);
    ManifestElement[] osgiCapabilities = ManifestElement.parseHeader("Provide-Capability", (String)manifest.get("Provide-Capability"));
    result.setGenericCapabilities(createGenericCapabilities(genericCapabilities, osgiCapabilities, result));
    ManifestElement[] nativeCode = ManifestElement.parseHeader("Bundle-NativeCode", (String)manifest.get("Bundle-NativeCode"));
    result.setNativeCodeSpecification(createNativeCode(nativeCode));
    return result;
  }
  
  private static ManifestElement[] getGenericRequires(Dictionary<String, String> manifest, String[][] genericAliases)
    throws BundleException
  {
    ManifestElement[] genericRequires = ManifestElement.parseHeader("Eclipse-GenericRequire", (String)manifest.get("Eclipse-GenericRequire"));
    List<ManifestElement> aliasList = null;
    if (genericAliases.length > 0)
    {
      aliasList = new ArrayList(genericRequires == null ? 0 : genericRequires.length);
      for (int i = 0; i < genericAliases.length; i++)
      {
        ManifestElement[] aliasReqs = ManifestElement.parseHeader(genericAliases[i][1], (String)manifest.get(genericAliases[i][1]));
        if (aliasReqs != null) {
          for (int j = 0; j < aliasReqs.length; j++)
          {
            StringBuffer strBuf = new StringBuffer();
            strBuf.append(aliasReqs[j].getValue()).append(':').append(genericAliases[i][2]);
            String filter = aliasReqs[j].getAttribute("selection-filter");
            if (filter != null) {
              strBuf.append("; ").append("selection-filter").append(filter).append("=\"").append(filter).append("\"");
            }
            ManifestElement[] withType = ManifestElement.parseHeader(genericAliases[i][1], strBuf.toString());
            aliasList.add(withType[0]);
          }
        }
      }
    }
    if ((aliasList == null) || (aliasList.size() == 0)) {
      return genericRequires;
    }
    if (genericRequires != null) {
      for (int i = 0; i < genericRequires.length; i++) {
        aliasList.add(genericRequires[i]);
      }
    }
    return (ManifestElement[])aliasList.toArray(new ManifestElement[aliasList.size()]);
  }
  
  private static ManifestElement[] getGenericCapabilities(Dictionary<String, String> manifest, String[][] genericAliases)
    throws BundleException
  {
    ManifestElement[] genericCapabilities = ManifestElement.parseHeader("Eclipse-GenericCapability", (String)manifest.get("Eclipse-GenericCapability"));
    List<ManifestElement> aliasList = null;
    if (genericAliases.length > 0)
    {
      aliasList = new ArrayList(genericCapabilities == null ? 0 : genericCapabilities.length);
      for (int i = 0; i < genericAliases.length; i++)
      {
        ManifestElement[] aliasCapabilities = ManifestElement.parseHeader(genericAliases[i][0], (String)manifest.get(genericAliases[i][0]));
        if (aliasCapabilities != null) {
          for (int j = 0; j < aliasCapabilities.length; j++)
          {
            StringBuffer strBuf = new StringBuffer();
            strBuf.append(aliasCapabilities[j].getValue()).append(':').append(genericAliases[i][2]);
            for (Enumeration<String> keys = aliasCapabilities[j].getKeys(); (keys != null) && (keys.hasMoreElements());)
            {
              String key = (String)keys.nextElement();
              strBuf.append("; ").append(key).append("=\"").append(aliasCapabilities[j].getAttribute(key)).append("\"");
            }
            ManifestElement[] withTypes = ManifestElement.parseHeader(genericAliases[i][0], strBuf.toString());
            aliasList.add(withTypes[0]);
          }
        }
      }
    }
    if ((aliasList == null) || (aliasList.size() == 0)) {
      return genericCapabilities;
    }
    if (genericCapabilities != null) {
      for (int i = 0; i < genericCapabilities.length; i++) {
        aliasList.add(genericCapabilities[i]);
      }
    }
    return (ManifestElement[])aliasList.toArray(new ManifestElement[aliasList.size()]);
  }
  
  private static String[][] getGenericAliases(StateImpl state)
  {
    String genericAliasesProp = getPlatformProperty(state, "osgi.genericAliases");
    if (genericAliasesProp == null) {
      return new String[0][0];
    }
    String[] aliases = ManifestElement.getArrayFromList(genericAliasesProp, ",");
    String[][] result = new String[aliases.length][];
    for (int i = 0; i < aliases.length; i++) {
      result[i] = ManifestElement.getArrayFromList(aliases[i], ":");
    }
    return result;
  }
  
  private static String getPlatformProperty(State state, String key)
  {
    Dictionary[] platformProps = state == null ? null : state.getPlatformProperties();
    return (platformProps == null) || (platformProps.length == 0) ? null : (String)platformProps[0].get(key);
  }
  
  private static void validateHeaders(Dictionary<String, String> manifest, boolean jreBundle)
    throws BundleException
  {
    for (int i = 0; i < DEFINED_OSGI_VALIDATE_HEADERS.length; i++)
    {
      String header = (String)manifest.get(DEFINED_OSGI_VALIDATE_HEADERS[i]);
      if (header != null)
      {
        ManifestElement[] elements = ManifestElement.parseHeader(DEFINED_OSGI_VALIDATE_HEADERS[i], header);
        checkForDuplicateDirectivesAttributes(DEFINED_OSGI_VALIDATE_HEADERS[i], elements);
        if (DEFINED_OSGI_VALIDATE_HEADERS[i] == "Import-Package") {
          checkImportExportSyntax(DEFINED_OSGI_VALIDATE_HEADERS[i], elements, false, false, jreBundle);
        }
        if (DEFINED_OSGI_VALIDATE_HEADERS[i] == "DynamicImport-Package") {
          checkImportExportSyntax(DEFINED_OSGI_VALIDATE_HEADERS[i], elements, false, true, jreBundle);
        }
        if (DEFINED_OSGI_VALIDATE_HEADERS[i] == "Export-Package") {
          checkImportExportSyntax(DEFINED_OSGI_VALIDATE_HEADERS[i], elements, true, false, jreBundle);
        }
        if (DEFINED_OSGI_VALIDATE_HEADERS[i] == "Fragment-Host") {
          checkExtensionBundle(DEFINED_OSGI_VALIDATE_HEADERS[i], elements);
        }
      }
      else if (DEFINED_OSGI_VALIDATE_HEADERS[i] == "Bundle-SymbolicName")
      {
        throw new BundleException(NLS.bind(StateMsg.HEADER_REQUIRED, "Bundle-SymbolicName"), 3);
      }
    }
  }
  
  private static BundleSpecification[] createRequiredBundles(ManifestElement[] specs)
  {
    if (specs == null) {
      return null;
    }
    BundleSpecification[] result = new BundleSpecification[specs.length];
    for (int i = 0; i < specs.length; i++) {
      result[i] = createRequiredBundle(specs[i]);
    }
    return result;
  }
  
  static BundleSpecification createRequiredBundle(ManifestElement spec)
  {
    BundleSpecificationImpl result = new BundleSpecificationImpl();
    result.setName(spec.getValue());
    result.setVersionRange(getVersionRange(spec.getAttribute("bundle-version")));
    result.setExported(("reexport".equals(spec.getDirective("visibility"))) || ("true".equals(spec.getAttribute("reprovide"))));
    result.setOptional(("optional".equals(spec.getDirective("resolution"))) || ("true".equals(spec.getAttribute("optional"))));
    result.setAttributes(getAttributes(spec, DEFINED_BSN_MATCHING_ATTRS));
    result.setArbitraryDirectives(getDirectives(spec, DEFINED_REQUIRE_BUNDLE_DIRECTIVES));
    return result;
  }
  
  private static ImportPackageSpecification[] createImportPackages(ExportPackageDescription[] exported, List<String> providedExports, ManifestElement[] imported, ManifestElement[] dynamicImported, int manifestVersion)
  {
    List<ImportPackageSpecification> allImports = null;
    if (manifestVersion < 2)
    {
      if ((exported.length == 0) && (imported == null) && (dynamicImported == null)) {
        return null;
      }
      allImports = new ArrayList(exported.length + (imported == null ? 0 : imported.length));
      for (int i = 0; i < exported.length; i++) {
        if (!providedExports.contains(exported[i].getName()))
        {
          ImportPackageSpecificationImpl result = new ImportPackageSpecificationImpl();
          result.setName(exported[i].getName());
          result.setVersionRange(getVersionRange(exported[i].getVersion().toString()));
          result.setDirective("resolution", "static");
          allImports.add(result);
        }
      }
    }
    else
    {
      allImports = new ArrayList(imported == null ? 0 : imported.length);
    }
    if (dynamicImported != null) {
      for (int i = 0; i < dynamicImported.length; i++) {
        addImportPackages(dynamicImported[i], allImports, manifestVersion, true);
      }
    }
    if (imported != null) {
      for (int i = 0; i < imported.length; i++) {
        addImportPackages(imported[i], allImports, manifestVersion, false);
      }
    }
    return (ImportPackageSpecification[])allImports.toArray(new ImportPackageSpecification[allImports.size()]);
  }
  
  public static void addImportPackages(ManifestElement importPackage, List<ImportPackageSpecification> allImports, int manifestVersion, boolean dynamic)
  {
    String[] importNames = importPackage.getValueComponents();
    for (int i = 0; i < importNames.length; i++)
    {
      if (manifestVersion < 2)
      {
        Iterator<ImportPackageSpecification> iter = allImports.iterator();
        while (iter.hasNext()) {
          if (importNames[i].equals(((ImportPackageSpecification)iter.next()).getName())) {
            iter.remove();
          }
        }
      }
      ImportPackageSpecificationImpl result = new ImportPackageSpecificationImpl();
      result.setName(importNames[i]);
      
      String versionString = importPackage.getAttribute("version");
      if (versionString == null) {
        versionString = importPackage.getAttribute("specification-version");
      }
      result.setVersionRange(getVersionRange(versionString));
      result.setBundleSymbolicName(importPackage.getAttribute("bundle-symbolic-name"));
      result.setBundleVersionRange(getVersionRange(importPackage.getAttribute("bundle-version")));
      if (manifestVersion >= 2) {
        result.setAttributes(getAttributes(importPackage, DEFINED_PACKAGE_MATCHING_ATTRS));
      }
      if (dynamic) {
        result.setDirective("resolution", "dynamic");
      } else {
        result.setDirective("resolution", getResolution(importPackage.getDirective("resolution")));
      }
      result.setArbitraryDirectives(getDirectives(importPackage, DEFINED_IMPORT_PACKAGE_DIRECTIVES));
      
      allImports.add(result);
    }
  }
  
  private static String getResolution(String resolution)
  {
    String result = "static";
    if (("optional".equals(resolution)) || ("dynamic".equals(resolution))) {
      result = resolution;
    }
    return result;
  }
  
  static ExportPackageDescription[] createExportPackages(ManifestElement[] exported, ManifestElement[] provides, List<String> providedExports, boolean strict)
  {
    int numExports = (exported == null ? 0 : exported.length) + (provides == null ? 0 : provides.length);
    if (numExports == 0) {
      return null;
    }
    List<ExportPackageDescription> allExports = new ArrayList(numExports);
    if (exported != null) {
      for (int i = 0; i < exported.length; i++) {
        addExportPackages(exported[i], allExports, strict);
      }
    }
    if (provides != null) {
      addProvidePackages(provides, allExports, providedExports);
    }
    return (ExportPackageDescription[])allExports.toArray(new ExportPackageDescription[allExports.size()]);
  }
  
  static void addExportPackages(ManifestElement exportPackage, List<ExportPackageDescription> allExports, boolean strict)
  {
    String[] exportNames = exportPackage.getValueComponents();
    for (int i = 0; i < exportNames.length; i++) {
      if ((!strict) || (!"true".equals(exportPackage.getDirective("x-internal"))))
      {
        ExportPackageDescriptionImpl result = new ExportPackageDescriptionImpl();
        result.setName(exportNames[i]);
        String versionString = exportPackage.getAttribute("version");
        if (versionString == null) {
          versionString = exportPackage.getAttribute("specification-version");
        }
        if (versionString != null) {
          result.setVersion(Version.parseVersion(versionString));
        }
        result.setDirective("uses", ManifestElement.getArrayFromList(exportPackage.getDirective("uses")));
        result.setDirective("include", exportPackage.getDirective("include"));
        result.setDirective("exclude", exportPackage.getDirective("exclude"));
        result.setDirective("x-friends", ManifestElement.getArrayFromList(exportPackage.getDirective("x-friends")));
        result.setDirective("x-internal", Boolean.valueOf(exportPackage.getDirective("x-internal")));
        result.setDirective("mandatory", ManifestElement.getArrayFromList(exportPackage.getDirective("mandatory")));
        result.setAttributes(getAttributes(exportPackage, DEFINED_PACKAGE_MATCHING_ATTRS));
        result.setArbitraryDirectives(getDirectives(exportPackage, DEFINED_EXPORT_PACKAGE_DIRECTIVES));
        allExports.add(result);
      }
    }
  }
  
  private static void addProvidePackages(ManifestElement[] provides, List<ExportPackageDescription> allExports, List<String> providedExports)
  {
    ExportPackageDescription[] currentExports = (ExportPackageDescription[])allExports.toArray(new ExportPackageDescription[allExports.size()]);
    for (int i = 0; i < provides.length; i++)
    {
      boolean duplicate = false;
      for (int j = 0; j < currentExports.length; j++) {
        if (provides[i].getValue().equals(currentExports[j].getName()))
        {
          duplicate = true;
          break;
        }
      }
      if (!duplicate)
      {
        ExportPackageDescriptionImpl result = new ExportPackageDescriptionImpl();
        result.setName(provides[i].getValue());
        allExports.add(result);
      }
      providedExports.add(provides[i].getValue());
    }
  }
  
  static Map<String, String> getDirectives(ManifestElement element, String[] definedDirectives)
  {
    Enumeration<String> keys = element.getDirectiveKeys();
    if (keys == null) {
      return null;
    }
    Map<String, String> arbitraryDirectives = null;
    while (keys.hasMoreElements())
    {
      String key = (String)keys.nextElement();
      String[] arrayOfString;
      int j = (arrayOfString = definedDirectives).length;
      for (int i = 0; i < j; i++)
      {
        String definedDirective = arrayOfString[i];
        if (definedDirective.equals(key)) {
          break;
        }
      }
      if (arbitraryDirectives == null) {
        arbitraryDirectives = new HashMap();
      }
      arbitraryDirectives.put(key, element.getDirective(key));
    }
    return arbitraryDirectives;
  }
  
  static Map<String, Object> getAttributes(ManifestElement element, String[] definedAttrs)
  {
    Enumeration<String> keys = element.getKeys();
    Map<String, Object> arbitraryAttrs = null;
    if (keys == null) {
      return null;
    }
    while (keys.hasMoreElements())
    {
      boolean definedAttr = false;
      String key = (String)keys.nextElement();
      for (int i = 0; i < definedAttrs.length; i++) {
        if (definedAttrs[i].equals(key))
        {
          definedAttr = true;
          break;
        }
      }
      String value = element.getAttribute(key);
      int colonIndex = key.indexOf(':');
      String type = "string";
      if (colonIndex > 0)
      {
        type = key.substring(colonIndex + 1).trim();
        key = key.substring(0, colonIndex).trim();
      }
      if (!definedAttr)
      {
        if (arbitraryAttrs == null) {
          arbitraryAttrs = new HashMap();
        }
        arbitraryAttrs.put(key, convertValue(type, value));
      }
    }
    return arbitraryAttrs;
  }
  
  private static Object convertValue(String type, String value)
  {
    if ("string".equalsIgnoreCase(type)) {
      return value;
    }
    String trimmed = value.trim();
    if ("double".equalsIgnoreCase(type)) {
      return new Double(trimmed);
    }
    if ("long".equalsIgnoreCase(type)) {
      return new Long(trimmed);
    }
    if ("uri".equalsIgnoreCase(type)) {
      try
      {
        Class<?> uriClazz = Class.forName("java.net.URI");
        Constructor<?> constructor = uriClazz.getConstructor(new Class[] { String.class });
        return constructor.newInstance(new Object[] { trimmed });
      }
      catch (ClassNotFoundException localClassNotFoundException2)
      {
        return value;
      }
      catch (RuntimeException e)
      {
        throw e;
      }
      catch (Exception e)
      {
        throw new RuntimeException(e.getMessage(), e);
      }
    }
    if ("version".equalsIgnoreCase(type)) {
      return new Version(trimmed);
    }
    if ("set".equalsIgnoreCase(type)) {
      return ManifestElement.getArrayFromList(trimmed, ",");
    }
    Tokenizer listTokenizer = new Tokenizer(type);
    String listType = listTokenizer.getToken("<");
    if (!"List".equalsIgnoreCase(listType)) {
      throw new RuntimeException("Unsupported type: " + type);
    }
    char c = listTokenizer.getChar();
    String componentType = "string";
    if (c == '<')
    {
      componentType = listTokenizer.getToken(">");
      if (listTokenizer.getChar() != '>') {
        throw new RuntimeException("Invalid type, missing ending '>' : " + type);
      }
    }
    List<String> tokens = new Tokenizer(value).getEscapedTokens(",");
    List<Object> components = new ArrayList();
    for (Iterator localIterator = tokens.iterator(); localIterator.hasNext();)
    {
      String component = (String)localIterator.next();
      components.add(convertValue(componentType, component));
    }
    return components;
  }
  
  static HostSpecification createHostSpecification(ManifestElement spec, State state)
  {
    if (spec == null) {
      return null;
    }
    HostSpecificationImpl result = new HostSpecificationImpl();
    result.setName(spec.getValue());
    result.setVersionRange(getVersionRange(spec.getAttribute("bundle-version")));
    String multiple = spec.getDirective("multiple-hosts");
    if (multiple == null) {
      multiple = getPlatformProperty(state, "osgi.support.multipleHosts");
    }
    result.setIsMultiHost("true".equals(multiple));
    result.setAttributes(getAttributes(spec, DEFINED_BSN_MATCHING_ATTRS));
    result.setArbitraryDirectives(getDirectives(spec, DEFINED_FRAGMENT_HOST_DIRECTIVES));
    return result;
  }
  
  private static GenericSpecification[] createGenericRequires(ManifestElement[] equinoxRequires, ManifestElement[] osgiRequires, String[] brees)
    throws BundleException
  {
    List<GenericSpecification> result = createEquinoxRequires(equinoxRequires);
    result = createOSGiRequires(osgiRequires, result);
    result = convertBREEs(brees, result);
    return result == null ? null : (GenericSpecification[])result.toArray(new GenericSpecification[result.size()]);
  }
  
  static List<GenericSpecification> convertBREEs(String[] brees, List<GenericSpecification> result)
    throws BundleException
  {
    if ((brees == null) || (brees.length == 0)) {
      return result;
    }
    if (result == null) {
      result = new ArrayList(brees.length);
    }
    List<String> breeFilters = new ArrayList();
    Object localObject = brees;int j = brees.length;
    for (int i = 0; i < j; i++)
    {
      String bree = localObject[i];
      breeFilters.add(createOSGiEERequirementFilter(bree));
    }
    String filterSpec;
    String filterSpec;
    if (breeFilters.size() == 1)
    {
      filterSpec = (String)breeFilters.get(0);
    }
    else
    {
      StringBuffer filterBuf = new StringBuffer("(|");
      for (localObject = breeFilters.iterator(); ((Iterator)localObject).hasNext();)
      {
        String breeFilter = (String)((Iterator)localObject).next();
        filterBuf.append(breeFilter);
      }
      filterSpec = ")";
    }
    GenericSpecificationImpl spec = new GenericSpecificationImpl();
    spec.setResolution(4);
    spec.setType("osgi.ee");
    try
    {
      FilterImpl filter = FilterImpl.newInstance(filterSpec);
      spec.setMatchingFilter(filter);
      String name = filter.getPrimaryKeyValue(spec.getType());
      if (name != null) {
        spec.setName(name);
      }
    }
    catch (InvalidSyntaxException e)
    {
      throw new BundleException("Error converting required execution environment.", e);
    }
    result.add(spec);
    return result;
  }
  
  private static String createOSGiEERequirementFilter(String bree)
    throws BundleException
  {
    String[] nameVersion = getOSGiEENameVersion(bree);
    String eeName = nameVersion[0];
    String v = nameVersion[1];
    String filterSpec;
    String filterSpec;
    if (v == null) {
      filterSpec = "(osgi.ee=" + eeName + ")";
    } else {
      filterSpec = "(&(osgi.ee=" + eeName + ")(version=" + v + "))";
    }
    try
    {
      FilterImpl.newInstance(filterSpec);
    }
    catch (InvalidSyntaxException localInvalidSyntaxException1)
    {
      filterSpec = "(osgi.ee=" + bree + ")";
      try
      {
        FilterImpl.newInstance(filterSpec);
      }
      catch (InvalidSyntaxException e1)
      {
        throw new BundleException("Error converting required execution environment.", e1);
      }
    }
    return filterSpec;
  }
  
  static String[] getOSGiEENameVersion(String bree)
  {
    String ee1 = null;
    String ee2 = null;
    String v1 = null;
    String v2 = null;
    int separator = bree.indexOf('/');
    if ((separator <= 0) || (separator == bree.length() - 1))
    {
      ee1 = bree;
    }
    else
    {
      ee1 = bree.substring(0, separator);
      ee2 = bree.substring(separator + 1);
    }
    int v1idx = ee1.indexOf('-');
    if ((v1idx > 0) && (v1idx < ee1.length() - 1)) {
      try
      {
        v1 = ee1.substring(v1idx + 1);
        
        Version.parseVersion(v1);
        ee1 = ee1.substring(0, v1idx);
      }
      catch (IllegalArgumentException localIllegalArgumentException1)
      {
        v1 = null;
      }
    }
    int v2idx = ee2 == null ? -1 : ee2.indexOf('-');
    if ((v2idx > 0) && (v2idx < ee2.length() - 1)) {
      try
      {
        v2 = ee2.substring(v2idx + 1);
        Version.parseVersion(v2);
        ee2 = ee2.substring(0, v2idx);
      }
      catch (IllegalArgumentException localIllegalArgumentException2)
      {
        v2 = null;
      }
    }
    if (v1 == null) {
      v1 = v2;
    }
    if ((v1 != null) && (v2 != null) && (!v1.equals(v2)))
    {
      ee1 = bree;
      ee2 = null;
      v1 = null;
      v2 = null;
    }
    if ("J2SE".equals(ee1)) {
      ee1 = "JavaSE";
    }
    if ("J2SE".equals(ee2)) {
      ee2 = "JavaSE";
    }
    String eeName = ee1 + (ee2 == null ? "" : new StringBuffer(String.valueOf('/')).append(ee2).toString());
    
    return new String[] { eeName, v1 };
  }
  
  static List<GenericSpecification> createOSGiRequires(ManifestElement[] osgiRequires, List<GenericSpecification> result)
    throws BundleException
  {
    if (osgiRequires == null) {
      return result;
    }
    if (result == null) {
      result = new ArrayList();
    }
    ManifestElement[] arrayOfManifestElement = osgiRequires;int j = osgiRequires.length;
    for (int i = 0; i < j; i++)
    {
      ManifestElement element = arrayOfManifestElement[i];
      String[] namespaces = element.getValueComponents();
      String[] arrayOfString1;
      int m = (arrayOfString1 = namespaces).length;
      for (int k = 0; k < m; k++)
      {
        String namespace = arrayOfString1[k];
        GenericSpecificationImpl spec = new GenericSpecificationImpl();
        spec.setType(namespace);
        String filterSpec = element.getDirective("filter");
        if (filterSpec != null) {
          try
          {
            FilterImpl filter = FilterImpl.newInstance(filterSpec);
            spec.setMatchingFilter(filter);
            String name = filter.getPrimaryKeyValue(namespace);
            if (name != null) {
              spec.setName(name);
            }
          }
          catch (InvalidSyntaxException e)
          {
            String message = NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, "Require-Capability", element.toString());
            throw new BundleException(message + " : filter", 3, e);
          }
        }
        String resolutionDirective = element.getDirective("resolution");
        int resolution = 0;
        if ("optional".equals(resolutionDirective)) {
          resolution |= 0x1;
        }
        String cardinality = element.getDirective("cardinality");
        if ("multiple".equals(cardinality)) {
          resolution |= 0x2;
        }
        spec.setResoluti
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87

Further reading...

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

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd