org.eclipse.osgi_3.7.2.v20120110-1415

   // Exception table:
    //   from	to	target	type
    //   86	299	299	finally
    //   309	313	316	java/io/IOException
    //   328	332	335	java/io/IOException
    //   57	336	339	java/io/IOException
  }
  
  private void cleanRemovalPendings(State systemState, BundleDescription[] removalPendings)
  {
    if (removalPendings.length == 0) {
      return;
    }
    systemState.resolve(removalPendings);
    for (int i = 0; i < removalPendings.length; i++)
    {
      Object userObject = removalPendings[i].getUserObject();
      if ((userObject instanceof BundleLoaderProxy))
      {
        BundleLoader.closeBundleLoader((BundleLoaderProxy)userObject);
        try
        {
          ((BundleLoaderProxy)userObject).getBundleData().close();
        }
        catch (IOException localIOException1) {}
      }
      else if ((userObject instanceof BundleData))
      {
        try
        {
          ((BundleData)userObject).close();
        }
        catch (IOException localIOException2) {}
      }
    }
  }
  
  /* Error */
  private void saveStateData(boolean shutdown)
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 1209	org/eclipse/osgi/internal/baseadaptor/BaseStorage:stateManager	Lorg/eclipse/osgi/internal/baseadaptor/StateManager;
    //   4: invokevirtual 1418	org/eclipse/osgi/internal/baseadaptor/StateManager:getSystemState	()Lorg/eclipse/osgi/service/resolver/State;
    //   7: astore_2
    //   8: iload_1
    //   9: ifeq +32 -> 41
    //   12: ldc_w 631
    //   15: ldc_w 629
    //   18: invokestatic 1338	org/eclipse/osgi/framework/internal/core/FrameworkProperties:getProperty	(Ljava/lang/String;)Ljava/lang/String;
    //   21: invokevirtual 1275	java/lang/String:equals	(Ljava/lang/Object;)Z
    //   24: ifeq +17 -> 41
    //   27: aload_2
    //   28: aload_2
    //   29: invokeinterface 1470 1 0
    //   34: lconst_1
    //   35: ladd
    //   36: invokeinterface 1471 3 0
    //   41: aload_2
    //   42: invokeinterface 1473 1 0
    //   47: astore_3
    //   48: aload_3
    //   49: arraylength
    //   50: ifle +14 -> 64
    //   53: iload_1
    //   54: ifne +4 -> 58
    //   57: return
    //   58: aload_0
    //   59: aload_2
    //   60: aload_3
    //   61: invokespecial 1392	org/eclipse/osgi/internal/baseadaptor/BaseStorage:cleanRemovalPendings	(Lorg/eclipse/osgi/service/resolver/State;[Lorg/eclipse/osgi/service/resolver/BundleDescription;)V
    //   64: aload_0
    //   65: getfield 1209	org/eclipse/osgi/internal/baseadaptor/BaseStorage:stateManager	Lorg/eclipse/osgi/internal/baseadaptor/StateManager;
    //   68: ifnull +20 -> 88
    //   71: aload_0
    //   72: invokevirtual 1364	org/eclipse/osgi/internal/baseadaptor/BaseStorage:isReadOnly	()Z
    //   75: ifne +13 -> 88
    //   78: aload_0
    //   79: getfield 1209	org/eclipse/osgi/internal/baseadaptor/BaseStorage:stateManager	Lorg/eclipse/osgi/internal/baseadaptor/StateManager;
    //   82: invokevirtual 1416	org/eclipse/osgi/internal/baseadaptor/StateManager:saveNeeded	()Z
    //   85: ifne +4 -> 89
    //   88: return
    //   89: getstatic 1184	org/eclipse/osgi/framework/debug/Debug:DEBUG_GENERAL	Z
    //   92: ifeq +9 -> 101
    //   95: ldc_w 616
    //   98: invokestatic 1331	org/eclipse/osgi/framework/debug/Debug:println	(Ljava/lang/String;)V
    //   101: aconst_null
    //   102: astore 4
    //   104: aconst_null
    //   105: astore 5
    //   107: ldc_w 596
    //   110: ldc_w 595
    //   113: invokestatic 1294	org/eclipse/core/runtime/adaptor/LocationManager:getOSGiConfigurationDir	()Ljava/io/File;
    //   116: invokestatic 1246	java/io/File:createTempFile	(Ljava/lang/String;Ljava/lang/String;Ljava/io/File;)Ljava/io/File;
    //   119: astore 4
    //   121: ldc_w 594
    //   124: ldc_w 595
    //   127: invokestatic 1294	org/eclipse/core/runtime/adaptor/LocationManager:getOSGiConfigurationDir	()Ljava/io/File;
    //   130: invokestatic 1246	java/io/File:createTempFile	(Ljava/lang/String;Ljava/lang/String;Ljava/io/File;)Ljava/io/File;
    //   133: astore 5
    //   135: iload_1
    //   136: ifeq +17 -> 153
    //   139: aload_0
    //   140: getfield 1209	org/eclipse/osgi/internal/baseadaptor/BaseStorage:stateManager	Lorg/eclipse/osgi/internal/baseadaptor/StateManager;
    //   143: aload 4
    //   145: aload 5
    //   147: invokevirtual 1421	org/eclipse/osgi/internal/baseadaptor/StateManager:shutdown	(Ljava/io/File;Ljava/io/File;)V
    //   150: goto +32 -> 182
    //   153: aload_0
    //   154: getfield 1209	org/eclipse/osgi/internal/baseadaptor/BaseStorage:stateManager	Lorg/eclipse/osgi/internal/baseadaptor/StateManager;
    //   157: dup
    //   158: astore 6
    //   160: monitorenter
    //   161: aload_0
    //   162: getfield 1209	org/eclipse/osgi/internal/baseadaptor/BaseStorage:stateManager	Lorg/eclipse/osgi/internal/baseadaptor/StateManager;
    //   165: aload 4
    //   167: aload 5
    //   169: invokevirtual 1422	org/eclipse/osgi/internal/baseadaptor/StateManager:update	(Ljava/io/File;Ljava/io/File;)V
    //   172: aload 6
    //   174: monitorexit
    //   175: goto +7 -> 182
    //   178: aload 6
    //   180: monitorexit
    //   181: athrow
    //   182: aload_0
    //   183: getfield 1210	org/eclipse/osgi/internal/baseadaptor/BaseStorage:storageManager	Lorg/eclipse/osgi/storagemanager/StorageManager;
    //   186: ldc_w 596
    //   189: iconst_1
    //   190: invokevirtual 1430	org/eclipse/osgi/storagemanager/StorageManager:lookup	(Ljava/lang/String;Z)Ljava/io/File;
    //   193: pop
    //   194: aload_0
    //   195: getfield 1210	org/eclipse/osgi/internal/baseadaptor/BaseStorage:storageManager	Lorg/eclipse/osgi/storagemanager/StorageManager;
    //   198: ldc_w 594
    //   201: iconst_1
    //   202: invokevirtual 1430	org/eclipse/osgi/storagemanager/StorageManager:lookup	(Ljava/lang/String;Z)Ljava/io/File;
    //   205: pop
    //   206: aload_0
    //   207: getfield 1210	org/eclipse/osgi/internal/baseadaptor/BaseStorage:storageManager	Lorg/eclipse/osgi/storagemanager/StorageManager;
    //   210: iconst_2
    //   211: anewarray 654	java/lang/String
    //   214: dup
    //   215: iconst_0
    //   216: ldc_w 596
    //   219: aastore
    //   220: dup
    //   221: iconst_1
    //   222: ldc_w 594
    //   225: aastore
    //   226: iconst_2
    //   227: anewarray 654	java/lang/String
    //   230: dup
    //   231: iconst_0
    //   232: aload 4
    //   234: invokevirtual 1240	java/io/File:getName	()Ljava/lang/String;
    //   237: aastore
    //   238: dup
    //   239: iconst_1
    //   240: aload 5
    //   242: invokevirtual 1240	java/io/File:getName	()Ljava/lang/String;
    //   245: aastore
    //   246: invokevirtual 1433	org/eclipse/osgi/storagemanager/StorageManager:update	([Ljava/lang/String;[Ljava/lang/String;)V
    //   249: goto +120 -> 369
    //   252: astore 6
    //   254: aload_0
    //   255: getfield 1204	org/eclipse/osgi/internal/baseadaptor/BaseStorage:adaptor	Lorg/eclipse/osgi/baseadaptor/BaseAdaptor;
    //   258: invokevirtual 1299	org/eclipse/osgi/baseadaptor/BaseAdaptor:getFrameworkLog	()Lorg/eclipse/osgi/framework/log/FrameworkLog;
    //   261: new 718	org/osgi/framework/FrameworkEvent
    //   264: dup
    //   265: iconst_2
    //   266: aload_0
    //   267: getfield 1211	org/eclipse/osgi/internal/baseadaptor/BaseStorage:context	Lorg/osgi/framework/BundleContext;
    //   270: invokeinterface 1486 1 0
    //   275: aload 6
    //   277: invokespecial 1442	org/osgi/framework/FrameworkEvent:<init>	(ILorg/osgi/framework/Bundle;Ljava/lang/Throwable;)V
    //   280: invokeinterface 1459 2 0
    //   285: aload 4
    //   287: ifnull +17 -> 304
    //   290: aload 4
    //   292: invokevirtual 1235	java/io/File:exists	()Z
    //   295: ifeq +9 -> 304
    //   298: aload 4
    //   300: invokevirtual 1234	java/io/File:delete	()Z
    //   303: pop
    //   304: aload 5
    //   306: ifnull +101 -> 407
    //   309: aload 5
    //   311: invokevirtual 1235	java/io/File:exists	()Z
    //   314: ifeq +93 -> 407
    //   317: aload 5
    //   319: invokevirtual 1234	java/io/File:delete	()Z
    //   322: pop
    //   323: goto +84 -> 407
    //   326: astore 7
    //   328: aload 4
    //   330: ifnull +17 -> 347
    //   333: aload 4
    //   335: invokevirtual 1235	java/io/File:exists	()Z
    //   338: ifeq +9 -> 347
    //   341: aload 4
    //   343: invokevirtual 1234	java/io/File:delete	()Z
    //   346: pop
    //   347: aload 5
    //   349: ifnull +17 -> 366
    //   352: aload 5
    //   354: invokevirtual 1235	java/io/File:exists	()Z
    //   357: ifeq +9 -> 366
    //   360: aload 5
    //   362: invokevirtual 1234	java/io/File:delete	()Z
    //   365: pop
    //   366: aload 7
    //   368: athrow
    //   369: aload 4
    //   371: ifnull +17 -> 388
    //   374: aload 4
    //   376: invokevirtual 1235	java/io/File:exists	()Z
    //   379: ifeq +9 -> 388
    //   382: aload 4
    //   384: invokevirtual 1234	java/io/File:delete	()Z
    //   387: pop
    //   388: aload 5
    //   390: ifnull +17 -> 407
    //   393: aload 5
    //   395: invokevirtual 1235	java/io/File:exists	()Z
    //   398: ifeq +9 -> 407
    //   401: aload 5
    //   403: invokevirtual 1234	java/io/File:delete	()Z
    //   406: pop
    //   407: return
    // Line number table:
    //   Java source line #638	-> byte code offset #0
    //   Java source line #639	-> byte code offset #8
    //   Java source line #641	-> byte code offset #27
    //   Java source line #642	-> byte code offset #41
    //   Java source line #643	-> byte code offset #48
    //   Java source line #644	-> byte code offset #53
    //   Java source line #645	-> byte code offset #57
    //   Java source line #646	-> byte code offset #58
    //   Java source line #648	-> byte code offset #64
    //   Java source line #649	-> byte code offset #88
    //   Java source line #650	-> byte code offset #89
    //   Java source line #651	-> byte code offset #95
    //   Java source line #652	-> byte code offset #101
    //   Java source line #653	-> byte code offset #104
    //   Java source line #655	-> byte code offset #107
    //   Java source line #656	-> byte code offset #121
    //   Java source line #657	-> byte code offset #135
    //   Java source line #658	-> byte code offset #139
    //   Java source line #660	-> byte code offset #153
    //   Java source line #661	-> byte code offset #161
    //   Java source line #660	-> byte code offset #172
    //   Java source line #663	-> byte code offset #182
    //   Java source line #664	-> byte code offset #194
    //   Java source line #665	-> byte code offset #206
    //   Java source line #666	-> byte code offset #252
    //   Java source line #667	-> byte code offset #254
    //   Java source line #669	-> byte code offset #285
    //   Java source line #670	-> byte code offset #298
    //   Java source line #671	-> byte code offset #304
    //   Java source line #672	-> byte code offset #317
    //   Java source line #668	-> byte code offset #326
    //   Java source line #669	-> byte code offset #328
    //   Java source line #670	-> byte code offset #341
    //   Java source line #671	-> byte code offset #347
    //   Java source line #672	-> byte code offset #360
    //   Java source line #673	-> byte code offset #366
    //   Java source line #669	-> byte code offset #369
    //   Java source line #670	-> byte code offset #382
    //   Java source line #671	-> byte code offset #388
    //   Java source line #672	-> byte code offset #401
    //   Java source line #674	-> byte code offset #407
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	408	0	this	BaseStorage
    //   0	408	1	shutdown	boolean
    //   7	53	2	systemState	State
    //   47	14	3	removalPendings	BundleDescription[]
    //   102	281	4	stateTmpFile	File
    //   105	297	5	lazyTmpFile	File
    //   158	21	6	Ljava/lang/Object;	Object
    //   252	24	6	e	IOException
    //   326	41	7	localObject1	Object
    // Exception table:
    //   from	to	target	type
    //   161	175	178	finally
    //   178	181	178	finally
    //   107	249	252	java/io/IOException
    //   107	285	326	finally
  }
  
  public PermissionStorage getPermissionStorage()
  {
    if (permissionStorage == null) {
      permissionStorage = readPermissionData();
    }
    return permissionStorage;
  }
  
  public int getInitialBundleStartLevel()
  {
    return initialBundleStartLevel;
  }
  
  public void setInitialBundleStartLevel(int value)
  {
    initialBundleStartLevel = value;
    requestSave();
  }
  
  public void save(BaseData data)
  {
    if (data.isDirty())
    {
      timeStamp -= 1L;
      requestSave();
      data.setDirty(false);
    }
  }
  
  public BundleOperation installBundle(String location, URLConnection source)
  {
    BaseData data = createBaseData(getNextBundleId(), location);
    return new BundleInstall(data, source, this);
  }
  
  public BundleOperation updateBundle(BaseData data, URLConnection source)
  {
    return new BundleUpdate(data, source, this);
  }
  
  public BundleOperation uninstallBundle(BaseData data)
  {
    return new BundleUninstall(data, this);
  }
  
  protected Object getBundleContent(BaseData bundledata)
  {
    BaseStorageHook storageHook = (BaseStorageHook)bundledata.getStorageHook(BaseStorageHook.KEY);
    if (storageHook == null) {
      throw new IllegalStateException();
    }
    return storageHook.isReference() ? new File(storageHook.getFileName()) : new File(storageHook.getGenerationDir(), storageHook.getFileName());
  }
  
  public BundleFile createBundleFile(Object content, BaseData data)
    throws IOException
  {
    boolean base = false;
    if (content == null)
    {
      base = true;
      
      content = getBundleContent(data);
    }
    BundleFile result = data.getBundleFile(content, base);
    if (result != null) {
      return result;
    }
    BundleFileFactoryHook[] factories = adaptor.getHookRegistry().getBundleFileFactoryHooks();
    for (int i = 0; (i < factories.length) && (result == null); i++) {
      result = factories[i].createBundleFile(content, data, base);
    }
    if ((result == null) && ((content instanceof File)))
    {
      File file = (File)content;
      if (isDirectory(data, base, file)) {
        result = new DirBundleFile(file);
      } else {
        result = new ZipBundleFile(file, data, getMRUList());
      }
    }
    if ((result == null) && ((content instanceof String))) {
      result = new NestedDirBundleFile(data.getBundleFile(), (String)content);
    }
    if (result == null) {
      throw new IOException("Cannot create bundle file for content of type: " + content.getClass().getName());
    }
    BundleFileWrapperFactoryHook[] wrapperFactories = adaptor.getHookRegistry().getBundleFileWrapperFactoryHooks();
    BundleFileWrapperChain wrapped = wrapperFactories.length == 0 ? null : new BundleFileWrapperChain(result, null);
    for (int i = 0; i < wrapperFactories.length; i++)
    {
      BundleFile wrapperBundle = wrapperFactories[i].wrapBundleFile(result, content, data, base);
      if ((wrapperBundle != null) && (wrapperBundle != result)) {
        result = wrapped = new BundleFileWrapperChain(wrapperBundle, wrapped);
      }
    }
    if (!base) {
      data.setBundleFile(content, result);
    }
    return result;
  }
  
  private synchronized MRUBundleFileList getMRUList()
  {
    if (mruList == null) {
      mruList = new MRUBundleFileList();
    }
    return mruList;
  }
  
  private boolean isDirectory(BaseData data, boolean base, File file)
  {
    if (!base) {
      return file.isDirectory();
    }
    boolean isDirectory = false;
    
    int type = data.getType();
    if ((type & 0x30000000) == 0)
    {
      isDirectory = file.isDirectory();
      data.setType(type | (isDirectory ? 268435456 : 536870912));
    }
    else
    {
      isDirectory = (type & 0x10000000) != 0;
    }
    return isDirectory;
  }
  
  public synchronized StateManager getStateManager()
  {
    if (stateManager != null) {
      return stateManager;
    }
    stateManager = readStateData();
    checkSystemState(stateManager.getSystemState());
    return stateManager;
  }
  
  private void checkSystemState(State state)
  {
    BundleDescription[] bundles = state.getBundles();
    if (bundles == null) {
      return;
    }
    boolean removedBundle = false;
    for (int i = 0; i < bundles.length; i++) {
      if (adaptor.getBundle(bundles[i].getBundleId()) == null)
      {
        state.removeBundle(bundles[i]);
        removedBundle = true;
      }
    }
    if (removedBundle) {
      state.resolve(false);
    }
    BundleDescription systemBundle = state.getBundle(0L);
    if ((systemBundle == null) || (!systemBundle.isResolved()))
    {
      ResolverError[] errors = systemBundle == null ? new ResolverError[0] : state.getResolverErrors(systemBundle);
      StringBuffer sb = new StringBuffer();
      for (int i = 0; i < errors.length; i++)
      {
        sb.append(errors[i].toString());
        if (i < errors.length - 1) {
          sb.append(", ");
        }
      }
      throw new IllegalStateException(NLS.bind(AdaptorMsg.SYSTEMBUNDLE_NOTRESOLVED, sb.toString()));
    }
  }
  
  private StateManager readStateData()
  {
    File[] stateFiles = findStorageFiles(new String[] { ".state", ".lazy" });
    File stateFile = stateFiles[0];
    File lazyFile = stateFiles[1];
    
    stateManager = new StateManager(stateFile, lazyFile, context, timeStamp);
    State systemState = null;
    if (!invalidState)
    {
      systemState = stateManager.readSystemState();
      if (systemState != null) {
        return stateManager;
      }
    }
    systemState = stateManager.createSystemState();
    Bundle[] installedBundles = context.getBundles();
    if (installedBundles == null) {
      return stateManager;
    }
    StateObjectFactory factory = stateManager.getFactory();
    for (int i = 0; i < installedBundles.length; i++)
    {
      AbstractBundle toAdd = (AbstractBundle)installedBundles[i];
      try
      {
        Dictionary<String, String> toAddManifest = loadManifest((BaseData)toAdd.getBundleData(), true);
        BundleDescription newDescription = factory.createBundleDescription(systemState, toAddManifest, toAdd.getLocation(), toAdd.getBundleId());
        systemState.addBundle(newDescription);
      }
      catch (BundleException localBundleException) {}
    }
    systemState.resolve();
    invalidState = false;
    return stateManager;
  }
  
  private File[] findStorageFiles(String[] fileNames)
  {
    File[] storageFiles = new File[fileNames.length];
    try
    {
      for (int i = 0; i < storageFiles.length; i++) {
        storageFiles[i] = storageManager.lookup(fileNames[i], false);
      }
    }
    catch (IOException ex)
    {
      if (Debug.DEBUG_GENERAL)
      {
        Debug.println("Error reading state file " + ex.getMessage());
        Debug.printStackTrace(ex);
      }
    }
    boolean success = true;
    for (int i = 0; i < storageFiles.length; i++) {
      if ((storageFiles[i] == null) || (!storageFiles[i].isFile()))
      {
        success = false;
        break;
      }
    }
    if (success) {
      return storageFiles;
    }
    Location parentConfiguration = null;
    Location currentConfiguration = LocationManager.getConfigurationLocation();
    if ((currentConfiguration != null) && ((parentConfiguration = currentConfiguration.getParentLocation()) != null))
    {
      try
      {
        File stateLocationDir = new File(parentConfiguration.getURL().getFile(), "org.eclipse.osgi");
        StorageManager newFileManager = initFileManager(stateLocationDir, "none", true);
        for (int i = 0; i < storageFiles.length; i++) {
          storageFiles[i] = newFileManager.lookup(fileNames[i], false);
        }
        newFileManager.close();
      }
      catch (IOException ex)
      {
        if (!Debug.DEBUG_GENERAL) {
          return storageFiles;
        }
      }
      Debug.println("Error reading state file " + ex.getMessage());
      Debug.printStackTrace(ex);
    }
    else
    {
      try
      {
        if (!isReadOnly()) {
          for (int i = 0; i < storageFiles.length; i++) {
            storageFiles[i] = storageManager.lookup(fileNames[i], true);
          }
        }
      }
      catch (IOException ex)
      {
        if (Debug.DEBUG_GENERAL)
        {
          Debug.println("Error reading state file " + ex.getMessage());
          Debug.printStackTrace(ex);
        }
      }
    }
    return storageFiles;
  }
  
  public void frameworkStart(BundleContext fwContext)
  {
    context = fwContext;
    if (Boolean.valueOf(FrameworkProperties.getProperty("eclipse.enableStateSaver", "true")).booleanValue()) {
      stateSaver = new StateSaver();
    }
  }
  
  public void frameworkStop(BundleContext fwContext)
  {
    if (stateSaver != null) {
      stateSaver.shutdown();
    }
    saveAllData(true);
    storageManager.close();
    storageManagerClosed = true;
    if (extensionListener != null) {
      context.removeBundleListener(extensionListener);
    }
    MRUBundleFileList current = mruList;
    if (current != null) {
      current.shutdown();
    }
    mruList = null;
    stateManager = null;
  }
  
  public void frameworkStopping(BundleContext fwContext) {}
  
  public void addProperties(Properties properties)
  {
    if (addFwkURLMethod != null) {
      properties.put("org.osgi.supports.framework.extension", "true");
    }
    properties.put("osgi.bundlestore", getBundleStoreRoot().getAbsolutePath());
  }
  
  private InputStream findStorageStream(String fileName)
  {
    InputStream storageStream = null;
    try
    {
      storageStream = storageManager.getInputStream(fileName);
    }
    catch (IOException ex)
    {
      if (Debug.DEBUG_GENERAL)
      {
        Debug.println("Error reading framework metadata: " + ex.getMessage());
        Debug.printStackTrace(ex);
      }
    }
    if (storageStream == null)
    {
      Location currentConfiguration = LocationManager.getConfigurationLocation();
      Location parentConfiguration = null;
      if ((currentConfiguration != null) && ((parentConfiguration = currentConfiguration.getParentLocation()) != null)) {
        try
        {
          File bundledataLocationDir = new File(parentConfiguration.getURL().getFile(), "org.eclipse.osgi");
          StorageManager newStorageManager = initFileManager(bundledataLocationDir, "none", true);
          storageStream = newStorageManager.getInputStream(fileName);
          newStorageManager.close();
        }
        catch (MalformedURLException localMalformedURLException) {}catch (IOException localIOException1) {}
      }
    }
    return storageStream;
  }
  
  protected void saveBaseData(BaseData bundledata, DataOutputStream out)
    throws IOException
  {
    StorageHook[] hooks = bundledata.getStorageHooks();
    out.writeInt(hooks.length);
    for (int i = 0; i < hooks.length; i++)
    {
      out.writeUTF((String)hooks[i].getKey());
      hooks[i].save(out);
    }
  }
  
  protected BaseData loadBaseData(long id, DataInputStream in)
    throws IOException
  {
    BaseData result = new BaseData(id, adaptor);
    int numHooks = in.readInt();
    StorageHook[] hooks = new StorageHook[numHooks];
    for (int i = 0; i < numHooks; i++)
    {
      String hookKey = in.readUTF();
      StorageHook storageHook = (StorageHook)storageHooks.getByKey(hookKey);
      if (storageHook == null) {
        throw new IOException();
      }
      hooks[i] = storageHook.load(result, in);
    }
    result.setStorageHooks(hooks);
    return result;
  }
  
  protected BaseData createBaseData(long id, String location)
  {
    BaseData result = new BaseData(id, adaptor);
    result.setLocation(location);
    return result;
  }
  
  public String getInstallPath()
  {
    return installPath;
  }
  
  private void cleanOSGiCache()
  {
    File osgiConfig = LocationManager.getOSGiConfigurationDir();
    if (!AdaptorUtil.rm(osgiConfig)) {
      adaptor.getFrameworkLog().log(new FrameworkLogEntry("org.eclipse.osgi", 4, 0, "The -clean (osgi.clean) option was not successful. Unable to clean the storage area: " + osgiConfig.getAbsolutePath(), 0, null, null));
    }
  }
  
  protected void processExtension(BaseData bundleData, byte type)
    throws BundleException
  {
    if ((bundleData.getType() & 0x2) != 0)
    {
      validateExtension(bundleData);
      processFrameworkExtension(bundleData, type);
    }
    else if ((bundleData.getType() & 0x4) != 0)
    {
      validateExtension(bundleData);
      processBootExtension(bundleData, type);
    }
    else if ((bundleData.getType() & 0x10) != 0)
    {
      validateExtension(bundleData);
      processExtExtension(bundleData, type);
    }
  }
  
  private void validateExtension(BundleData bundleData)
    throws BundleException
  {
    Dictionary<String, String> extensionManifest = bundleData.getManifest();
    if (extensionManifest.get("Import-Package") != null) {
      throw new BundleException(NLS.bind(AdaptorMsg.ADAPTOR_EXTENSION_IMPORT_ERROR, bundleData.getLocation()), 3);
    }
    if (extensionManifest.get("Require-Bundle") != null) {
      throw new BundleException(NLS.bind(AdaptorMsg.ADAPTOR_EXTENSION_REQUIRE_ERROR, bundleData.getLocation()), 3);
    }
    if (extensionManifest.get("Bundle-NativeCode") != null) {
      throw new BundleException(NLS.bind(AdaptorMsg.ADAPTOR_EXTENSION_NATIVECODE_ERROR, bundleData.getLocation()), 3);
    }
  }
  
  protected void processFrameworkExtension(BaseData bundleData, byte type)
    throws BundleException
  {
    if (addFwkURLMethod == null) {
      throw new BundleException("Framework extensions are not supported.", 1, new UnsupportedOperationException());
    }
    addExtensionContent(bundleData, type, getFwkClassLoader(), addFwkURLMethod);
  }
  
  protected void processExtExtension(BaseData bundleData, byte type)
    throws BundleException
  {
    if (addExtURLMethod == null) {
      throw new BundleException("Extension classpath extensions are not supported.", 1, new UnsupportedOperationException());
    }
    addExtensionContent(bundleData, type, getExtClassLoader(), addExtURLMethod);
  }
  
  private void addExtensionContent(BaseData bundleData, byte type, ClassLoader addToLoader, Method addToMethod)
  {
    if ((type & 0xC) != 0) {
      return;
    }
    String[] extensions = getConfiguredExtensions();
    for (int i = 0; i < extensions.length; i++) {
      if (extensions[i].equals(bundleData.getSymbolicName())) {
        return;
      }
    }
    if ((type & 0x2) != 0)
    {
      if (extensionListener == null)
      {
        extensionListener = this;
        context.addBundleListener(extensionListener);
      }
      return;
    }
    File[] files = getExtensionFiles(bundleData);
    if (files == null) {
      return;
    }
    for (int i = 0; i < files.length; i++) {
      if (files[i] != null) {
        try
        {
          callAddURLMethod(addToLoader, addToMethod, AdaptorUtil.encodeFileURL(files[i]));
        }
        catch (InvocationTargetException e)
        {
          adaptor.getEventPublisher().publishFrameworkEvent(2, bundleData.getBundle(), e);
        }
        catch (MalformedURLException e)
        {
          adaptor.getEventPublisher().publishFrameworkEvent(2, bundleData.getBundle(), e);
        }
      }
    }
    try
    {
      addToLoader.loadClass("thisIsNotAClass");
    }
    catch (ClassNotFoundException localClassNotFoundException) {}
  }
  
  protected String[] getConfiguredExtensions()
  {
    if (configuredExtensions != null) {
      return configuredExtensions;
    }
    String prop = FrameworkProperties.getProperty("osgi.framework.extensions");
    if ((prop == null) || (prop.trim().length() == 0)) {
      configuredExtensions = new String[0];
    } else {
      configuredExtensions = ManifestElement.getArrayFromList(prop);
    }
    return configuredExtensions;
  }
  
  protected void processBootExtension(BundleData bundleData, byte type)
    throws BundleException
  {
    throw new BundleException("Boot classpath extensions are not supported.", 1, new UnsupportedOperationException());
  }
  
  private void initBundleStoreRoot()
  {
    File configurationLocation = LocationManager.getOSGiConfigurationDir();
    if (configurationLocation != null) {
      bundleStoreRoot = new File(configurationLocation, "bundles");
    } else {
      bundleStoreRoot = new File("bundles");
    }
  }
  
  public File getBundleStoreRoot()
  {
    if (bundleStoreRoot == null) {
      initBundleStoreRoot();
    }
    return bundleStoreRoot;
  }
  
  protected File[] getExtensionFiles(BaseData bundleData)
  {
    File[] files = (File[])null;
    try
    {
      String[] paths = bundleData.getClassPath();
      if (DevClassPathHelper.inDevelopmentMode())
      {
        String[] devPaths = DevClassPathHelper.getDevClassPath(bundleData.getSymbolicName());
        String[] origPaths = paths;
        
        paths = new String[origPaths.length + devPaths.length];
        System.arraycopy(origPaths, 0, paths, 0, origPaths.length);
        System.arraycopy(devPaths, 0, paths, origPaths.length, devPaths.length);
      }
      List<File> results = new ArrayList(paths.length);
      for (int i = 0; i < paths.length; i++) {
        if (".".equals(paths[i]))
        {
          results.add(bundleData.getBundleFile().getBaseFile());
        }
        else
        {
          File result = bundleData.getBundleFile().getFile(paths[i], false);
          if (result != null) {
            results.add(result);
          }
        }
      }
      return (File[])results.toArray(new File[results.size()]);
    }
    catch (BundleException e)
    {
      adaptor.getEventPublisher().publishFrameworkEvent(2, bundleData.getBundle(), e);
    }
    return files;
  }
  
  void requestSave()
  {
    if (stateSaver == null) {
      return;
    }
    stateSaver.requestSave();
  }
  
  public void updateState(BaseData bundleData, int type)
    throws BundleException
  {
    if (stateManager == null)
    {
      invalidState = true;
      return;
    }
    State systemState = stateManager.getSystemState();
    BundleDescription oldDescription = null;
    BundleDescription newDescription = null;
    switch (type)
    {
    case 1: 
    case 8: 
      if (type == 8) {
        oldDescription = systemState.getBundle(bundleData.getBundleID());
      }
      newDescription = stateManager.getFactory().createBundleDescription(systemState, bundleData.getManifest(), bundleData.getLocation(), bundleData.getBundleID());
      
      newDescription.setUserObject(bundleData);
      if (oldDescription == null) {
        systemState.addBundle(newDescription);
      } else {
        systemState.updateBundle(newDescription);
      }
      break;
    case 16: 
      systemState.removeBundle(bundleData.getBundleID());
    }
    if (newDescription != null) {
      validateNativeCodePaths(newDescription, bundleData);
    }
  }
  
  private void validateNativeCodePaths(BundleDescription newDescription, BaseData data)
  {
    NativeCodeSpecification nativeCode = newDescription.getNativeCodeSpecification();
    if (nativeCode == null) {
      return;
    }
    NativeCodeDescription[] nativeCodeDescs = nativeCode.getPossibleSuppliers();
    for (int i = 0; i < nativeCodeDescs.length; i++)
    {
      BaseStorageHook storageHook = (BaseStorageHook)data.getStorageHook(BaseStorageHook.KEY);
      if (storageHook != null) {
        try
        {
          storageHook.validateNativePaths(nativeCodeDescs[i].getNativePaths());
        }
        catch (BundleException localBundleException)
        {
          stateManager.getSystemState().setNativePathsInvalid(nativeCodeDescs[i], true);
        }
      }
    }
  }
  
  /* Error */
  public long getNextBundleId()
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 1199	org/eclipse/osgi/internal/baseadaptor/BaseStorage:nextIdMonitor	Ljava/lang/Object;
    //   4: dup
    //   5: astore_1
    //   6: monitorenter
    //   7: aload_0
    //   8: dup
    //   9: getfield 1193	org/eclipse/osgi/internal/baseadaptor/BaseStorage:nextId	J
    //   12: dup2_x1
    //   13: lconst_1
    //   14: ladd
    //   15: putfield 1193	org/eclipse/osgi/internal/baseadaptor/BaseStorage:nextId	J
    //   18: aload_1
    //   19: monitorexit
    //   20: lreturn
    //   21: aload_1
    //   22: monitorexit
    //   23: athrow
    // Line number table:
    //   Java source line #1374	-> byte code offset #0
    //   Java source line #1375	-> byte code offset #7
    //   Java source line #1374	-> byte code offset #21
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	24	0	this	BaseStorage
    //   5	17	1	Ljava/lang/Object;	Object
    // Exception table:
    //   from	to	target	type
    //   7	20	21	finally
    //   21	23	21	finally
  }
  
  private class StateSaver
    implements Runnable
  {
    private final long delay_interval;
    private final long max_total_delay_interval;
    private boolean shutdown = false;
    private long lastSaveTime = 0L;
    private Thread runningThread = null;
    private Thread shutdownHook = null;
    
    StateSaver()
    {
      String prop = FrameworkProperties.getProperty("eclipse.stateSaveDelayInterval");
      long delayValue = 30000L;
      long maxDelayValue = 1800000L;
      if (prop != null) {
        try
        {
          long val = Long.parseLong(prop);
          if ((val >= 1000L) && (val <= 1800000L))
          {
            delayValue = val;
            maxDelayValue = val * 60L;
          }
          else if (val == 0L)
          {
            delayValue = 0L;
            maxDelayValue = 0L;
          }
        }
        catch (NumberFormatException localNumberFormatException) {}
      }
      delay_interval = delayValue;
      max_total_delay_interval = maxDelayValue;
    }
    
    public void run()
    {
      State systemState = adaptor.getState();
      synchronized (systemState)
      {
        long firstSaveTime = lastSaveTime;
        long curSaveTime = 0L;
        do
        {
          do
          {
            if (System.currentTimeMillis() - firstSaveTime > max_total_delay_interval)
            {
              curSaveTime = lastSaveTime;
              
              break;
            }
            long delayTime = Math.min(delay_interval, lastSaveTime - curSaveTime);
            curSaveTime = lastSaveTime;
            try
            {
              if (!shutdown) {
                systemState.wait(delayTime);
              }
            }
            catch (InterruptedException localInterruptedException)
            {
              curSaveTime = lastSaveTime;
              break;
            }
          } while ((!shutdown) && (curSaveTime < lastSaveTime));
          saveAllData(false);
        } while ((!shutdown) && (curSaveTime < lastSaveTime));
        runningThread = null;
        try
        {
          Runtime.getRuntime().removeShutdownHook(shutdownHook);
        }
        catch (IllegalStateException localIllegalStateException) {}
        shutdownHook = null;
      }
    }
    
    void shutdown()
    {
      State systemState = adaptor.getState();
      Thread joinWith = null;
      synchronized (systemState)
      {
        shutdown = true;
        joinWith = runningThread;
        systemState.notifyAll();
      }
      try
      {
        if (joinWith != null)
        {
          if (Debug.DEBUG_GENERAL) {
            Debug.println("About to join saving thread");
          }
          joinWith.join();
          if (Debug.DEBUG_GENERAL) {
            Debug.println("Joined with saving thread");
          }
        }
      }
      catch (InterruptedException ie)
      {
        if (Debug.DEBUG_GENERAL)
        {
          Debug.println("Error shutdowning StateSaver: " + ie.getMessage());
          Debug.printStackTrace(ie);
        }
      }
    }
    
    void requestSave()
    {
      State systemState = adaptor.getState();
      synchronized (systemState)
      {
        if (shutdown) {
          return;
        }
        if (delay_interval == 0L)
        {
          saveAllData(false);
          return;
        }
        lastSaveTime = System.currentTimeMillis();
        if (runningThread == null)
        {
          shutdownHook = new Thread(new Runnable()
          {
            public void run()
            {
              shutdown();
            }
          });
          runningThread = new Thread(this, "State Saver");
          runningThread.start();
          Runtime.getRuntime().addShutdownHook(shutdownHook);
        }
      }
    }
  }
  
  public void bundleChanged(BundleEvent event)
  {
    if (event.getType() != 32) {
      return;
    }
    BaseData data = (BaseData)((AbstractBundle)event.getBundle()).getBundleData();
    try
    {
      if ((data.getType() & 0x2) != 0) {
        processFrameworkExtension(data, (byte)1);
      } else if ((data.getType() & 0x4) != 0) {
        processBootExtension(data, (byte)1);
      } else if ((data.getType() & 0x10) != 0) {
        processExtExtension(data, (byte)1);
      }
    }
    catch (BundleException localBundleException) {}
  }
  
  public String copyToTempLibrary(BaseData data, String absolutePath)
    throws IOException
  {
    File storageRoot = getBundleStoreRoot();
    File libTempDir = new File(storageRoot, "libtemp");
    
    File realLib = new File(absolutePath);
    String libName = realLib.getName();
    
    File bundleTempDir = null;
    File libTempFile = null;
    
    Long bundleID = new Long(data.getBundleID());
    for (int i = 0; i < Integer.MAX_VALUE; i++)
    {
      bundleTempDir = new File(libTempDir, bundleID.toString() + "_" + new Integer(i).toString());
      libTempFile = new File(bundleTempDir, libName);
      if ((!bundleTempDir.exists()) || 
        (!libTempFile.exists())) {
        break;
      }
    }
    if (!bundleTempDir.exists())
    {
      bundleTempDir.mkdirs();
      bundleTempDir.deleteOnExit();
      
      File deleteFlag = new File(libTempDir, ".delete");
      if (!deleteFlag.exists()) {
        try
        {
          FileOutputStream out = new FileOutputStream(deleteFlag);
          out.close();
        }
        catch (IOException localIOException) {}
      }
    }
    InputStream in = new FileInputStream(realLib);
    AdaptorUtil.readFile(in, libTempFile);
    
    BundleFile.setPermissions(libTempFile);
    libTempFile.deleteOnExit();
    
    return libTempFile.getAbsolutePath();
  }
}

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

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLConnection;
import java.util.Dictionary;
import java.util.Properties;
import java.util.StringTokenizer;
import org.eclipse.core.runtime.adaptor.LocationManager;
import org.eclipse.osgi.baseadaptor.BaseAdaptor;
import org.eclipse.osgi.baseadaptor.BaseData;
import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;
import org.eclipse.osgi.baseadaptor.bundlefile.BundleFile;
import org.eclipse.osgi.baseadaptor.hooks.AdaptorHook;
import org.eclipse.osgi.baseadaptor.hooks.StorageHook;
import org.eclipse.osgi.framework.adaptor.FilePath;
import org.eclipse.osgi.framework.debug.Debug;
import org.eclipse.osgi.framework.internal.core.AbstractBundle;
import org.eclipse.osgi.framework.internal.core.Constants;
import org.eclipse.osgi.framework.internal.core.FrameworkProperties;
import org.eclipse.osgi.framework.log.FrameworkLog;
import org.eclipse.osgi.framework.util.KeyedElement;
import org.eclipse.osgi.service.datalocation.Location;
import org.eclipse.osgi.util.ManifestElement;
import org.eclipse.osgi.util.NLS;
import o
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84

Further reading...

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

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd