org.eclipse.osgi_3.8.2.v20130124-134944

ERROR_SINGLETON_CONFLICT;
  public static String RES_ERROR_PLATFORM_FILTER;
  public static String RES_ERROR_NO_NATIVECODE_MATCH;
  public static String RES_ERROR_NATIVECODE_PATH_INVALID;
  public static String RES_ERROR_UNKNOWN;
  
  static
  {
    NLS.initializeMessages("org.eclipse.osgi.internal.resolver.StateMessages", StateMsg.class);
  }
}

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

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Dictionary;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import org.eclipse.osgi.internal.module.ResolverImpl;
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.State;
import org.eclipse.osgi.service.resolver.StateObjectFactory;
import org.eclipse.osgi.service.resolver.VersionRange;
import org.eclipse.osgi.util.ManifestElement;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.Filter;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.Version;

public class StateObjectFactoryImpl
  implements StateObjectFactory
{
  /**
   * @deprecated
   */
  public BundleDescription createBundleDescription(Dictionary<String, String> manifest, String location, long id)
    throws BundleException
  {
    return createBundleDescription(null, manifest, location, id);
  }
  
  public BundleDescription createBundleDescription(State state, Dictionary<String, String> manifest, String location, long id)
    throws BundleException
  {
    BundleDescriptionImpl result = (BundleDescriptionImpl)StateBuilder.createBundleDescription((StateImpl)state, manifest, location);
    result.setBundleId(id);
    return result;
  }
  
  /**
   * @deprecated
   */
  public BundleDescription createBundleDescription(long id, String symbolicName, Version version, String location, BundleSpecification[] required, HostSpecification host, ImportPackageSpecification[] imports, ExportPackageDescription[] exports, String[] providedPackages, boolean singleton)
  {
    return createBundleDescription(id, symbolicName, version, location, required, host, imports, exports, providedPackages, singleton, true, true, null, null, null, null);
  }
  
  /**
   * @deprecated
   */
  public BundleDescription createBundleDescription(long id, String symbolicName, Version version, String location, BundleSpecification[] required, HostSpecification host, ImportPackageSpecification[] imports, ExportPackageDescription[] exports, String[] providedPackages, boolean singleton, boolean attachFragments, boolean dynamicFragments, String platformFilter, String executionEnvironment, GenericSpecification[] genericRequires, GenericDescription[] genericCapabilities)
  {
    return createBundleDescription(id, symbolicName, version, location, required, host, imports, exports, singleton, attachFragments, dynamicFragments, platformFilter, ManifestElement.getArrayFromList(executionEnvironment), genericRequires, genericCapabilities);
  }
  
  public BundleDescription createBundleDescription(long id, String symbolicName, Version version, String location, BundleSpecification[] required, HostSpecification host, ImportPackageSpecification[] imports, ExportPackageDescription[] exports, boolean singleton, boolean attachFragments, boolean dynamicFragments, String platformFilter, String[] executionEnvironments, GenericSpecification[] genericRequires, GenericDescription[] genericCapabilities)
  {
    return createBundleDescription(id, symbolicName, version, location, required, host, imports, exports, singleton, attachFragments, dynamicFragments, platformFilter, executionEnvironments, genericRequires, genericCapabilities, null);
  }
  
  public BundleDescription createBundleDescription(long id, String symbolicName, Version version, String location, BundleSpecification[] required, HostSpecification host, ImportPackageSpecification[] imports, ExportPackageDescription[] exports, boolean singleton, boolean attachFragments, boolean dynamicFragments, String platformFilter, String[] executionEnvironments, GenericSpecification[] genericRequires, GenericDescription[] genericCapabilities, NativeCodeSpecification nativeCode)
  {
    BundleDescriptionImpl bundle = new BundleDescriptionImpl();
    bundle.setBundleId(id);
    bundle.setSymbolicName(symbolicName);
    bundle.setVersion(version);
    bundle.setLocation(location);
    bundle.setRequiredBundles(required);
    bundle.setHost(host);
    bundle.setImportPackages(imports);
    bundle.setExportPackages(exports);
    bundle.setStateBit(2, singleton);
    bundle.setStateBit(64, attachFragments);
    bundle.setStateBit(128, dynamicFragments);
    bundle.setPlatformFilter(platformFilter);
    bundle.setExecutionEnvironments(executionEnvironments);
    bundle.setGenericRequires(genericRequires);
    bundle.setGenericCapabilities(genericCapabilities);
    bundle.setNativeCodeSpecification(nativeCode);
    return bundle;
  }
  
  public BundleDescription createBundleDescription(long id, String symbolicName, Version version, String location, BundleSpecification[] required, HostSpecification host, ImportPackageSpecification[] imports, ExportPackageDescription[] exports, String platformFilter, String[] executionEnvironments, GenericSpecification[] genericRequires, GenericDescription[] genericCapabilities, NativeCodeSpecification nativeCode)
  {
    BundleDescriptionImpl bundle = new BundleDescriptionImpl();
    bundle.setBundleId(id);
    try
    {
      ManifestElement[] symbolicNameElements = ManifestElement.parseHeader("Bundle-SymbolicName", symbolicName);
      if (symbolicNameElements.length > 0)
      {
        ManifestElement bsnElement = symbolicNameElements[0];
        bundle.setSymbolicName(bsnElement.getValue());
        bundle.setStateBit(2, "true".equals(bsnElement.getDirective("singleton")));
        String fragmentAttachment = bsnElement.getDirective("fragment-attachment");
        if (fragmentAttachment != null) {
          if (fragmentAttachment.equals("resolve-time"))
          {
            bundle.setStateBit(64, true);
            bundle.setStateBit(128, false);
          }
          else if (fragmentAttachment.equals("never"))
          {
            bundle.setStateBit(64, false);
            bundle.setStateBit(128, false);
          }
        }
        bundle.setDirective("mandatory", ManifestElement.getArrayFromList(bsnElement.getDirective("mandatory")));
        bundle.setAttributes(StateBuilder.getAttributes(bsnElement, StateBuilder.DEFINED_BSN_MATCHING_ATTRS));
        bundle.setArbitraryDirectives(StateBuilder.getDirectives(bsnElement, StateBuilder.DEFINED_BSN_DIRECTIVES));
      }
    }
    catch (BundleException e)
    {
      throw ((IllegalArgumentException)new IllegalArgumentException("Illegal symbolic name: " + symbolicName).initCause(e));
    }
    bundle.setVersion(version);
    bundle.setLocation(location);
    bundle.setRequiredBundles(required);
    bundle.setHost(host);
    bundle.setImportPackages(imports);
    bundle.setExportPackages(exports);
    bundle.setPlatformFilter(platformFilter);
    bundle.setExecutionEnvironments(executionEnvironments);
    bundle.setGenericRequires(genericRequires);
    GenericDescription[] includeIdentity = new GenericDescription[genericCapabilities == null ? 1 : genericCapabilities.length + 1];
    if (genericCapabilities != null) {
      System.arraycopy(genericCapabilities, 0, includeIdentity, 1, genericCapabilities.length);
    }
    includeIdentity[0] = StateBuilder.createOsgiIdentityCapability(bundle);
    bundle.setGenericCapabilities(includeIdentity);
    bundle.setNativeCodeSpecification(nativeCode);
    return bundle;
  }
  
  public BundleDescription createBundleDescription(BundleDescription original)
  {
    BundleDescriptionImpl bundle = new BundleDescriptionImpl();
    bundle.setBundleId(original.getBundleId());
    bundle.setSymbolicName(original.getSymbolicName());
    bundle.setVersion(original.getVersion());
    bundle.setLocation(original.getLocation());
    BundleSpecification[] originalRequired = original.getRequiredBundles();
    BundleSpecification[] newRequired = new BundleSpecification[originalRequired.length];
    for (int i = 0; i < newRequired.length; i++) {
      newRequired[i] = createBundleSpecification(originalRequired[i]);
    }
    bundle.setRequiredBundles(newRequired);
    ExportPackageDescription[] originalExports = original.getExportPackages();
    ExportPackageDescription[] newExports = new ExportPackageDescription[originalExports.length];
    for (int i = 0; i < newExports.length; i++) {
      newExports[i] = createExportPackageDescription(originalExports[i]);
    }
    bundle.setExportPackages(newExports);
    ImportPackageSpecification[] originalImports = original.getImportPackages();
    ImportPackageSpecification[] newImports = new ImportPackageSpecification[originalImports.length];
    for (int i = 0; i < newImports.length; i++) {
      newImports[i] = createImportPackageSpecification(originalImports[i]);
    }
    bundle.setImportPackages(newImports);
    if (original.getHost() != null) {
      bundle.setHost(createHostSpecification(original.getHost()));
    }
    bundle.setStateBit(2, original.isSingleton());
    bundle.setStateBit(64, original.attachFragments());
    bundle.setStateBit(128, original.dynamicFragments());
    bundle.setStateBit(32, original.hasDynamicImports());
    bundle.setPlatformFilter(original.getPlatformFilter());
    bundle.setExecutionEnvironments(original.getExecutionEnvironments());
    bundle.setGenericCapabilities(createGenericCapabilities(original.getGenericCapabilities()));
    bundle.setGenericRequires(createGenericRequires(original.getGenericRequires()));
    bundle.setNativeCodeSpecification(createNativeCodeSpecification(original.getNativeCodeSpecification()));
    bundle.setAttributes(original.getAttributes());
    if ((original instanceof BundleDescriptionImpl))
    {
      bundle.setDirective("mandatory", ((BundleDescriptionImpl)original).getDirective("mandatory"));
      bundle.setArbitraryDirectives(((BundleDescriptionImpl)original).getArbitraryDirectives());
    }
    return bundle;
  }
  
  private NativeCodeSpecification createNativeCodeSpecification(NativeCodeSpecification original)
  {
    if (original == null) {
      return null;
    }
    NativeCodeSpecificationImpl result = new NativeCodeSpecificationImpl();
    result.setName(original.getName());
    result.setOptional(original.isOptional());
    NativeCodeDescription[] originalDescriptions = original.getPossibleSuppliers();
    NativeCodeDescriptionImpl[] newDescriptions = new NativeCodeDescriptionImpl[originalDescriptions.length];
    for (int i = 0; i < originalDescriptions.length; i++)
    {
      newDescriptions[i] = new NativeCodeDescriptionImpl();
      newDescriptions[i].setName(originalDescriptions[i].getName());
      newDescriptions[i].setNativePaths(originalDescriptions[i].getNativePaths());
      newDescriptions[i].setProcessors(originalDescriptions[i].getProcessors());
      newDescriptions[i].setOSNames(originalDescriptions[i].getOSNames());
      newDescriptions[i].setOSVersions(originalDescriptions[i].getOSVersions());
      newDescriptions[i].setLanguages(originalDescriptions[i].getLanguages());
      try
      {
        newDescriptions[i].setFilter(originalDescriptions[i].getFilter() == null ? null : originalDescriptions[i].getFilter().toString());
      }
      catch (InvalidSyntaxException localInvalidSyntaxException) {}
    }
    result.setPossibleSuppliers(newDescriptions);
    return result;
  }
  
  private GenericDescription[] createGenericCapabilities(GenericDescription[] genericCapabilities)
  {
    if ((genericCapabilities == null) || (genericCapabilities.length == 0)) {
      return null;
    }
    GenericDescription[] result = new GenericDescription[genericCapabilities.length];
    for (int i = 0; i < genericCapabilities.length; i++)
    {
      GenericDescriptionImpl cap = new GenericDescriptionImpl();
      cap.setType(genericCapabilities[i].getType());
      cap.setAttributes(genericCapabilities[i].getAttributes());
      cap.setDirectives(genericCapabilities[i].getDeclaredDirectives());
      result[i] = cap;
    }
    return result;
  }
  
  private GenericSpecification[] createGenericRequires(GenericSpecification[] genericRequires)
  {
    if ((genericRequires == null) || (genericRequires.length == 0)) {
      return null;
    }
    GenericSpecification[] result = new GenericSpecification[genericRequires.length];
    for (int i = 0; i < genericRequires.length; i++)
    {
      GenericSpecificationImpl req = new GenericSpecificationImpl();
      req.setName(genericRequires[i].getName());
      req.setType(genericRequires[i].getType());
      req.setResolution(req.getResolution());
      try
      {
        req.setMatchingFilter(genericRequires[i].getMatchingFilter(), false);
      }
      catch (InvalidSyntaxException localInvalidSyntaxException) {}
      if ((genericRequires[i] instanceof GenericSpecificationImpl))
      {
        req.setAttributes(((GenericSpecificationImpl)genericRequires[i]).getAttributes());
        req.setArbitraryDirectives(((GenericSpecificationImpl)genericRequires[i]).getArbitraryDirectives());
      }
      result[i] = req;
    }
    return result;
  }
  
  public BundleSpecification createBundleSpecification(String requiredSymbolicName, VersionRange requiredVersionRange, boolean export, boolean optional)
  {
    BundleSpecificationImpl bundleSpec = new BundleSpecificationImpl();
    bundleSpec.setName(requiredSymbolicName);
    bundleSpec.setVersionRange(requiredVersionRange);
    bundleSpec.setExported(export);
    bundleSpec.setOptional(optional);
    return bundleSpec;
  }
  
  public BundleSpecification createBundleSpecification(BundleSpecification original)
  {
    BundleSpecificationImpl bundleSpec = new BundleSpecificationImpl();
    bundleSpec.setName(original.getName());
    bundleSpec.setVersionRange(original.getVersionRange());
    bundleSpec.setExported(original.isExported());
    bundleSpec.setOptional(original.isOptional());
    if ((original instanceof BundleSpecificationImpl))
    {
      bundleSpec.setAttributes(((BundleSpecificationImpl)original).getAttributes());
      bundleSpec.setArbitraryDirectives(((BundleSpecificationImpl)original).getArbitraryDirectives());
    }
    return bundleSpec;
  }
  
  public HostSpecification createHostSpecification(String hostSymbolicName, VersionRange versionRange)
  {
    HostSpecificationImpl hostSpec = new HostSpecificationImpl();
    hostSpec.setName(hostSymbolicName);
    hostSpec.setVersionRange(versionRange);
    return hostSpec;
  }
  
  public HostSpecification createHostSpecification(HostSpecification original)
  {
    HostSpecificationImpl hostSpec = new HostSpecificationImpl();
    hostSpec.setName(original.getName());
    hostSpec.setVersionRange(original.getVersionRange());
    if ((original instanceof HostSpecificationImpl))
    {
      hostSpec.setAttributes(((HostSpecificationImpl)original).getAttributes());
      hostSpec.setArbitraryDirectives(((HostSpecificationImpl)original).getArbitraryDirectives());
    }
    return hostSpec;
  }
  
  public ImportPackageSpecification createImportPackageSpecification(String packageName, VersionRange versionRange, String bundleSymbolicName, VersionRange bundleVersionRange, Map<String, ?> directives, Map<String, ?> attributes, BundleDescription importer)
  {
    ImportPackageSpecificationImpl packageSpec = new ImportPackageSpecificationImpl();
    packageSpec.setName(packageName);
    packageSpec.setVersionRange(versionRange);
    packageSpec.setBundleSymbolicName(bundleSymbolicName);
    packageSpec.setBundleVersionRange(bundleVersionRange);
    packageSpec.setDirectives(directives);
    packageSpec.setAttributes(attributes);
    packageSpec.setBundle(importer);
    return packageSpec;
  }
  
  public ImportPackageSpecification createImportPackageSpecification(ImportPackageSpecification original)
  {
    ImportPackageSpecificationImpl packageSpec = new ImportPackageSpecificationImpl();
    packageSpec.setName(original.getName());
    packageSpec.setVersionRange(original.getVersionRange());
    packageSpec.setBundleSymbolicName(original.getBundleSymbolicName());
    packageSpec.setBundleVersionRange(original.getBundleVersionRange());
    packageSpec.setDirectives(original.getDirectives());
    packageSpec.setAttributes(original.getAttributes());
    if ((original instanceof ImportPackageSpecificationImpl)) {
      packageSpec.setArbitraryDirectives(((ImportPackageSpecificationImpl)original).getArbitraryDirectives());
    }
    return packageSpec;
  }
  
  public ExportPackageDescription createExportPackageDescription(ExportPackageDescription original)
  {
    ExportPackageDescriptionImpl exportPackage = new ExportPackageDescriptionImpl();
    exportPackage.setName(original.getName());
    exportPackage.setVersion(original.getVersion());
    exportPackage.setDirectives(original.getDirectives());
    exportPackage.setAttributes(original.getAttributes());
    exportPackage.setArbitraryDirectives(((ExportPackageDescriptionImpl)original).getArbitraryDirectives());
    return exportPackage;
  }
  
  public ExportPackageDescription createExportPackageDescription(String packageName, Version version, Map<String, ?> directives, Map<String, ?> attributes, boolean root, BundleDescription exporter)
  {
    ExportPackageDescriptionImpl exportPackage = new ExportPackageDescriptionImpl();
    exportPackage.setName(packageName);
    exportPackage.setVersion(version);
    exportPackage.setDirectives(directives);
    exportPackage.setAttributes(attributes);
    exportPackage.setExporter(exporter);
    return exportPackage;
  }
  
  /**
   * @deprecated
   */
  public GenericDescription createGenericDescription(String name, String type, Version version, Map<String, ?> attributes)
  {
    return createGenericDescription(name, type, version, attributes, null, null);
  }
  
  public GenericDescription createGenericDescription(String type, Map<String, ?> attributes, Map<String, String> directives, BundleDescription supplier)
  {
    return createGenericDescription(null, type, null, attributes, directives, supplier);
  }
  
  private GenericDescription createGenericDescription(String name, String type, Version version, Map<String, ?> attributes, Map<String, String> directives, BundleDescription supplier)
  {
    GenericDescriptionImpl result = new GenericDescriptionImpl();
    result.setType(type);
    Dictionary<String, Object> attrs = attributes == null ? new Hashtable() : new Hashtable(attributes);
    if (version != null)
    {
      Object versionObj = attrs.get("version");
      if ((!(versionObj instanceof Version)) && (version != null)) {
        attrs.put("version", version);
      }
    }
    if (name != null)
    {
      Object nameObj = attrs.get(result.getType());
      if (!(nameObj instanceof String)) {
        attrs.put(result.getType(), name);
      }
    }
    result.setAttributes(attrs);
    result.setDirectives(directives);
    result.setSupplier(supplier);
    return result;
  }
  
  public GenericSpecification createGenericSpecification(String name, String type, String matchingFilter, boolean optional, boolean multiple)
    throws InvalidSyntaxException
  {
    GenericSpecificationImpl result = new GenericSpecificationImpl();
    result.setName(name);
    result.setType(type);
    result.setMatchingFilter(matchingFilter, true);
    int resolution = 0;
    if (optional) {
      resolution |= 0x1;
    }
    if (multiple) {
      resolution |= 0x2;
    }
    result.setResolution(resolution);
    return result;
  }
  
  public NativeCodeDescription createNativeCodeDescription(String[] nativePaths, String[] processors, String[] osNames, VersionRange[] osVersions, String[] languages, String filter)
    throws InvalidSyntaxException
  {
    NativeCodeDescriptionImpl result = new NativeCodeDescriptionImpl();
    result.setName("Bundle-NativeCode");
    result.setNativePaths(nativePaths);
    result.setProcessors(processors);
    result.setOSNames(osNames);
    result.setOSVersions(osVersions);
    result.setLanguages(languages);
    result.setFilter(filter);
    return result;
  }
  
  public NativeCodeSpecification createNativeCodeSpecification(NativeCodeDescription[] nativeCodeDescriptions, boolean optional)
  {
    NativeCodeSpecificationImpl result = new NativeCodeSpecificationImpl();
    result.setName("Bundle-NativeCode");
    result.setOptional(optional);
    result.setPossibleSuppliers(nativeCodeDescriptions);
    return result;
  }
  
  public SystemState createSystemState(BundleContext context)
  {
    SystemState state = new SystemState(context);
    state.setFactory(this);
    return state;
  }
  
  /**
   * @deprecated
   */
  public State createState()
  {
    return internalCreateState();
  }
  
  public State createState(boolean createResolver)
  {
    State result = internalCreateState();
    if (createResolver) {
      result.setResolver(new ResolverImpl(false));
    }
    return result;
  }
  
  public State createState(State original)
  {
    StateImpl newState = internalCreateState();
    newState.setTimeStamp(original.getTimeStamp());
    BundleDescription[] bundles = original.getBundles();
    for (int i = 0; i < bundles.length; i++)
    {
      BundleDescription newBundle = createBundleDescription(bundles[i]);
      newState.basicAddBundle(newBundle);
      DisabledInfo[] infos = original.getDisabledInfos(bundles[i]);
      for (int j = 0; j < infos.length; j++) {
        newState.addDisabledInfo(new DisabledInfo(infos[j].getPolicyName(), infos[j].getMessage(), newBundle));
      }
    }
    newState.setResolved(false);
    newState.setPlatformProperties(original.getPlatformProperties());
    return newState;
  }
  
  private StateImpl internalCreateState()
  {
    StateImpl state = new UserState();
    state.setFactory(this);
    return state;
  }
  
  public SystemState readSystemState(BundleContext context, File stateFile, File lazyFile, boolean lazyLoad, long expectedTimeStamp)
    throws IOException
  {
    StateReader reader = new StateReader(stateFile, lazyFile, lazyLoad);
    SystemState restoredState = new SystemState(context);
    restoredState.setReader(reader);
    restoredState.setFactory(this);
    if (!reader.loadState(restoredState, expectedTimeStamp)) {
      return null;
    }
    return restoredState;
  }
  
  /**
   * @deprecated
   */
  public State readState(InputStream stream)
    throws IOException
  {
    return internalReadStateDeprecated(internalCreateState(), new DataInputStream(stream), -1L);
  }
  
  /**
   * @deprecated
   */
  public State readState(DataInputStream stream)
    throws IOException
  {
    return internalReadStateDeprecated(internalCreateState(), stream, -1L);
  }
  
  public State readState(File stateDirectory)
    throws IOException
  {
    return internalReadState(internalCreateState(), stateDirectory, -1L);
  }
  
  private State internalReadStateDeprecated(StateImpl toRestore, DataInputStream stream, long expectedTimestamp)
    throws IOException
  {
    StateReader reader = new StateReader();
    if (!reader.loadStateDeprecated(toRestore, stream, expectedTimestamp)) {
      return null;
    }
    return toRestore;
  }
  
  /* Error */
  private State internalReadState(StateImpl toRestore, File stateDirectory, long expectedTimestamp)
    throws IOException
  {
    // Byte code:
    //   0: new 350	java/io/File
    //   3: dup
    //   4: aload_2
    //   5: ldc_w 338
    //   8: invokespecial 735	java/io/File:<init>	(Ljava/io/File;Ljava/lang/String;)V
    //   11: astore 5
    //   13: new 350	java/io/File
    //   16: dup
    //   17: aload_2
    //   18: ldc_w 337
    //   21: invokespecial 735	java/io/File:<init>	(Ljava/io/File;Ljava/lang/String;)V
    //   24: astore 6
    //   26: aload 5
    //   28: invokevirtual 734	java/io/File:exists	()Z
    //   31: ifeq +11 -> 42
    //   34: aload 6
    //   36: invokevirtual 734	java/io/File:exists	()Z
    //   39: ifne +81 -> 120
    //   42: new 391	org/eclipse/osgi/storagemanager/StorageManager
    //   45: dup
    //   46: aload_2
    //   47: ldc_w 346
    //   50: iconst_1
    //   51: invokespecial 884	org/eclipse/osgi/storagemanager/StorageManager:<init>	(Ljava/io/File;Ljava/lang/String;Z)V
    //   54: astore 7
    //   56: aload 7
    //   58: iconst_1
    //   59: invokevirtual 882	org/eclipse/osgi/storagemanager/StorageManager:open	(Z)V
    //   62: aload 7
    //   64: ldc_w 338
    //   67: iconst_0
    //   68: invokevirtual 883	org/eclipse/osgi/storagemanager/StorageManager:lookup	(Ljava/lang/String;Z)Ljava/io/File;
    //   71: astore 8
    //   73: aload 7
    //   75: ldc_w 337
    //   78: iconst_0
    //   79: invokevirtual 883	org/eclipse/osgi/storagemanager/StorageManager:lookup	(Ljava/lang/String;Z)Ljava/io/File;
    //   82: astore 9
    //   84: aload 8
    //   86: ifnull +29 -> 115
    //   89: aload 9
    //   91: ifnull +24 -> 115
    //   94: aload 8
    //   96: astore 5
    //   98: aload 9
    //   100: astore 6
    //   102: goto +13 -> 115
    //   105: astore 10
    //   107: aload 7
    //   109: invokevirtual 881	org/eclipse/osgi/storagemanager/StorageManager:close	()V
    //   112: aload 10
    //   114: athrow
    //   115: aload 7
    //   117: invokevirtual 881	org/eclipse/osgi/storagemanager/StorageManager:close	()V
    //   120: new 375	org/eclipse/osgi/internal/resolver/StateReader
    //   123: dup
    //   124: aload 5
    //   126: aload 6
    //   128: iconst_0
    //   129: invokespecial 870	org/eclipse/osgi/internal/resolver/StateReader:<init>	(Ljava/io/File;Ljava/io/File;Z)V
    //   132: astore 7
    //   134: aload 7
    //   136: aload_1
    //   137: lload_3
    //   138: invokevirtual 868	org/eclipse/osgi/internal/resolver/StateReader:loadState	(Lorg/eclipse/osgi/internal/resolver/StateImpl;J)Z
    //   141: ifne +5 -> 146
    //   144: aconst_null
    //   145: areturn
    //   146: aload_1
    //   147: areturn
    // Line number table:
    //   Java source line #456	-> byte code offset #0
    //   Java source line #457	-> byte code offset #13
    //   Java source line #458	-> byte code offset #26
    //   Java source line #459	-> byte code offset #42
    //   Java source line #462	-> byte code offset #56
    //   Java source line #464	-> byte code offset #62
    //   Java source line #465	-> byte code offset #73
    //   Java source line #466	-> byte code offset #84
    //   Java source line #467	-> byte code offset #94
    //   Java source line #468	-> byte code offset #98
    //   Java source line #470	-> byte code offset #102
    //   Java source line #471	-> byte code offset #107
    //   Java source line #472	-> byte code offset #112
    //   Java source line #471	-> byte code offset #115
    //   Java source line #474	-> byte code offset #120
    //   Java source line #475	-> byte code offset #134
    //   Java source line #476	-> byte code offset #144
    //   Java source line #477	-> byte code offset #146
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	148	0	this	StateObjectFactoryImpl
    //   0	148	1	toRestore	StateImpl
    //   0	148	2	stateDirectory	File
    //   0	148	3	expectedTimestamp	long
    //   11	114	5	stateFile	File
    //   24	103	6	lazyFile	File
    //   54	62	7	storageManager	org.eclipse.osgi.storagemanager.StorageManager
    //   132	3	7	reader	StateReader
    //   71	24	8	managedState	File
    //   82	17	9	managedLazy	File
    //   105	8	10	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   56	105	105	finally
  }
  
  /**
   * @deprecated
   */
  public void writeState(State state, DataOutputStream stream)
    throws IOException
  {
    internalWriteStateDeprecated(state, stream);
  }
  
  public void writeState(State state, File stateDirectory)
    throws IOException
  {
    if (stateDirectory == null) {
      throw new IOException();
    }
    StateWriter writer = new StateWriter();
    File stateFile = new File(stateDirectory, ".state");
    File lazyFile = new File(stateDirectory, ".lazy");
    writer.saveState((StateImpl)state, stateFile, lazyFile);
  }
  
  /**
   * @deprecated
   */
  public void writeState(State state, OutputStream stream)
    throws IOException
  {
    internalWriteStateDeprecated(state, new DataOutputStream(stream));
  }
  
  public void writeState(State state, File stateFile, File lazyFile)
    throws IOException
  {
    StateWriter writer = new StateWriter();
    writer.saveState((StateImpl)state, stateFile, lazyFile);
  }
  
  public void internalWriteStateDeprecated(State state, DataOutputStream stream)
    throws IOException
  {
    if (state.getFactory() != this) {
      throw new IllegalArgumentException();
    }
    StateWriter writer = new StateWriter();
    writer.saveStateDeprecated((StateImpl)state, stream);
  }
  
  public List<BundleSpecification> createBundleSpecifications(String declaration)
  {
    try
    {
      ManifestElement[] elements = ManifestElement.parseHeader("Require-Bundle", declaration);
      if (elements == null) {
        return Collections.EMPTY_LIST;
      }
      List<BundleSpecification> result = new ArrayList(elements.length);
      ManifestElement[] arrayOfManifestElement1;
      int j = (arrayOfManifestElement1 = elements).length;
      for (int i = 0; i < j; i++)
      {
        ManifestElement element = arrayOfManifestElement1[i];
        result.add(StateBuilder.createRequiredBundle(element));
      }
      return result;
    }
    catch (BundleException e)
    {
      throw ((IllegalArgumentException)new IllegalArgumentException("Declaration is invalid: " + declaration).initCause(e));
    }
  }
  
  public List<HostSpecification> createHostSpecifications(String declaration)
  {
    try
    {
      ManifestElement[] elements = ManifestElement.parseHeader("Fragment-Host", declaration);
      if (elements == null) {
        return Collections.EMPTY_LIST;
      }
      List<HostSpecification> result = new ArrayList(elements.length);
      ManifestElement[] arrayOfManifestElement1;
      int j = (arrayOfManifestElement1 = elements).length;
      for (int i = 0; i < j; i++)
      {
        ManifestElement element = arrayOfManifestElement1[i];
        result.add(StateBuilder.createHostSpecification(element, null));
      }
      return result;
    }
    catch (BundleException e)
    {
      throw ((IllegalArgumentException)new IllegalArgumentException("Declaration is invalid: " + declaration).initCause(e));
    }
  }
  
  public List<ImportPackageSpecification> createImportPackageSpecifications(String declaration)
  {
    try
    {
      ManifestElement[] elements = ManifestElement.parseHeader("Import-Package", declaration);
      if (elements == null) {
        return Collections.EMPTY_LIST;
      }
      List<ImportPackageSpecification> result = new ArrayList(elements.length);
      ManifestElement[] arrayOfManifestElement1;
      int j = (arrayOfManifestElement1 = elements).length;
      for (int i = 0; i < j; i++)
      {
        ManifestElement element = arrayOfManifestElement1[i];
        StateBuilder.addImportPackages(element, result, 2, false);
      }
      return result;
    }
    catch (BundleException e)
    {
      throw ((IllegalArgumentException)new IllegalArgumentException("Declaration is invalid: " + declaration).initCause(e));
    }
  }
  
  public List<GenericDescription> createGenericDescriptions(String declaration)
  {
    try
    {
      ManifestElement[] elements = ManifestElement.parseHeader("Provide-Capability", declaration);
      if (elements == null) {
        return Collections.EMPTY_LIST;
      }
      return StateBuilder.createOSGiCapabilities(elements, new ArrayList(elements.length), null);
    }
    catch (BundleException e)
    {
      throw ((IllegalArgumentException)new IllegalArgumentException("Declaration is invalid: " + declaration).initCause(e));
    }
  }
  
  public List<GenericSpecification> createGenericSpecifications(String declaration)
  {
    try
    {
      ManifestElement[] elements = ManifestElement.parseHeader("Require-Capability", declaration);
      if (elements == null) {
        return Collections.EMPTY_LIST;
      }
      return StateBuilder.createOSGiRequires(elements, new ArrayList(elements.length));
    }
    catch (BundleException e)
    {
      throw ((IllegalArgumentException)new IllegalArgumentException("Declaration is invalid: " + declaration).initCause(e));
    }
  }
  
  public List<ExportPackageDescription> createExportPackageDescriptions(String declaration)
  {
    try
    {
      ManifestElement[] elements = ManifestElement.parseHeader("Import-Package", declaration);
      if (elements == null) {
        return Collections.EMPTY_LIST;
      }
      List<ExportPackageDescription> result = new ArrayList(elements.length);
      ManifestElement[] arrayOfManifestElement1;
      int j = (arrayOfManifestElement1 = elements).length;
      for (int i = 0; i < j; i++)
      {
        ManifestElement element = arrayOfManifestElement1[i];
        StateBuilder.addExportPackages(element, result, false);
      }
      return result;
    }
    catch (BundleException e)
    {
      throw ((IllegalArgumentException)new IllegalArgumentException("Declaration is invalid: " + declaration).initCause(e));
    }
  }
}

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

import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.security.AccessController;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.eclipse.osgi.framework.util.ObjectPool;
import org.eclipse.osgi.framework.util.SecureAction;
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.ImportPackageSpecification;
import org.eclipse.osgi.service.resolver.NativeCodeSpecification;
import org.eclipse.osgi.service.resolver.StateWire;
import org.eclipse.osgi.service.resolver.VersionRange;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.Version;

final class StateReader
{
  public static final String STATE_FILE = ".state";
  public static final String LAZY_FILE = ".lazy";
  public static final String UTF_8 = "UTF-8";
  private static final int BUFFER_SIZE_LAZY = 4096;
  private static final int BUFFER_SIZE_FULLYREAD = 16384;
  private static final SecureAction secureAction = (SecureAction)AccessController.doPrivileged(SecureAction.createSecureAction());
  final Map<Integer, Object> objectTable = Collections.synchronizedMap(new HashMap());
  private volatile File stateFile;
  private volatile File lazyFile;
  private volatile boolean lazyLoad = true;
  private volatile int numBundles;
  private volatile boolean accessedFlag = false;
  public static final byte STATE_CACHE_VERSION = 38;
  public static final byte NULL = 0;
  public static final byte OBJECT = 1;
  public static final byte INDEX = 2;
  public static final byte LONG_STRING = 3;
  
  public StateReader()
  {
    lazyLoad = false;
  }
  
  public StateReader(File stateDirectory)
  {
    if (!stateDirectory.exists()) {
      stateDirectory.mkdirs();
    }
    stateFile = new File(stateDirectory, ".state");
    lazyFile = new File(stateDirectory, ".lazy");
    lazyLoad = false;
  }
  
  public StateReader(File stateFile, File lazyFile, boolean lazyLoad)
  {
    this.stateFile = stateFile;
    this.lazyFile = lazyFile;
    this.lazyLoad = lazyLoad;
  }
  
  private void addToObjectTable(Object object, int index)
  {
    objectTable.put(new Integer(index), object);
  }
  
  private Object getFromObjectTable(int index)
  {
    Object result = objectTable.get(new Integer(index));
    if (result == null) {
      throw new IllegalStateException("Expected to find an object at table index: " + index);
    }
    return result;
  }
  
  private boolean readState(StateImpl state, long expectedTimestamp)
    throws IOException
  {
    DataInputStream in = new DataInputStream(new BufferedInputStream(secureAction.getFileInputStream(stateFile), 16384));
    DataInputStream lazyIn = null;
    try
    {
      if (in.readByte() != 38) {
        return false;
      }
      byte tag = readTag(in);
      if (tag != 1) {
        return false;
      }
      byte tag;
      int index = in.readInt();
      long timestampRead = in.readLong();
      if ((expectedTimestamp >= 0L) && (timestampRead != expectedTimestamp)) {
        return false;
      }
      long timestampRead;
      int index;
      byte tag;
      addToObjectTable(state, index);
      
      String[] platformPropKeys = (String[])readPlatformProp(in);
      state.addPlatformPropertyKeys(platformPropKeys);
      int numSets = in.readInt();
      Dictionary[] platformProps = new Dictionary[numSets];
      for (int i = 0; i < numSets; i++)
      {
        Hashtable<Object, Object> props = new Hashtable(platformPropKeys.length);
        int numProps = in.readInt();
        for (int j = 0; j < numProps; j++)
        {
          Object value = readPlatformProp(in);
          if ((value != null) && (j < platformPropKeys.length)) {
            props.put(platformPropKeys[j], value);
          }
        }
        platformProps[i] = props;
      }
      state.setPlatformProperties(platformProps, false);
      numBundles = in.readInt();
      for (int i = 0; i < numBundles; i++)
      {
        BundleDescriptionImpl bundle = readBundleDescription(in);
        state.basicAddBundle(bundle);
        if (bundle.isResolved()) {
          state.addResolvedBundle(bundle);
        }
      }
      int numDisableInfos = in.readInt();
      for (int i = 0; i < numDisableInfos; i++)
      {
        DisabledInfo info = readDisabledInfo(in);
        state.addDisabledInfo(info);
      }
      state.setTimeStamp(timestampRead);
      state.setResolved(in.readBoolean());
      if (lazyLoad) {
        return true;
      }
      int numDisableInfos;
      Dictionary[] platformProps;
      int numSets;
      String[] platformPropKeys;
      long timestampRead;
      int index;
      byte tag;
      lazyIn = new DataInputStream(new BufferedInputStream(secureAction.getFileInputStream(lazyFile), 16384));
      for (int 
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