org.eclipse.osgi_3.8.2.v20130124-134944

//   80: invokespecial 1235	java/io/DataOutputStream:<init>	(Ljava/io/OutputStream;)V
    //   83: astore_2
    //   84: iconst_1
    //   85: istore_3
    //   86: aload_2
    //   87: bipush 18
    //   89: invokevirtual 1232	java/io/DataOutputStream:writeByte	(I)V
    //   92: aload_2
    //   93: aload_0
    //   94: getfield 1213	org/eclipse/osgi/internal/baseadaptor/BaseStorage:stateManager	Lorg/eclipse/osgi/internal/baseadaptor/StateManager;
    //   97: invokevirtual 1423	org/eclipse/osgi/internal/baseadaptor/StateManager:getSystemState	()Lorg/eclipse/osgi/service/resolver/State;
    //   100: invokeinterface 1475 1 0
    //   105: invokevirtual 1234	java/io/DataOutputStream:writeLong	(J)V
    //   108: aload_2
    //   109: aload_0
    //   110: getfield 1196	org/eclipse/osgi/internal/baseadaptor/BaseStorage:initialBundleStartLevel	I
    //   113: invokevirtual 1233	java/io/DataOutputStream:writeInt	(I)V
    //   116: aload_2
    //   117: aload_0
    //   118: getfield 1197	org/eclipse/osgi/internal/baseadaptor/BaseStorage:nextId	J
    //   121: invokevirtual 1234	java/io/DataOutputStream:writeLong	(J)V
    //   124: aload_0
    //   125: getfield 1208	org/eclipse/osgi/internal/baseadaptor/BaseStorage:adaptor	Lorg/eclipse/osgi/baseadaptor/BaseAdaptor;
    //   128: invokevirtual 1301	org/eclipse/osgi/baseadaptor/BaseAdaptor:getHookRegistry	()Lorg/eclipse/osgi/baseadaptor/HookRegistry;
    //   131: invokevirtual 1326	org/eclipse/osgi/baseadaptor/HookRegistry:getStorageHooks	()[Lorg/eclipse/osgi/baseadaptor/hooks/StorageHook;
    //   134: astore 4
    //   136: aload_2
    //   137: aload 4
    //   139: arraylength
    //   140: invokevirtual 1233	java/io/DataOutputStream:writeInt	(I)V
    //   143: iconst_0
    //   144: istore 5
    //   146: goto +37 -> 183
    //   149: aload_2
    //   150: aload 4
    //   152: iload 5
    //   154: aaload
    //   155: invokeinterface 1456 1 0
    //   160: checkcast 655	java/lang/String
    //   163: invokevirtual 1236	java/io/DataOutputStream:writeUTF	(Ljava/lang/String;)V
    //   166: aload_2
    //   167: aload 4
    //   169: iload 5
    //   171: aaload
    //   172: invokeinterface 1453 1 0
    //   177: invokevirtual 1233	java/io/DataOutputStream:writeInt	(I)V
    //   180: iinc 5 1
    //   183: iload 5
    //   185: aload 4
    //   187: arraylength
    //   188: if_icmplt -39 -> 149
    //   191: aload_0
    //   192: getfield 1215	org/eclipse/osgi/internal/baseadaptor/BaseStorage:context	Lorg/osgi/framework/BundleContext;
    //   195: invokeinterface 1492 1 0
    //   200: astore 5
    //   202: aload_2
    //   203: aload 5
    //   205: arraylength
    //   206: invokevirtual 1233	java/io/DataOutputStream:writeInt	(I)V
    //   209: iconst_0
    //   210: istore 6
    //   212: goto +54 -> 266
    //   215: aload 5
    //   217: iload 6
    //   219: aaload
    //   220: invokeinterface 1490 1 0
    //   225: lstore 7
    //   227: aload_2
    //   228: lload 7
    //   230: invokevirtual 1234	java/io/DataOutputStream:writeLong	(J)V
    //   233: lload 7
    //   235: lconst_0
    //   236: lcmp
    //   237: ifeq +26 -> 263
    //   240: aload 5
    //   242: iload 6
    //   244: aaload
    //   245: checkcast 686	org/eclipse/osgi/framework/internal/core/AbstractBundle
    //   248: invokevirtual 1342	org/eclipse/osgi/framework/internal/core/AbstractBundle:getBundleData	()Lorg/eclipse/osgi/framework/adaptor/BundleData;
    //   251: astore 9
    //   253: aload_0
    //   254: aload 9
    //   256: checkcast 671	org/eclipse/osgi/baseadaptor/BaseData
    //   259: aload_2
    //   260: invokevirtual 1387	org/eclipse/osgi/internal/baseadaptor/BaseStorage:saveBaseData	(Lorg/eclipse/osgi/baseadaptor/BaseData;Ljava/io/DataOutputStream;)V
    //   263: iinc 6 1
    //   266: iload 6
    //   268: aload 5
    //   270: arraylength
    //   271: if_icmplt -56 -> 215
    //   274: aload_2
    //   275: invokevirtual 1231	java/io/DataOutputStream:close	()V
    //   278: aload_0
    //   279: aload_0
    //   280: getfield 1213	org/eclipse/osgi/internal/baseadaptor/BaseStorage:stateManager	Lorg/eclipse/osgi/internal/baseadaptor/StateManager;
    //   283: invokevirtual 1423	org/eclipse/osgi/internal/baseadaptor/StateManager:getSystemState	()Lorg/eclipse/osgi/service/resolver/State;
    //   286: invokeinterface 1475 1 0
    //   291: putfield 1198	org/eclipse/osgi/internal/baseadaptor/BaseStorage:timeStamp	J
    //   294: iconst_0
    //   295: istore_3
    //   296: goto +24 -> 320
    //   299: astore 10
    //   301: iload_3
    //   302: ifeq +15 -> 317
    //   305: aload_1
    //   306: invokevirtual 1431	org/eclipse/osgi/storagemanager/ManagedOutputStream:abort	()V
    //   309: aload_2
    //   310: invokevirtual 1231	java/io/DataOutputStream:close	()V
    //   313: goto +4 -> 317
    //   316: pop
    //   317: aload 10
    //   319: athrow
    //   320: iload_3
    //   321: ifeq +50 -> 371
    //   324: aload_1
    //   325: invokevirtual 1431	org/eclipse/osgi/storagemanager/ManagedOutputStream:abort	()V
    //   328: aload_2
    //   329: invokevirtual 1231	java/io/DataOutputStream:close	()V
    //   332: goto +39 -> 371
    //   335: pop
    //   336: goto +35 -> 371
    //   339: astore_1
    //   340: aload_0
    //   341: getfield 1208	org/eclipse/osgi/internal/baseadaptor/BaseStorage:adaptor	Lorg/eclipse/osgi/baseadaptor/BaseAdaptor;
    //   344: invokevirtual 1303	org/eclipse/osgi/baseadaptor/BaseAdaptor:getFrameworkLog	()Lorg/eclipse/osgi/framework/log/FrameworkLog;
    //   347: new 719	org/osgi/framework/FrameworkEvent
    //   350: dup
    //   351: iconst_2
    //   352: aload_0
    //   353: getfield 1215	org/eclipse/osgi/internal/baseadaptor/BaseStorage:context	Lorg/osgi/framework/BundleContext;
    //   356: invokeinterface 1491 1 0
    //   361: aload_1
    //   362: invokespecial 1447	org/osgi/framework/FrameworkEvent:<init>	(ILorg/osgi/framework/Bundle;Ljava/lang/Throwable;)V
    //   365: invokeinterface 1464 2 0
    //   370: return
    //   371: return
    // Line number table:
    //   Java source line #567	-> byte code offset #0
    //   Java source line #568	-> byte code offset #44
    //   Java source line #569	-> byte code offset #45
    //   Java source line #570	-> byte code offset #51
    //   Java source line #572	-> byte code offset #57
    //   Java source line #573	-> byte code offset #68
    //   Java source line #574	-> byte code offset #84
    //   Java source line #576	-> byte code offset #86
    //   Java source line #577	-> byte code offset #92
    //   Java source line #578	-> byte code offset #108
    //   Java source line #579	-> byte code offset #116
    //   Java source line #581	-> byte code offset #124
    //   Java source line #582	-> byte code offset #136
    //   Java source line #583	-> byte code offset #143
    //   Java source line #584	-> byte code offset #149
    //   Java source line #585	-> byte code offset #166
    //   Java source line #583	-> byte code offset #180
    //   Java source line #588	-> byte code offset #191
    //   Java source line #589	-> byte code offset #202
    //   Java source line #590	-> byte code offset #209
    //   Java source line #591	-> byte code offset #215
    //   Java source line #592	-> byte code offset #227
    //   Java source line #593	-> byte code offset #233
    //   Java source line #594	-> byte code offset #240
    //   Java source line #595	-> byte code offset #253
    //   Java source line #590	-> byte code offset #263
    //   Java source line #598	-> byte code offset #274
    //   Java source line #600	-> byte code offset #278
    //   Java source line #601	-> byte code offset #294
    //   Java source line #602	-> byte code offset #296
    //   Java source line #604	-> byte code offset #301
    //   Java source line #605	-> byte code offset #305
    //   Java source line #607	-> byte code offset #309
    //   Java source line #608	-> byte code offset #313
    //   Java source line #611	-> byte code offset #317
    //   Java source line #604	-> byte code offset #320
    //   Java source line #605	-> byte code offset #324
    //   Java source line #607	-> byte code offset #328
    //   Java source line #608	-> byte code offset #332
    //   Java source line #612	-> byte code offset #336
    //   Java source line #613	-> byte code offset #340
    //   Java source line #614	-> byte code offset #370
    //   Java source line #616	-> byte code offset #371
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	372	0	this	BaseStorage
    //   67	258	1	fmos	org.eclipse.osgi.storagemanager.ManagedOutputStream
    //   339	23	1	e	IOException
    //   83	246	2	out	DataOutputStream
    //   85	236	3	error	boolean
    //   134	52	4	hooks	StorageHook[]
    //   144	40	5	i	int
    //   200	69	5	bundles	Bundle[]
    //   210	57	6	i	int
    //   225	9	7	id	long
    //   251	4	9	data	BundleData
    //   299	19	10	localObject	Object
    //   316	1	12	localIOException1	IOException
    //   335	1	13	localIOException2	IOException
    // 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 1213	org/eclipse/osgi/internal/baseadaptor/BaseStorage:stateManager	Lorg/eclipse/osgi/internal/baseadaptor/StateManager;
    //   4: invokevirtual 1423	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 632
    //   15: ldc_w 630
    //   18: invokestatic 1343	org/eclipse/osgi/framework/internal/core/FrameworkProperties:getProperty	(Ljava/lang/String;)Ljava/lang/String;
    //   21: invokevirtual 1279	java/lang/String:equals	(Ljava/lang/Object;)Z
    //   24: ifeq +17 -> 41
    //   27: aload_2
    //   28: aload_2
    //   29: invokeinterface 1475 1 0
    //   34: lconst_1
    //   35: ladd
    //   36: invokeinterface 1476 3 0
    //   41: aload_2
    //   42: invokeinterface 1478 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 1397	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 1213	org/eclipse/osgi/internal/baseadaptor/BaseStorage:stateManager	Lorg/eclipse/osgi/internal/baseadaptor/StateManager;
    //   68: ifnull +20 -> 88
    //   71: aload_0
    //   72: invokevirtual 1369	org/eclipse/osgi/internal/baseadaptor/BaseStorage:isReadOnly	()Z
    //   75: ifne +13 -> 88
    //   78: aload_0
    //   79: getfield 1213	org/eclipse/osgi/internal/baseadaptor/BaseStorage:stateManager	Lorg/eclipse/osgi/internal/baseadaptor/StateManager;
    //   82: invokevirtual 1421	org/eclipse/osgi/internal/baseadaptor/StateManager:saveNeeded	()Z
    //   85: ifne +4 -> 89
    //   88: return
    //   89: getstatic 1188	org/eclipse/osgi/framework/debug/Debug:DEBUG_GENERAL	Z
    //   92: ifeq +9 -> 101
    //   95: ldc_w 617
    //   98: invokestatic 1336	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 597
    //   110: ldc_w 596
    //   113: invokestatic 1298	org/eclipse/core/runtime/adaptor/LocationManager:getOSGiConfigurationDir	()Ljava/io/File;
    //   116: invokestatic 1250	java/io/File:createTempFile	(Ljava/lang/String;Ljava/lang/String;Ljava/io/File;)Ljava/io/File;
    //   119: astore 4
    //   121: ldc_w 595
    //   124: ldc_w 596
    //   127: invokestatic 1298	org/eclipse/core/runtime/adaptor/LocationManager:getOSGiConfigurationDir	()Ljava/io/File;
    //   130: invokestatic 1250	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 1213	org/eclipse/osgi/internal/baseadaptor/BaseStorage:stateManager	Lorg/eclipse/osgi/internal/baseadaptor/StateManager;
    //   143: aload 4
    //   145: aload 5
    //   147: invokevirtual 1426	org/eclipse/osgi/internal/baseadaptor/StateManager:shutdown	(Ljava/io/File;Ljava/io/File;)V
    //   150: goto +32 -> 182
    //   153: aload_0
    //   154: getfield 1213	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 1213	org/eclipse/osgi/internal/baseadaptor/BaseStorage:stateManager	Lorg/eclipse/osgi/internal/baseadaptor/StateManager;
    //   165: aload 4
    //   167: aload 5
    //   169: invokevirtual 1427	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: invokespecial 1386	org/eclipse/osgi/internal/baseadaptor/BaseStorage:getStorageManager	()Lorg/eclipse/osgi/storagemanager/StorageManager;
    //   186: astore 6
    //   188: aload 6
    //   190: ldc_w 597
    //   193: iconst_1
    //   194: invokevirtual 1435	org/eclipse/osgi/storagemanager/StorageManager:lookup	(Ljava/lang/String;Z)Ljava/io/File;
    //   197: pop
    //   198: aload 6
    //   200: ldc_w 595
    //   203: iconst_1
    //   204: invokevirtual 1435	org/eclipse/osgi/storagemanager/StorageManager:lookup	(Ljava/lang/String;Z)Ljava/io/File;
    //   207: pop
    //   208: aload 6
    //   210: iconst_2
    //   211: anewarray 655	java/lang/String
    //   214: dup
    //   215: iconst_0
    //   216: ldc_w 597
    //   219: aastore
    //   220: dup
    //   221: iconst_1
    //   222: ldc_w 595
    //   225: aastore
    //   226: iconst_2
    //   227: anewarray 655	java/lang/String
    //   230: dup
    //   231: iconst_0
    //   232: aload 4
    //   234: invokevirtual 1244	java/io/File:getName	()Ljava/lang/String;
    //   237: aastore
    //   238: dup
    //   239: iconst_1
    //   240: aload 5
    //   242: invokevirtual 1244	java/io/File:getName	()Ljava/lang/String;
    //   245: aastore
    //   246: invokevirtual 1438	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 1208	org/eclipse/osgi/internal/baseadaptor/BaseStorage:adaptor	Lorg/eclipse/osgi/baseadaptor/BaseAdaptor;
    //   258: invokevirtual 1303	org/eclipse/osgi/baseadaptor/BaseAdaptor:getFrameworkLog	()Lorg/eclipse/osgi/framework/log/FrameworkLog;
    //   261: new 719	org/osgi/framework/FrameworkEvent
    //   264: dup
    //   265: iconst_2
    //   266: aload_0
    //   267: getfield 1215	org/eclipse/osgi/internal/baseadaptor/BaseStorage:context	Lorg/osgi/framework/BundleContext;
    //   270: invokeinterface 1491 1 0
    //   275: aload 6
    //   277: invokespecial 1447	org/osgi/framework/FrameworkEvent:<init>	(ILorg/osgi/framework/Bundle;Ljava/lang/Throwable;)V
    //   280: invokeinterface 1464 2 0
    //   285: aload 4
    //   287: ifnull +17 -> 304
    //   290: aload 4
    //   292: invokevirtual 1239	java/io/File:exists	()Z
    //   295: ifeq +9 -> 304
    //   298: aload 4
    //   300: invokevirtual 1238	java/io/File:delete	()Z
    //   303: pop
    //   304: aload 5
    //   306: ifnull +101 -> 407
    //   309: aload 5
    //   311: invokevirtual 1239	java/io/File:exists	()Z
    //   314: ifeq +93 -> 407
    //   317: aload 5
    //   319: invokevirtual 1238	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 1239	java/io/File:exists	()Z
    //   338: ifeq +9 -> 347
    //   341: aload 4
    //   343: invokevirtual 1238	java/io/File:delete	()Z
    //   346: pop
    //   347: aload 5
    //   349: ifnull +17 -> 366
    //   352: aload 5
    //   354: invokevirtual 1239	java/io/File:exists	()Z
    //   357: ifeq +9 -> 366
    //   360: aload 5
    //   362: invokevirtual 1238	java/io/File:delete	()Z
    //   365: pop
    //   366: aload 7
    //   368: athrow
    //   369: aload 4
    //   371: ifnull +17 -> 388
    //   374: aload 4
    //   376: invokevirtual 1239	java/io/File:exists	()Z
    //   379: ifeq +9 -> 388
    //   382: aload 4
    //   384: invokevirtual 1238	java/io/File:delete	()Z
    //   387: pop
    //   388: aload 5
    //   390: ifnull +17 -> 407
    //   393: aload 5
    //   395: invokevirtual 1239	java/io/File:exists	()Z
    //   398: ifeq +9 -> 407
    //   401: aload 5
    //   403: invokevirtual 1238	java/io/File:delete	()Z
    //   406: pop
    //   407: return
    // Line number table:
    //   Java source line #642	-> byte code offset #0
    //   Java source line #643	-> byte code offset #8
    //   Java source line #645	-> byte code offset #27
    //   Java source line #646	-> byte code offset #41
    //   Java source line #647	-> byte code offset #48
    //   Java source line #648	-> byte code offset #53
    //   Java source line #649	-> byte code offset #57
    //   Java source line #650	-> byte code offset #58
    //   Java source line #652	-> byte code offset #64
    //   Java source line #653	-> byte code offset #88
    //   Java source line #654	-> byte code offset #89
    //   Java source line #655	-> byte code offset #95
    //   Java source line #656	-> byte code offset #101
    //   Java source line #657	-> byte code offset #104
    //   Java source line #659	-> byte code offset #107
    //   Java source line #660	-> byte code offset #121
    //   Java source line #661	-> byte code offset #135
    //   Java source line #662	-> byte code offset #139
    //   Java source line #664	-> byte code offset #153
    //   Java source line #665	-> byte code offset #161
    //   Java source line #664	-> byte code offset #172
    //   Java source line #667	-> byte code offset #182
    //   Java source line #668	-> byte code offset #188
    //   Java source line #669	-> byte code offset #198
    //   Java source line #670	-> byte code offset #208
    //   Java source line #671	-> byte code offset #249
    //   Java source line #672	-> byte code offset #254
    //   Java source line #674	-> byte code offset #285
    //   Java source line #675	-> byte code offset #298
    //   Java source line #676	-> byte code offset #304
    //   Java source line #677	-> byte code offset #317
    //   Java source line #673	-> byte code offset #326
    //   Java source line #674	-> byte code offset #328
    //   Java source line #675	-> byte code offset #341
    //   Java source line #676	-> byte code offset #347
    //   Java source line #677	-> byte code offset #360
    //   Java source line #678	-> byte code offset #366
    //   Java source line #674	-> byte code offset #369
    //   Java source line #675	-> byte code offset #382
    //   Java source line #676	-> byte code offset #388
    //   Java source line #677	-> byte code offset #401
    //   Java source line #679	-> 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
    //   186	23	6	curStorageManager	StorageManager
    //   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, mruList);
      }
    }
    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 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)
  {
    StorageManager curStorageManager = getStorageManager();
    File[] storageFiles = new File[fileNames.length];
    try
    {
      for (int i = 0; i < storageFiles.length; i++) {
        storageFiles[i] = curStorageManager.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] = curStorageManager.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(adaptor.getState());
    }
  }
  
  public void frameworkStop(BundleContext fwContext)
  {
    if (stateSaver != null) {
      stateSaver.shutdown();
    }
    saveAllData(true);
    storageManager.close();
    storageManagerClosed = true;
    if (extensionListener != null) {
      context.removeBundleListener(extensionListener);
    }
    mruList.shutdown();
    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 = getStorageManager().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 = 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) {
     
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