org.eclipse.osgi_3.8.2.v20130124-134944

blic static boolean DEBUG_PLATFORM_ADMIN_RESOLVER = false;
  public static boolean MONITOR_PLATFORM_ADMIN = false;
  public static String PROP_NO_LAZY_LOADING = "osgi.noLazyStateLoading";
  public static String PROP_LAZY_UNLOADING_TIME = "osgi.lazyStateUnloadingTime";
  private long expireTime = 300000L;
  private long readStartupTime;
  private StateImpl systemState;
  private final StateObjectFactoryImpl factory;
  private long lastTimeStamp;
  private boolean cachedState = false;
  private final File stateFile;
  private final File lazyFile;
  private final long expectedTimeStamp;
  private final BundleContext context;
  private Thread dataManagerThread;
  
  public StateManager(File stateFile, File lazyFile, BundleContext context)
  {
    this(stateFile, lazyFile, context, -1L);
  }
  
  public StateManager(File stateFile, File lazyFile, BundleContext context, long expectedTimeStamp)
  {
    this.stateFile = stateFile;
    this.lazyFile = lazyFile;
    this.context = context;
    this.expectedTimeStamp = expectedTimeStamp;
    factory = new StateObjectFactoryImpl();
  }
  
  public void shutdown(File saveStateFile, File saveLazyFile)
    throws IOException
  {
    writeState(systemState, saveStateFile, saveLazyFile);
    stopDataManager();
  }
  
  public void update(File updateStateFile, File updateLazyFile)
    throws IOException
  {
    writeState(systemState, updateStateFile, updateLazyFile);
    
    lastTimeStamp = systemState.getTimeStamp();
  }
  
  /* Error */
  private void internalReadSystemState()
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 263	org/eclipse/osgi/internal/baseadaptor/StateManager:stateFile	Ljava/io/File;
    //   4: ifnull +13 -> 17
    //   7: aload_0
    //   8: getfield 263	org/eclipse/osgi/internal/baseadaptor/StateManager:stateFile	Ljava/io/File;
    //   11: invokevirtual 270	java/io/File:isFile	()Z
    //   14: ifne +4 -> 18
    //   17: return
    //   18: getstatic 259	org/eclipse/osgi/internal/baseadaptor/StateManager:DEBUG_READER	Z
    //   21: ifeq +10 -> 31
    //   24: aload_0
    //   25: invokestatic 283	java/lang/System:currentTimeMillis	()J
    //   28: putfield 255	org/eclipse/osgi/internal/baseadaptor/StateManager:readStartupTime	J
    //   31: getstatic 265	org/eclipse/osgi/internal/baseadaptor/StateManager:PROP_NO_LAZY_LOADING	Ljava/lang/String;
    //   34: invokestatic 291	org/eclipse/osgi/framework/internal/core/FrameworkProperties:getProperty	(Ljava/lang/String;)Ljava/lang/String;
    //   37: invokestatic 274	java/lang/Boolean:valueOf	(Ljava/lang/String;)Ljava/lang/Boolean;
    //   40: invokevirtual 273	java/lang/Boolean:booleanValue	()Z
    //   43: ifeq +7 -> 50
    //   46: iconst_0
    //   47: goto +4 -> 51
    //   50: iconst_1
    //   51: istore_1
    //   52: aload_0
    //   53: aload_0
    //   54: getfield 268	org/eclipse/osgi/internal/baseadaptor/StateManager:factory	Lorg/eclipse/osgi/internal/resolver/StateObjectFactoryImpl;
    //   57: aload_0
    //   58: getfield 269	org/eclipse/osgi/internal/baseadaptor/StateManager:context	Lorg/osgi/framework/BundleContext;
    //   61: aload_0
    //   62: getfield 263	org/eclipse/osgi/internal/baseadaptor/StateManager:stateFile	Ljava/io/File;
    //   65: aload_0
    //   66: getfield 262	org/eclipse/osgi/internal/baseadaptor/StateManager:lazyFile	Ljava/io/File;
    //   69: iload_1
    //   70: aload_0
    //   71: getfield 252	org/eclipse/osgi/internal/baseadaptor/StateManager:expectedTimeStamp	J
    //   74: invokevirtual 317	org/eclipse/osgi/internal/resolver/StateObjectFactoryImpl:readSystemState	(Lorg/osgi/framework/BundleContext;Ljava/io/File;Ljava/io/File;ZJ)Lorg/eclipse/osgi/internal/resolver/SystemState;
    //   77: putfield 267	org/eclipse/osgi/internal/baseadaptor/StateManager:systemState	Lorg/eclipse/osgi/internal/resolver/StateImpl;
    //   80: aload_0
    //   81: getfield 267	org/eclipse/osgi/internal/baseadaptor/StateManager:systemState	Lorg/eclipse/osgi/internal/resolver/StateImpl;
    //   84: ifnull +10 -> 94
    //   87: aload_0
    //   88: invokespecial 296	org/eclipse/osgi/internal/baseadaptor/StateManager:initializeSystemState	()Z
    //   91: ifne +44 -> 135
    //   94: aload_0
    //   95: aconst_null
    //   96: putfield 267	org/eclipse/osgi/internal/baseadaptor/StateManager:systemState	Lorg/eclipse/osgi/internal/resolver/StateImpl;
    //   99: getstatic 259	org/eclipse/osgi/internal/baseadaptor/StateManager:DEBUG_READER	Z
    //   102: ifeq +32 -> 134
    //   105: getstatic 251	java/lang/System:out	Ljava/io/PrintStream;
    //   108: new 135	java/lang/StringBuffer
    //   111: dup
    //   112: ldc 2
    //   114: invokespecial 281	java/lang/StringBuffer:<init>	(Ljava/lang/String;)V
    //   117: invokestatic 283	java/lang/System:currentTimeMillis	()J
    //   120: aload_0
    //   121: getfield 255	org/eclipse/osgi/internal/baseadaptor/StateManager:readStartupTime	J
    //   124: lsub
    //   125: invokevirtual 282	java/lang/StringBuffer:append	(J)Ljava/lang/StringBuffer;
    //   128: invokevirtual 280	java/lang/StringBuffer:toString	()Ljava/lang/String;
    //   131: invokevirtual 272	java/io/PrintStream:println	(Ljava/lang/String;)V
    //   134: return
    //   135: aload_0
    //   136: iconst_1
    //   137: putfield 261	org/eclipse/osgi/internal/baseadaptor/StateManager:cachedState	Z
    //   140: aload_0
    //   141: getstatic 264	org/eclipse/osgi/internal/baseadaptor/StateManager:PROP_LAZY_UNLOADING_TIME	Ljava/lang/String;
    //   144: aload_0
    //   145: getfield 253	org/eclipse/osgi/internal/baseadaptor/StateManager:expireTime	J
    //   148: invokestatic 277	java/lang/Long:toString	(J)Ljava/lang/String;
    //   151: invokestatic 292	org/eclipse/osgi/framework/internal/core/FrameworkProperties:getProperty	(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
    //   154: invokestatic 278	java/lang/Long:parseLong	(Ljava/lang/String;)J
    //   157: putfield 253	org/eclipse/osgi/internal/baseadaptor/StateManager:expireTime	J
    //   160: goto +9 -> 169
    //   163: pop
    //   164: aload_0
    //   165: lconst_0
    //   166: putfield 253	org/eclipse/osgi/internal/baseadaptor/StateManager:expireTime	J
    //   169: iload_1
    //   170: ifeq +100 -> 270
    //   173: aload_0
    //   174: getfield 253	org/eclipse/osgi/internal/baseadaptor/StateManager:expireTime	J
    //   177: lconst_0
    //   178: lcmp
    //   179: ifle +91 -> 270
    //   182: aload_0
    //   183: invokespecial 294	org/eclipse/osgi/internal/baseadaptor/StateManager:startDataManager	()V
    //   186: goto +84 -> 270
    //   189: astore_1
    //   190: aload_1
    //   191: invokevirtual 271	java/io/IOException:printStackTrace	()V
    //   194: getstatic 259	org/eclipse/osgi/internal/baseadaptor/StateManager:DEBUG_READER	Z
    //   197: ifeq +108 -> 305
    //   200: getstatic 251	java/lang/System:out	Ljava/io/PrintStream;
    //   203: new 135	java/lang/StringBuffer
    //   206: dup
    //   207: ldc 2
    //   209: invokespecial 281	java/lang/StringBuffer:<init>	(Ljava/lang/String;)V
    //   212: invokestatic 283	java/lang/System:currentTimeMillis	()J
    //   215: aload_0
    //   216: getfield 255	org/eclipse/osgi/internal/baseadaptor/StateManager:readStartupTime	J
    //   219: lsub
    //   220: invokevirtual 282	java/lang/StringBuffer:append	(J)Ljava/lang/StringBuffer;
    //   223: invokevirtual 280	java/lang/StringBuffer:toString	()Ljava/lang/String;
    //   226: invokevirtual 272	java/io/PrintStream:println	(Ljava/lang/String;)V
    //   229: goto +76 -> 305
    //   232: astore_2
    //   233: getstatic 259	org/eclipse/osgi/internal/baseadaptor/StateManager:DEBUG_READER	Z
    //   236: ifeq +32 -> 268
    //   239: getstatic 251	java/lang/System:out	Ljava/io/PrintStream;
    //   242: new 135	java/lang/StringBuffer
    //   245: dup
    //   246: ldc 2
    //   248: invokespecial 281	java/lang/StringBuffer:<init>	(Ljava/lang/String;)V
    //   251: invokestatic 283	java/lang/System:currentTimeMillis	()J
    //   254: aload_0
    //   255: getfield 255	org/eclipse/osgi/internal/baseadaptor/StateManager:readStartupTime	J
    //   258: lsub
    //   259: invokevirtual 282	java/lang/StringBuffer:append	(J)Ljava/lang/StringBuffer;
    //   262: invokevirtual 280	java/lang/StringBuffer:toString	()Ljava/lang/String;
    //   265: invokevirtual 272	java/io/PrintStream:println	(Ljava/lang/String;)V
    //   268: aload_2
    //   269: athrow
    //   270: getstatic 259	org/eclipse/osgi/internal/baseadaptor/StateManager:DEBUG_READER	Z
    //   273: ifeq +32 -> 305
    //   276: getstatic 251	java/lang/System:out	Ljava/io/PrintStream;
    //   279: new 135	java/lang/StringBuffer
    //   282: dup
    //   283: ldc 2
    //   285: invokespecial 281	java/lang/StringBuffer:<init>	(Ljava/lang/String;)V
    //   288: invokestatic 283	java/lang/System:currentTimeMillis	()J
    //   291: aload_0
    //   292: getfield 255	org/eclipse/osgi/internal/baseadaptor/StateManager:readStartupTime	J
    //   295: lsub
    //   296: invokevirtual 282	java/lang/StringBuffer:append	(J)Ljava/lang/StringBuffer;
    //   299: invokevirtual 280	java/lang/StringBuffer:toString	()Ljava/lang/String;
    //   302: invokevirtual 272	java/io/PrintStream:println	(Ljava/lang/String;)V
    //   305: return
    // Line number table:
    //   Java source line #123	-> byte code offset #0
    //   Java source line #124	-> byte code offset #17
    //   Java source line #125	-> byte code offset #18
    //   Java source line #126	-> byte code offset #24
    //   Java source line #128	-> byte code offset #31
    //   Java source line #129	-> byte code offset #52
    //   Java source line #131	-> byte code offset #80
    //   Java source line #132	-> byte code offset #94
    //   Java source line #148	-> byte code offset #99
    //   Java source line #149	-> byte code offset #105
    //   Java source line #133	-> byte code offset #134
    //   Java source line #135	-> byte code offset #135
    //   Java source line #137	-> byte code offset #140
    //   Java source line #138	-> byte code offset #160
    //   Java source line #140	-> byte code offset #164
    //   Java source line #142	-> byte code offset #169
    //   Java source line #143	-> byte code offset #182
    //   Java source line #144	-> byte code offset #186
    //   Java source line #146	-> byte code offset #190
    //   Java source line #148	-> byte code offset #194
    //   Java source line #149	-> byte code offset #200
    //   Java source line #147	-> byte code offset #232
    //   Java source line #148	-> byte code offset #233
    //   Java source line #149	-> byte code offset #239
    //   Java source line #150	-> byte code offset #268
    //   Java source line #148	-> byte code offset #270
    //   Java source line #149	-> byte code offset #276
    //   Java source line #151	-> byte code offset #305
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	306	0	this	StateManager
    //   51	19	1	lazyLoad	boolean
    //   135	35	1	lazyLoad	boolean
    //   189	2	1	ioe	IOException
    //   232	37	2	localObject	Object
    //   163	1	5	localNumberFormatException	NumberFormatException
    // Exception table:
    //   from	to	target	type
    //   140	160	163	java/lang/NumberFormatException
    //   31	99	189	java/io/IOException
    //   135	186	189	java/io/IOException
    //   31	99	232	finally
    //   135	194	232	finally
  }
  
  private synchronized void startDataManager()
  {
    if (dataManagerThread != null) {
      return;
    }
    dataManagerThread = new Thread(this, "State Data Manager");
    dataManagerThread.setDaemon(true);
    dataManagerThread.start();
  }
  
  public synchronized void stopDataManager()
  {
    if (dataManagerThread == null) {
      return;
    }
    dataManagerThread.interrupt();
    dataManagerThread = null;
  }
  
  private void writeState(StateImpl state, File saveStateFile, File saveLazyFile)
    throws IOException
  {
    if (state == null) {
      return;
    }
    if ((cachedState) && (!saveNeeded())) {
      return;
    }
    state.fullyLoad();
    factory.writeState(state, saveStateFile, saveLazyFile);
  }
  
  private boolean initializeSystemState()
  {
    systemState.setResolver(createResolver(System.getSecurityManager() != null));
    lastTimeStamp = systemState.getTimeStamp();
    return !systemState.setPlatformProperties(FrameworkProperties.getProperties());
  }
  
  public synchronized State createSystemState()
  {
    if (systemState == null)
    {
      systemState = factory.createSystemState(context);
      initializeSystemState();
    }
    return systemState;
  }
  
  public synchronized State readSystemState()
  {
    if (systemState == null) {
      internalReadSystemState();
    }
    return systemState;
  }
  
  public State getSystemState()
  {
    return systemState;
  }
  
  public long getCachedTimeStamp()
  {
    return lastTimeStamp;
  }
  
  public boolean saveNeeded()
  {
    return (systemState.getTimeStamp() != lastTimeStamp) || (systemState.dynamicCacheChanged());
  }
  
  public State getState(boolean mutable)
  {
    return mutable ? factory.createState(systemState) : new ReadOnlyState(systemState);
  }
  
  public State getState()
  {
    return getState(true);
  }
  
  public StateObjectFactory getFactory()
  {
    return factory;
  }
  
  public synchronized void commit(State state)
    throws BundleException
  {
    throw new IllegalArgumentException("PlatformAdmin.commit() not supported");
  }
  
  /**
   * @deprecated
   */
  public Resolver getResolver()
  {
    return createResolver(false);
  }
  
  public Resolver createResolver()
  {
    return createResolver(false);
  }
  
  private Resolver createResolver(boolean checkPermissions)
  {
    return new ResolverImpl(checkPermissions);
  }
  
  public StateHelper getStateHelper()
  {
    return StateHelperImpl.getInstance();
  }
  
  public void run()
  {
    long timeStamp = lastTimeStamp;
    for (;;)
    {
      try
      {
        Thread.sleep(expireTime);
      }
      catch (InterruptedException localInterruptedException)
      {
        return;
      }
      if (systemState == null) {
        continue;
      }
      synchronized (systemState)
      {
        if (!systemState.unloadLazyData(timeStamp)) {
          return;
        }
      }
    }
  }
  
  public void addDisabledInfo(DisabledInfo disabledInfo)
  {
    if (systemState == null) {
      throw new IllegalStateException();
    }
    systemState.addDisabledInfo(disabledInfo);
  }
  
  public void removeDisabledInfo(DisabledInfo disabledInfo)
  {
    if (systemState == null) {
      throw new IllegalStateException();
    }
    systemState.removeDisabledInfo(disabledInfo);
  }
}

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

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;

class SystemBundleData$1$1
  extends BundleEntry
{
  final SystemBundleData.1 this$1;
  
  SystemBundleData$1$1(SystemBundleData.1 param1) {}
  
  public InputStream getInputStream()
    throws IOException
  {
    return SystemBundleData.access$0(SystemBundleData.1.access$0(this$1)).openStream();
  }
  
  public long getSize()
  {
    return 0L;
  }
  
  public String getName()
  {
    return "META-INF/MANIFEST.MF";
  }
  
  public long getTime()
  {
    return 0L;
  }
  
  public URL getLocalURL()
  {
    return SystemBundleData.access$0(SystemBundleData.1.access$0(this$1));
  }
  
  public URL getFileURL()
  {
    return null;
  }
}

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

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.net.URL;
import java.util.Enumeration;
import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;
import org.eclipse.osgi.baseadaptor.bundlefile.BundleFile;

class SystemBundleData$1
  extends BundleFile
{
  final SystemBundleData this$0;
  
  SystemBundleData$1(SystemBundleData paramSystemBundleData, File $anonymous0)
  {
    super($anonymous0);
  }
  
  public File getFile(String path, boolean nativeCode)
  {
    return null;
  }
  
  public BundleEntry getEntry(String path)
  {
    if ("META-INF/MANIFEST.MF".equals(path))
    {
      System.err.println("Getting system bundle manifest: " + path);
      new BundleEntry()
      {
        public InputStream getInputStream()
          throws IOException
        {
          return SystemBundleData.access$0(this$0).openStream();
        }
        
        public long getSize()
        {
          return 0L;
        }
        
        public String getName()
        {
          return "META-INF/MANIFEST.MF";
        }
        
        public long getTime()
        {
          return 0L;
        }
        
        public URL getLocalURL()
        {
          return SystemBundleData.access$0(this$0);
        }
        
        public URL getFileURL()
        {
          return null;
        }
      };
    }
    return null;
  }
  
  public Enumeration<String> getEntryPaths(String path)
  {
    return null;
  }
  
  public void close() {}
  
  public void open() {}
  
  public boolean containsDir(String dir)
  {
    return false;
  }
}

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

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.net.URL;
import java.security.CodeSource;
import java.security.ProtectionDomain;
import java.util.Enumeration;
import org.eclipse.osgi.baseadaptor.BaseAdaptor;
import org.eclipse.osgi.baseadaptor.BaseData;
import org.eclipse.osgi.baseadaptor.HookRegistry;
import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;
import org.eclipse.osgi.baseadaptor.bundlefile.BundleFile;
import org.eclipse.osgi.baseadaptor.hooks.StorageHook;
import org.eclipse.osgi.framework.adaptor.BundleClassLoader;
import org.eclipse.osgi.framework.adaptor.BundleProtectionDomain;
import org.eclipse.osgi.framework.adaptor.ClassLoaderDelegate;
import org.eclipse.osgi.framework.debug.Debug;
import org.eclipse.osgi.framework.internal.core.FrameworkProperties;
import org.eclipse.osgi.framework.util.Headers;
import org.osgi.framework.BundleException;

public class SystemBundleData
  extends BaseData
{
  private static final String OSGI_FRAMEWORK = "osgi.framework";
  
  public SystemBundleData(BaseAdaptor adaptor)
    throws BundleException
  {
    super(0L, adaptor);
    File osgiBase = getOsgiBase();
    createBundleFile(osgiBase);
    manifest = createManifest(osgiBase);
    setMetaData();
    setLastModified(System.currentTimeMillis());
    StorageHook[] hooks = adaptor.getHookRegistry().getStorageHooks();
    StorageHook[] instanceHooks = new StorageHook[hooks.length];
    for (int i = 0; i < hooks.length; i++) {
      instanceHooks[i] = hooks[i].create(this);
    }
    setStorageHooks(instanceHooks);
  }
  
  private File getOsgiBase()
  {
    String frameworkLocation = FrameworkProperties.getProperty("osgi.framework");
    if ((frameworkLocation != null) && (frameworkLocation.startsWith("file:"))) {
      return new File(frameworkLocation.substring(5));
    }
    try
    {
      URL url = getClass().getProtectionDomain().getCodeSource().getLocation();
      if ("file".equals(url.getProtocol())) {
        return new File(url.getPath());
      }
    }
    catch (Throwable localThrowable) {}
    return null;
  }
  
  private Headers<String, String> createManifest(File osgiBase)
    throws BundleException
  {
    InputStream in = null;
    if ((osgiBase != null) && (osgiBase.exists())) {
      try
      {
        BundleEntry entry = getBundleFile().getEntry("META-INF/MANIFEST.MF");
        if (entry != null) {
          in = entry.getInputStream();
        }
      }
      catch (IOException localIOException) {}
    }
    if (in == null) {
      in = getManifestAsResource();
    }
    if ((Debug.DEBUG_GENERAL) && 
      (in == null)) {
      Debug.println("Unable to find system bundle manifest META-INF/MANIFEST.MF");
    }
    if (in == null) {
      throw new BundleException(AdaptorMsg.SYSTEMBUNDLE_MISSING_MANIFEST, 3);
    }
    return Headers.parseManifest(in);
  }
  
  private InputStream getManifestAsResource()
  {
    URL url = getManifestURL();
    try
    {
      return url == null ? null : url.openStream();
    }
    catch (IOException localIOException) {}
    return null;
  }
  
  private URL getManifestURL()
  {
    ClassLoader cl = getClass().getClassLoader();
    try
    {
      Enumeration<URL> manifests = cl != null ? cl.getResources("META-INF/MANIFEST.MF") : ClassLoader.getSystemResources("META-INF/MANIFEST.MF");
      while (manifests.hasMoreElements())
      {
        URL url = (URL)manifests.nextElement();
        try
        {
          Headers<String, String> headers = Headers.parseManifest(url.openStream());
          if ("true".equals(headers.get("Eclipse-SystemBundle"))) {
            return url;
          }
        }
        catch (BundleException localBundleException) {}
      }
    }
    catch (IOException localIOException) {}
    return null;
  }
  
  private void createBundleFile(File osgiBase)
  {
    if (osgiBase != null) {
      try
      {
        bundleFile = getAdaptor().createBundleFile(osgiBase, this);
      }
      catch (IOException localIOException) {}
    } else {
      bundleFile = new BundleFile(osgiBase)
      {
        public File getFile(String path, boolean nativeCode)
        {
          return null;
        }
        
        public BundleEntry getEntry(String path)
        {
          if ("META-INF/MANIFEST.MF".equals(path))
          {
            System.err.println("Getting system bundle manifest: " + path);
            new BundleEntry()
            {
              public InputStream getInputStream()
                throws IOException
              {
                return SystemBundleData.this.getManifestURL().openStream();
              }
              
              public long getSize()
              {
                return 0L;
              }
              
              public String getName()
              {
                return "META-INF/MANIFEST.MF";
              }
              
              public long getTime()
              {
                return 0L;
              }
              
              public URL getLocalURL()
              {
                return SystemBundleData.this.getManifestURL();
              }
              
              public URL getFileURL()
              {
                return null;
              }
            };
          }
          return null;
        }
        
        public Enumeration<String> getEntryPaths(String path)
        {
          return null;
        }
        
        public void close() {}
        
        public void open() {}
        
        public boolean containsDir(String dir)
        {
          return false;
        }
      };
    }
  }
  
  private void setMetaData()
    throws BundleException
  {
    setLocation("System Bundle");
    BaseStorageHook.loadManifest(this, manifest);
  }
  
  public BundleClassLoader createClassLoader(ClassLoaderDelegate delegate, BundleProtectionDomain domain, String[] bundleclasspath)
  {
    return null;
  }
  
  public File createGenerationDir()
  {
    return null;
  }
  
  public String findLibrary(String libname)
  {
    return null;
  }
  
  public void installNativeCode(String[] nativepaths)
    throws BundleException
  {}
  
  public int getStartLevel()
  {
    return 0;
  }
  
  public int getStatus()
  {
    return 1;
  }
  
  public void save() {}
}

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

import java.util.AbstractList;
import java.util.ArrayList;
import java.util.List;
import java.util.RandomAccess;
import org.eclipse.osgi.internal.resolver.StateBuilder;
import org.eclipse.osgi.service.resolver.ImportPackageSpecification;
import org.eclipse.osgi.util.ManifestElement;

public class DynamicImportList
  extends AbstractList<String>
  implements RandomAccess
{
  private final List<String> imports = new ArrayList(0);
  private final WovenClassImpl wovenClass;
  
  public DynamicImportList(WovenClassImpl wovenClass)
  {
    this.wovenClass = wovenClass;
  }
  
  public String get(int index)
  {
    return (String)imports.get(index);
  }
  
  public int size()
  {
    return imports.size();
  }
  
  public String set(int index, String element)
  {
    wovenClass.checkPermission();
    validateSyntax(element);
    return (String)imports.set(index, element);
  }
  
  public void add(int index, String element)
  {
    wovenClass.checkPermission();
    validateSyntax(element);
    imports.add(index, element);
  }
  
  public String remove(int index)
  {
    wovenClass.checkPermission();
    return (String)imports.remove(index);
  }
  
  private void validateSyntax(String imported)
  {
    try
    {
      ManifestElement[] importElements = ManifestElement.parseHeader("Import-Package", imported);
      
      StateBuilder.checkImportExportSyntax("Import-Package", importElements, false, false, false);
      
      List<ImportPackageSpecification> dynamicImportSpecs = new ArrayList(importElements.length);
      ManifestElement[] arrayOfManifestElement1;
      int j = (arrayOfManifestElement1 = importElements).length;
      for (int i = 0; i < j; i++)
      {
        ManifestElement dynamicImportElement = arrayOfManifestElement1[i];
        StateBuilder.addImportPackages(dynamicImportElement, dynamicImportSpecs, 2, true);
      }
    }
    catch (Throwable t)
    {
      IllegalArgumentException exception = new IllegalArgumentException();
      exception.initCause(t);
      throw exception;
    }
    ManifestElement[] importElements;
  }
}

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

import java.net.URL;
import java.security.ProtectionDomain;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import org.eclipse.osgi.baseadaptor.BaseAdaptor;
import org.eclipse.osgi.baseadaptor.BaseData;
import org.eclipse.osgi.baseadaptor.HookConfigurator;
import org.eclipse.osgi.baseadaptor.HookRegistry;
import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;
import org.eclipse.osgi.baseadaptor.hooks.ClassLoadingHook;
import org.eclipse.osgi.baseadaptor.hooks.ClassLoadingStatsHook;
import org.eclipse.osgi.baseadaptor.loader.BaseClassLoader;
import org.eclipse.osgi.baseadaptor.loader.ClasspathEntry;
import org.eclipse.osgi.baseadaptor.loader.ClasspathManager;
import org.eclipse.osgi.framework.adaptor.BundleProtectionDomain;
import org.eclipse.osgi.framework.adaptor.ClassLoaderDelegate;
import org.eclipse.osgi.framework.adaptor.EventPublisher;
import org.eclipse.osgi.framework.internal.core.Framework;
import org.eclipse.osgi.internal.loader.BundleLoader;
import org.eclipse.osgi.internal.serviceregistry.ServiceRegistry;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;

public class WeavingHookConfigurator
  implements HookConfigurator, ClassLoadingHook, ClassLoadingStatsHook
{
  private BaseAdaptor adaptor;
  private final Map<ServiceRegistration<?>, Boolean> blackList = Collections.synchronizedMap(new WeakHashMap());
  private final ThreadLocal<List<WovenClassImpl>> wovenClassStack = new ThreadLocal();
  
  public void addHooks(HookRegistry hookRegistry)
  {
    adaptor = hookRegistry.getAdaptor();
    hookRegistry.addClassLoadingHook(this);
    hookRegistry.addClassLoadingStatsHook(this);
  }
  
  private ServiceRegistry getRegistry()
  {
    return ((Framework)adaptor.getEventPublisher()).getServiceRegistry();
  }
  
  public byte[] processClass(String name, byte[] classbytes, ClasspathEntry classpathEntry, BundleEntry entry, ClasspathManager manager)
  {
    ServiceRegistry registry = getRegistry();
    if (registry == null) {
      return null;
    }
    ClassLoaderDelegate delegate = manager.getBaseClassLoader().getDelegate();
    BundleLoader loader;
    if ((delegate instanceof BundleLoader))
    {
      loader = (BundleLoader)delegate;
    }
    else
    {
      Throwable e = new IllegalStateException("Could not obtain loader");
      adaptor.getEventPublisher().publishFrameworkEvent(2, manager.getBaseData().getBundle(), e);
      return null;
    }
    BundleLoader loader;
    WovenClassImpl wovenClass = new WovenClassImpl(name, classbytes, entry, classpathEntry.getDomain(), loader, registry, blackList);
    List<WovenClassImpl> wovenClasses = (List)wovenClassStack.get();
    if (wovenClasses == null)
    {
      wovenClasses = new ArrayList(6);
      wovenClassStack.set(wovenClasses);
    }
    wovenClasses.add(wovenClass);
    try
    {
      return wovenClass.callHooks();
    }
    catch (Throwable t)
    {
      ServiceRegistration<?> errorHook = wovenClass.getErrorHook();
      Bundle errorBundle = errorHook != null ? errorHook.getReference().getBundle() : manager.getBaseData().getBundle();
      adaptor.getEventPublisher().publishFrameworkEvent(2, errorBundle, t);
      
      ClassFormatError error = new ClassFormatError("Unexpected error from weaving hook.");
      error.initCause(t);
      throw error;
    }
  }
  
  public boolean addClassPathEntry(ArrayList<ClasspathEntry> cpEntries, String cp, ClasspathManager hostmanager, BaseData sourcedata, ProtectionDomain sourcedomain)
  {
    return false;
  }
  
  public String findLibrary(BaseData data, String libName)
  {
    return null;
  }
  
  public ClassLoader getBundleClassLoaderParent()
  {
    return null;
  }
  
  public BaseClassLoader createClassLoader(ClassLoader parent, ClassLoaderDelegate delegate, BundleProtectionDomain domain, BaseData data, String[] bundleclasspath)
  {
    return null;
  }
  
  public void initializedClassLoader(BaseClassLoader baseClassLoader, BaseData data) {}
  
  public void preFindLocalClass(String name, ClasspathManager manager) {}
  
  public void postFindLocalClass(String name, Class<?> clazz, ClasspathManager manager) {}
  
  public void preFindLocalResource(String name, ClasspathManager manager) {}
  
  public void postFindLocalResource(String name, URL resource, ClasspathManager manager) {}
  
  public void recordClassDefine(String name, Class<?> clazz, byte[] classbytes, ClasspathEntry classpathEntry, BundleEntry entry, ClasspathManager manager)
  {
    List<WovenClassImpl> wovenClasses = (List)wovenClassStack.get();
    if ((wovenClasses == null) || (wovenClasses.size() == 0)) {
      return;
    }
    WovenClassImpl wovenClass = (WovenClassImpl)wovenClasses.remove(wovenClasses.size() - 1);
    
    wovenClass.setWeavingCompleted(clazz);
  }
}

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

import java.security.PrivilegedExceptionAction;
import org.eclipse.osgi.internal.serviceregistry.ServiceRegistry;

class WovenClassImpl$1
  implements PrivilegedExceptionAction<Object>
{
  final WovenClassImpl this$0;
  
  WovenClassImpl$1(WovenClassImpl paramWovenClassImpl) {}
  
  public Object run()
  {
    this$0.registry.notifyHooksPrivileged(this$0);
    return null;
  }
}

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

import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.security.ProtectionDomain;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;
import org.eclipse.osgi.internal.baseadaptor.AdaptorUtil;
import org.eclipse.osgi.internal.loader.BundleLoader;
import org.eclipse.osgi.internal.loader.BundleLoaderProxy;
import org.eclipse.osgi.internal.serviceregistry.HookContext;
import org.eclipse.osgi.internal.serviceregistry.ServiceRegistry;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.util.ManifestElement;
import org.osgi.framework.AdminPermission;
import org.osgi.framework.BundleException;
import org.osgi.framework.ServiceRegistration;
import org.osgi.framework.hooks.weaving.WeavingException;
import org.osgi.framework.hooks.weaving.WeavingHook;
import org.osgi.framework.hooks.weaving.WovenClass;
import org.osgi.framework.wiring.BundleWiring;

public final class WovenClassImpl
  implements WovenClass, HookContext
{
  private static final byte FLAG_HOOKCALLED = 1;
  private static final byte FLAG_HOOKSCOMPLETE = 2;
  private static final byte FLAG_WEAVINGCOMPLETE = 4;
  private static final String weavingHookName = WeavingHook.class.getName();
  private final String className;
  private final BundleEntry entry;
  private final List<String> dynamicImports;
  private final ProtectionDomain domain;
  private final BundleLoader loader;
  final ServiceRegistry registry;
  private final Map<ServiceRegistration<?>, Boolean> blackList;
  private byte[] validBytes;
  private byte[] resultBytes;
  private byte hookFlags = 0;
  private Throwable error;
  private ServiceRegistration<?> errorHook;
  private Class<?> clazz;
  
  public WovenClassImpl(String className, byte[] bytes, BundleEntry entry, ProtectionDomain domain, BundleLoader loader, ServiceRegistry registry, Map<ServiceRegistration<?>, Boolean> blacklist)
  {
    this.className = className;
    validBytes = (resultBytes = bytes);
    this.entry = entry;
    dynamicImports = new DynamicImportList(this);
    this.domain = domain;
    this.loader = loader;
    this.registry = registry;
    blackList = blacklist;
  }
  
  public byte[] getBytes()
  {
    if ((hookFlags & 0x2) == 0)
    {
      checkPermission();
      return validBytes;
    }
    byte[] current = validBytes;
    byte[] results = new byte[current.length];
    System.arraycopy(current, 0, results, 0, current.length);
    return results;
  }
  
  public void setBytes(byte[] newBytes)
  {
    checkPermission();
    if (newBytes == null) {
      throw new NullPointerException("newBytes cannot be null.");
    }
    if ((hookFlags & 0x2) != 0) {
      throw new IllegalStateException("Weaving has completed already.");
    }
    resultBytes = (validBytes = newBytes);
  }
  
  void checkPermission()
  {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
      sm.checkPermission(new AdminPermission(loader.getBundle(), "weave"));
    }
  }
  
  public List<String> getDynamicImports()
  {
    if ((hookFlags & 0x2) == 0) {
      return dynamicImports;
    }
    return Collections.unmodifiableList(dynamicImports);
  }
  
  public boolean isWeavingComplete()
  {
    return (hookFlags & 0x4) != 0;
  }
  
  private void setHooksComplete()
  {
    byte[] original = validBytes;
    validBytes = new byte[original.length];
    System.arraycopy(original, 0, validBytes, 0, original.length);
    hookFlags = ((byte)(hookFlags | 0x2));
  }
  
  void setWeavingCompleted(Class<?> clazz)
  {
    this.clazz = clazz;
    hookFlags = ((byte)(hookFlags | 0x4));
  }
  
  public String getClassName()
  {
    return className;
  }
  
  public ProtectionDomain getProtectionDomain()
  {
    return domain;
  }
  
  public Class<?> getDefinedClass()
  {
    return clazz;
  }
  
  public BundleWiring getBundleWiring()
  {
    return loader.getLoaderProxy().getBundleDescription().getWiring();
  }
  
  public void call(Object hook, ServiceRegistration<?> hookRegistration)
    throws Exception
  {
    if (error != null) {
      return;
    }
    if ((hook instanceof WeavingHook))
    {
      if (blackList.containsKey(hookRegistration)) {
        return;
      }
      if ((hookFlags & 0x1) == 0)
      {
        hookFlags = ((byte)(hookFlags | 0x1));
        if (!validBytes(validBytes)) {
          validBytes = AdaptorUtil.getBytes(entry.getInputStream(), (int)entry.getSize(), 8192);
        }
      }
      try
      {
        ((WeavingHook)hook).weave(this);
      }
      catch (WeavingException e)
      {
        error = e;
        errorHook = hookRegistration;
      }
      catch (Throwable t)
      {
        error = t;
        errorHook = hookRegistration;
        
        blackList.put(hookRegistration, Boolean.TRUE);
      }
    }
  }
  
  private boolean validBytes(byte[] checkBytes)
  {
    if ((checkBytes == null) || (checkBytes.length < 4)) {
      return false;
    }
    if ((checkBytes[0] & 0xCA) != 202) {
      return false;
    }
    if ((checkBytes[1] & 0xFE) != 254) {
      return false;
    }
    if ((checkBytes[2] & 0xBA) != 186) {
      return false;
    }
    if ((checkBytes[3] & 0xBE) != 190) {
      return false;
    }
    return true;
  }
  
  public String getHookMethodName()
  {
    return "weave";
  }
  
  public String getHookClassName()
  {
    return weavingHookName;
  }
  
  byte[] callHooks()
    throws Throwable
  {
    SecurityManager sm = System.getSecurityManager();
    byte[] wovenBytes = null;
    List<String> newImports = null;
    try
    {
      if (sm == null) {
        registry.notifyHooksPrivileged(this);
      } else {
        try
        {
          AccessController.doPrivileged(new PrivilegedExceptionAction()
          {
            public Object run()
            {
              registry.notifyHooksPrivileged(WovenClassImpl.this);
              return null;
            }
          });
        }
        catch (PrivilegedActionException e)
        {
          throw ((RuntimeException)e.getException());
        }
      }
    }
    finally
    {
      if ((hookFlags & 0x1) != 0)
      {
        wovenBytes = resultBytes;
        newImports = dynamicImports;
        setHooksComplete();
      }
    }
    if ((hookFlags & 0x1) != 0)
    {
      wovenBytes = resultBytes;
      newImports = dynamicImports;
      setHooksComplete();
    }
    if (error != null) {
      throw error;
    }
    if (newImports != null) {
      for (Iterator localIterator = newImports.iterator(); localIterator.hasNext();)
      {
        String newImport = (String)localIterator.next();
        try
        {
          ManifestElement[] importElements = ManifestElement.parseHeader("Import-Package", newImport);
          loader.addDynamicImportPackage(importElements);
        }
        catch (BundleException localBundleException) {}
      }
    }
    return wovenBytes;
  }
  
  public String toString()
  {
    return className;
  }
  
  public ServiceRegistration<?> getErrorHook()
  {
    return errorHook;
  }
}

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

import java.io.IOException;
import java.io.InputStream;
import org.eclipse.osgi.framework.adaptor.BundleData;
import org.eclipse.osgi.framework.adaptor.ClassLoaderDelegate;
import org.eclipse.osgi.framework.internal.core.BundleHost;
import org.ecli
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