org.eclipse.osgi_3.7.2.v20120110-1415

quires.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(), true);
      }
      catch (InvalidSyntaxException localInvalidSyntaxException) {}
      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());
    }
    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());
    }
    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());
    return packageSpec;
  }
  
  public ExportPackageDescription createExportPackageDescription(ExportPackageDescription original)
  {
    return createExportPackageDescription(original.getName(), original.getVersion(), original.getDirectives(), original.getAttributes(), true, null);
  }
  
  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 287	java/io/File
    //   3: dup
    //   4: aload_2
    //   5: ldc_w 281
    //   8: invokespecial 612	java/io/File:<init>	(Ljava/io/File;Ljava/lang/String;)V
    //   11: astore 5
    //   13: new 287	java/io/File
    //   16: dup
    //   17: aload_2
    //   18: ldc_w 280
    //   21: invokespecial 612	java/io/File:<init>	(Ljava/io/File;Ljava/lang/String;)V
    //   24: astore 6
    //   26: aload 5
    //   28: invokevirtual 611	java/io/File:exists	()Z
    //   31: ifeq +11 -> 42
    //   34: aload 6
    //   36: invokevirtual 611	java/io/File:exists	()Z
    //   39: ifne +81 -> 120
    //   42: new 323	org/eclipse/osgi/storagemanager/StorageManager
    //   45: dup
    //   46: aload_2
    //   47: ldc_w 283
    //   50: iconst_1
    //   51: invokespecial 731	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 729	org/eclipse/osgi/storagemanager/StorageManager:open	(Z)V
    //   62: aload 7
    //   64: ldc_w 281
    //   67: iconst_0
    //   68: invokevirtual 730	org/eclipse/osgi/storagemanager/StorageManager:lookup	(Ljava/lang/String;Z)Ljava/io/File;
    //   71: astore 8
    //   73: aload 7
    //   75: ldc_w 280
    //   78: iconst_0
    //   79: invokevirtual 730	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 728	org/eclipse/osgi/storagemanager/StorageManager:close	()V
    //   112: aload 10
    //   114: athrow
    //   115: aload 7
    //   117: invokevirtual 728	org/eclipse/osgi/storagemanager/StorageManager:close	()V
    //   120: new 307	org/eclipse/osgi/internal/resolver/StateReader
    //   123: dup
    //   124: aload 5
    //   126: aload 6
    //   128: iconst_0
    //   129: invokespecial 717	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 715	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 #390	-> byte code offset #0
    //   Java source line #391	-> byte code offset #13
    //   Java source line #392	-> byte code offset #26
    //   Java source line #393	-> byte code offset #42
    //   Java source line #396	-> byte code offset #56
    //   Java source line #398	-> byte code offset #62
    //   Java source line #399	-> byte code offset #73
    //   Java source line #400	-> byte code offset #84
    //   Java source line #401	-> byte code offset #94
    //   Java source line #402	-> byte code offset #98
    //   Java source line #404	-> byte code offset #105
    //   Java source line #405	-> byte code offset #107
    //   Java source line #406	-> byte code offset #112
    //   Java source line #405	-> byte code offset #115
    //   Java source line #408	-> byte code offset #120
    //   Java source line #409	-> byte code offset #134
    //   Java source line #410	-> byte code offset #144
    //   Java source line #411	-> 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);
  }
}

/* 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";
  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 = 36;
  public static final byte NULL = 0;
  public static final byte OBJECT = 1;
  public static final byte INDEX = 2;
  
  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() != 36) {
        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 i = 0; i < numBundles; i++) {
        readBundleDescriptionLazyData(lazyIn, 0);
      }
    }
    finally
    {
      in.close();
      if (lazyIn != null) {
        try
        {
          lazyIn.close();
        }
        catch (IOException localIOException5) {}
      }
    }
    in.close();
    if (lazyIn != null) {
      try
      {
        lazyIn.close();
      }
      catch (IOException localIOException6) {}
    }
    return true;
  }
  
  private boolean readStateDeprecated(StateImpl state, DataInputStream in, long expectedTimestamp)
    throws IOException
  {
    if (in.readByte() != 36) {
      return false;
    }
    byte tag = readTag(in);
    if (tag != 1) {
      return false;
    }
    int index = in.readInt();
    long timestampRead = in.readLong();
    if ((expectedTimestamp >= 0L) && (timestampRead != expectedTimestamp)) {
      return false;
    }
    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);
    numBundles = in.readInt();
    if (numBundles == 0) {
      return true;
    }
    for (int i = 0; i < numBundles; i++)
    {
      BundleDescriptionImpl bundle = readBundleDescription(in);
      state.basicAddBundle(bundle);
      if (bundle.isResolved()) {
        state.addResolvedBundle(bundle);
      }
    }
    state.setTimeStamp(timestampRead);
    state.setResolved(in.readBoolean());
    in.readInt();
    if (lazyLoad) {
      return true;
    }
    for (int i = 0; i < numBundles; i++) {
      readBundleDescriptionLazyData(in, 0);
    }
    return true;
  }
  
  private Object readPlatformProp(DataInputStream in)
    throws IOException
  {
    byte type = in.readByte();
    if (type == 0) {
      return null;
    }
    int num = in.readInt();
    if (num == 1) {
      return readString(in, false);
    }
    String[] result = new String[num];
    for (int i = 0; i < result.length; i++) {
      result[i] = readString(in, false);
    }
    return result;
  }
  
  private BundleDescriptionImpl readBundleDescription(DataInputStream in)
    throws IOException
  {
    byte tag = readTag(in);
    if (tag == 0) {
      return null;
    }
    if (tag == 2) {
      return (BundleDescriptionImpl)getFromObjectTable(in.readInt());
    }
    BundleDescriptionImpl result = new BundleDescriptionImpl();
    addToObjectTable(result, in.readInt());
    
    result.setBundleId(in.readLong());
    readBaseDescription(result, in);
    result.setLazyDataOffset(in.readInt());
    result.setLazyDataSize(in.readInt());
    result.setStateBit(1, in.readBoolean());
    result.setStateBit(2, in.readBoolean());
    result.setStateBit(32, in.readBoolean());
    result.setStateBit(64, in.readBoolean());
    result.setStateBit(128, in.readBoolean());
    String[] mandatory = readList(in);
    if (mandatory != null) {
      result.setDirective("mandatory", mandatory);
    }
    result.setAttributes(readMap(in));
    result.setHost(readHostSpec(in));
    
    int numDeps = in.readInt();
    if (numDeps > 0)
    {
      BundleDescription[] deps = new BundleDescription[numDeps];
      for (int i = 0; i < numDeps; i++) {
        deps[i] = readBundleDescription(in);
      }
      result.addDependencies(deps, false);
    }
    HostSpecificationImpl hostSpec = (HostSpecificationImpl)result.getHost();
    if (hostSpec != null)
    {
      BundleDescription[] hosts = hostSpec.getHosts();
      if (hosts != null) {
        for (int i = 0; i < hosts.length; i++) {
          ((BundleDescriptionImpl)hosts[i]).addDependency(result, false);
        }
      }
    }
    result.setFullyLoaded(false);
    return result;
  }
  
  private BundleDescriptionImpl readBundleDescriptionLazyData(DataInputStream in, int skip)
    throws IOException
  {
    if (skip > 0) {
      in.skipBytes(skip);
    }
    int index = in.readInt();
    BundleDescriptionImpl result = (BundleDescriptionImpl)getFromObjectTable(index);
    if (result.isFullyLoaded())
    {
      in.skipBytes(result.getLazyDataSize() - 4);
      return result;
    }
    result.setLocation(readString(in, false));
    result.setPlatformFilter(readString(in, false));
    
    int exportCount = in.readInt();
    if (exportCount > 0)
    {
      ExportPackageDescription[] exports = new ExportPackageDescription[exportCount];
      for (int i = 0; i < exports.length; i++) {
        exports[i] = readExportPackageDesc(in);
      }
      result.setExportPackages(exports);
    }
    int importCount = in.readInt();
    if (importCount > 0)
    {
      ImportPackageSpecification[] imports = new ImportPackageSpecification[importCount];
      for (int i = 0; i < imports.length; i++) {
        imports[i] = readImportPackageSpec(in);
      }
      result.setImportPackages(imports);
    }
    int requiredBundleCount = in.readInt();
    if (requiredBundleCount > 0)
    {
      BundleSpecification[] requiredBundles = new BundleSpecification[requiredBundleCount];
      for (int i = 0; i < requiredBundles.length; i++) {
        requiredBundles[i] = readBundleSpec(in);
      }
      result.setRequiredBundles(requiredBundles);
    }
    int selectedCount = in.readInt();
    if (selectedCount > 0)
    {
      ExportPackageDescription[] selected = new ExportPackageDescription[selectedCount];
      for (int i = 0; i < selected.length; i++) {
        selected[i] = readExportPackageDesc(in);
      }
      result.setSelectedExports(selected);
    }
    int substitutedCount = in.readInt();
    if (substitutedCount > 0)
    {
      ExportPackageDescription[] selected = new ExportPackageDescription[substitutedCount];
      for (int i = 0; i < selected.length; i++) {
        selected[i] = readExportPackageDesc(in);
      }
      result.setSubstitutedExports(selected);
    }
    int resolvedCount = in.readInt();
    if (resolvedCount > 0)
    {
      ExportPackageDescription[] resolved = new ExportPackageDescription[resolvedCount];
      for (int i = 0; i < resolved.length; i++) {
        resolved[i] = readExportPackageDesc(in);
      }
      result.setResolvedImports(resolved);
    }
    int resolvedRequiredCount = in.readInt();
    if (resolvedRequiredCount > 0)
    {
      BundleDescription[] resolved = new BundleDescription[resolvedRequiredCount];
      for (int i = 0; i < resolved.length; i++) {
        resolved[i] = readBundleDescription(in);
      }
      result.setResolvedRequires(resolved);
    }
    int eeCount = in.readInt();
    if (eeCount > 0)
    {
      String[] ee = new String[eeCount];
      for (int i = 0; i < ee.length; i++) {
        ee[i] = readString(in, false);
      }
      result.setExecutionEnvironments(ee);
    }
    int dynamicPkgCnt = in.readInt();
    if (dynamicPkgCnt > 0)
    {
      HashMap<String, Long> dynamicStamps = new HashMap(dynamicPkgCnt);
      for (int i = 0; i < dynamicPkgCnt; i++)
      {
        String pkg = readString(in, false);
        Long stamp = new Long(in.readLong());
        dynamicStamps.put(pkg, stamp);
      }
      result.setDynamicStamps(dynamicStamps);
    }
    int genericCapCnt = in.readInt();
    if (genericCapCnt > 0)
    {
      GenericDescription[] capabilities = new GenericDescription[genericCapCnt];
      for (int i = 0; i < capabilities.length; i++) {
        capabilities[i] = readGenericDescription(in);
      }
      result.setGenericCapabilities(capabilities);
    }
    int genericReqCnt = in.readInt();
    if (genericReqCnt > 0)
    {
      GenericSpecification[] reqs = new GenericSpecification[genericReqCnt];
      for (int i = 0; i < reqs.length; i++) {
        reqs[i] = readGenericSpecification(in);
      }
      result.setGenericRequires(reqs);
    }
    int selectedGenCapCnt = in.readInt();
    if (selectedGenCapCnt > 0)
    {
      GenericDescription[] capabilities = new GenericDescription[selectedGenCapCnt];
      for (int i = 0; i < capabilities.length; i++) {
        capabilities[i] = readGenericDescription(in);
      }
      result.setSelectedCapabilities(capabilities);
    }
    int resolvedGenCapCnt = in.readInt();
    if (resolvedGenCapCnt > 0)
    {
      GenericDescription[] capabilities = new GenericDescription[resolvedGenCapCnt];
      for (int i = 0; i < capabilities.length; i++) {
        capabilities[i] = readGenericDescription(in);
      }
      result.setResolvedCapabilities(capabilities);
    }
    result.setNativeCodeSpecification(readNativeCode(in));
    
    Map raw = readMap(in);
    result.setStateWires(raw);
    
    result.setFullyLoaded(true);
    
    return result;
  }
  
  private BundleSpecificationImpl readBundleSpec(DataInputStream in)
    throws IOException
  {
    byte tag = readTag(in);
    if (tag == 0) {
      return null;
    }
    if (tag == 2) {
      return (BundleSpecificationImpl)getFromObjectTable(in.readInt());
    }
    BundleSpecificationImpl result = new BundleSpecificationImpl();
    int tableIndex = in.readInt();
    addToObjectTable(result, tableIndex);
    readVersionConstraint(result, in);
    result.setSupplier(readBundleDescription(in));
    result.setExported(in.readBoolean());
    result.setOptional(in.readBoolean());
    result.setAttributes(readMap(in));
    return result;
  }
  
  private ExportPackageDescriptionImpl readExportPackageDesc(DataInputStream in)
    throws IOException
  {
    byte tag = readTag(in);
    if (tag == 0) {
      return null;
    }
    if (tag == 2) {
      return (ExportPackageDescriptionImpl)getFromObjectTable(in.readInt());
    }
    ExportPackageDescriptionImpl exportPackageDesc = new ExportPackageDescriptionImpl();
    int tableIndex = in.readInt();
    addToObjectTable(exportPackageDesc, tableIndex);
    readBaseDescription(exportPackageDesc, in);
    exportPackageDesc.setExporter(readBundleDescription(in));
    exportPackageDesc.setAttributes(readMap(in));
    exportPackageDesc.setDirectives(readMap(in));
    exportPackageDesc.setFragmentDeclaration(readExportPackageDesc(in));
    return exportPackageDesc;
  }
  
  private DisabledInfo readDisabledInfo(DataInputStream in)
    throws IOException
  {
    return new DisabledInfo(readString(in, false), readString(in, false), readBundleDescription(in));
  }
  
  private Map<String, Object> readMap(DataInputStream in)
    throws IOException
  {
    int count = in.readInt();
    if (count == 0) {
      return null;
    }
    HashMap<String, Object> result = new HashMap(count);
    for (int i = 0; i < count; i++)
    {
      String key = readString(in, false);
      Object value = null;
      byte type = in.readByte();
      if (type == 0)
      {
        value = readString(in, false);
      }
      else if (type == 1)
      {
        value = readList(in);
      }
      else if (type == 2)
      {
        value = in.readBoolean() ? Boolean.TRUE : Boolean.FALSE;
      }
      else if (type == 3)
      {
        value = new Integer(in.readInt());
      }
      else if (type == 4)
      {
        value = new Long(in.readLong());
      }
      else if (type == 5)
      {
        value = new Double(in.readDouble());
      }
      else if (type == 6)
      {
        value = readVersion(in);
      }
      else if (type == 7)
      {
        value = readString(in, false);
        try
        {
          Class<?> uriClazz = Class.forName("java.net.URI");
          Constructor<?> constructor = uriClazz.getConstructor(new Class[] { String.class });
          value = constructor.newInstance(new Object[] { value });
        }
        catch (ClassNotFoundException localClassNotFoundException2) {}catch (RuntimeException e)
        {
          throw e;
        }
        catch (Exception e)
        {
          throw new RuntimeException(e.getMessage(), e);
        }
      }
      else if (type == 8)
      {
        int listType = in.readByte();
        int size = in.readInt();
        List<Object> list = new ArrayList(size);
        for (int j = 0; j < size; j++) {
          switch (listType)
          {
          case 0: 
            list.add(readString(in, false));
            break;
          case 3: 
            list.add(new Integer(in.readInt()));
            break;
          case 4: 
            list.add(new Long(in.readLong()));
            break;
          case 5: 
            list.add(new Double(in.readDouble()));
            break;
          case 6: 
            list.add(readVersion(in));
            break;
          case 7: 
            list.add(readStateWire(in));
            break;
          case 1: 
          case 2: 
          default: 
            throw new IOException("Invalid type: " + listType);
          }
        }
        value = list;
      }
      result.put(key, value);
    }
    return result;
  }
  
  private Object readStateWire(DataInputStream in)
    throws IOException
  {
    byte wireType = in.readByte();
    BaseDescription capability;
    BaseDescription capability;
    BaseDescription capability;
    BaseDescription capability;
    switch (wireType)
    {
    case 0: 
      VersionConstraintImpl requirement = readImportPackageSpec(in);
      capability = readExportPackageDesc(in);
      break;
    case 1: 
      VersionConstraintImpl requirement = readBundleSpec(in);
      capability = readBundleDescription(in);
      break;
    case 2: 
      VersionConstraintImpl requirement = readHostSpec(in);
      capability = readBundleDescription(in);
      break;
    case 3: 
      VersionConstraintImpl requirement = readGenericSpecification(in);
      capability = readGenericDescription(in);
      break;
    default: 
      throw new IOException("Invalid wire type: " + wireType);
    }
    BaseDescription capability;
    VersionConstraintImpl requirement;
    BundleDescription requirementHost = readBundleDescription(in);
    BundleDescription capabilityHost = readBundleDescription(in);
    if (requirement.getBundle() == null) {
      requirement.setBundle(requirementHost);
    }
    return new StateWire(requirementHost, requirement, capabilityHost, capability);
  }
  
  private String[] readList(DataInputStream in)
    throws IOException
  {
    int count = in.readInt();
    if (count == 0) {
      return null;
    }
    String[] result = new String[count];
    for (int i = 0; i < count; i++) {
      result[i] = readString(in, false);
    }
    return result;
  }
  
  private void readBaseDescription(BaseDescriptionImpl root, DataInputStream in)
    throws IOException
  {
    root.setName(readString(in, false));
    root.setVersion(readVersion(in));
  }
  
  private ImportPackageSpecificationImpl readImportPackageSpec(DataInputStream in)
    throws IOException
  {
    byte tag = readTag(in);
    if (tag == 0) {
      return null;
    }
    if (tag == 2) {
      return (ImportPackageSpecificationImpl)getFromObjectTable(in.readInt());
    }
    ImportPackageSpecificationImpl result = new ImportPackageSpecificationImpl();
    int tableIndex = in.readInt();
    addToObjectTable(result, tableIndex);
    readVersionConstraint(result, in);
    result.setSupplier(readExportPackageDesc(in));
    result.setBundleSymbolicName(readString(in, false));
    result.setBundleVersionRange(readVersionRange(in));
    result.setAttributes(readMap(in));
    result.setDirectives(readMap(in));
    return result;
  }
  
  private HostSpecificationImpl readHostSpec(DataInputStream in)
    throws IOException
  {
    byte tag = readTag(in);
    if (tag == 0) {
      return null;
    }
    if (tag == 2) {
      return (HostSpecificationImpl)getFromObjectTable(in.readInt());
    }
    HostSpecificationImpl result = new HostSpecificationImpl();
    int tableIndex = in.readInt();
    addToObjectTable(result, tableIndex);
    readVersionConstraint(result, in);
    int hostCount = in.readInt();
    if (hostCount > 0)
    {
      BundleDescription[] hosts = new BundleDescription[hostCount];
      for (int i = 0; i < hosts.length; i++) {
        hosts[i] = readBundleDescription(in);
      }
      result.setHosts(hosts);
    }
    result.setAttributes(readMap(in));
    return result;
  }
  
  private GenericDescription readGenericDescription(DataInputStream in)
    throws IOException
  {
    byte tag = readTag(in);
    if (tag == 0) {
      return null;
    }
    if (tag == 2) {
      return (GenericDescription)getFromObjectTable(in.readInt());
    }
    int tableIndex = in.readInt();
    GenericDescriptionImpl result = new GenericDescriptionImpl();
    addToObjectTable(result, tableIndex);
    readBaseDescription(result, in);
    result.setSupplier(readBundleDescription(in));
    result.setType(readString(in, false));
    Map<String, Object> mapAttrs = readMap(in);
    Dictionary<String, Object> attrs = new Hashtable();
    if (mapAttrs != null) {
      for (Iterator<String> keys = mapAttrs.keySet().iterator(); keys.hasNext();)
      {
        String key = (String)keys.next();
        attrs.put(key, mapAttrs.get(key));
      }
    }
    result.setAttributes(attrs);
    Map directives = readMap(in);
    if (directives != null) {
      result.setDirectives(directives);
    }
    result.setFragmentDeclaration(readGenericDescription(in));
    return result;
  }
  
  private GenericSpecificationImpl readGenericSpecification(DataInputStream in)
    throws IOException
  {
    byte tag = readTag(in);
    if (tag == 0) {
      return null;
    }
    if (tag == 2) {
      return (GenericSpecificationImpl)getFromObjectTable(in.readInt());
    }
    GenericSpecificationImpl result = new GenericSpecificationImpl();
    int tableIndex = in.readInt();
    addToObjectTable(result, tableIndex);
    readVersionConstraint(result, in);
    result.setType(readString(in, false));
    int num = in.readInt();
    GenericDescription[] suppliers = num == 0 ? null : new GenericDescription[num];
    for (int i = 0; i < num; i++) {
      suppliers[i] = readGenericDescription(in);
    }
    result.setSupplers(suppliers);
    result.setResolution(in.readInt());
    try
    {
      result.setMatchingFilter(readString(in, false), false);
    }
    catch (InvalidSyntaxException localInvalidSyntaxException) {}
    return result;
  }
  
  private NativeCodeSpecification readNativeCode(DataInputStream in)
    throws IOException
  {
    if (!in.readBoolean()) {
      return null;
    }
    NativeCodeSpecificationImpl result = new NativeCodeSpecificationImpl();
    result.setOptional(in.readBoolean());
    int numNativeDesc = in.readInt();
    NativeCodeDescriptionImpl[] nativeDescs = new N
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-2017. Infinite Loop Ltd