org.eclipse.osgi_3.8.2.v20130124-134944

       if (Debug.DEBUG_GENERAL) {
            Debug.println("Creating file: " + nested.getPath());
          }
          File dir = new File(nested.getParent());
          if ((!dir.exists()) && (!dir.mkdirs()))
          {
            if (Debug.DEBUG_GENERAL) {
              Debug.println("Unable to create directory: " + dir.getPath());
            }
            throw new IOException(NLS.bind(AdaptorMsg.ADAPTOR_DIRECTORY_CREATE_EXCEPTION, dir.getAbsolutePath()));
          }
          AdaptorUtil.readFile(in, nested);
          if (nativeCode) {
            setPermissions(nested);
          }
        }
        return nested;
      }
    }
    catch (IOException e)
    {
      if (Debug.DEBUG_GENERAL) {
        Debug.printStackTrace(e);
      }
    }
    return null;
  }
  
  public synchronized boolean containsDir(String dir)
  {
    if (!checkedOpen()) {
      return false;
    }
    if (dir == null) {
      return false;
    }
    if (dir.length() == 0) {
      return true;
    }
    if (dir.charAt(0) == '/')
    {
      if (dir.length() == 1) {
        return true;
      }
      dir = dir.substring(1);
    }
    if ((dir.length() > 0) && (dir.charAt(dir.length() - 1) != '/')) {
      dir = dir + '/';
    }
    Enumeration<? extends ZipEntry> entries = zipFile.entries();
    while (entries.hasMoreElements())
    {
      ZipEntry zipEntry = (ZipEntry)entries.nextElement();
      String entryPath = zipEntry.getName();
      if (entryPath.startsWith(dir)) {
        return true;
      }
    }
    return false;
  }
  
  public synchronized BundleEntry getEntry(String path)
  {
    if (!checkedOpen()) {
      return null;
    }
    ZipEntry zipEntry = getZipEntry(path);
    if (zipEntry == null)
    {
      if ((path.length() == 0) || (path.charAt(path.length() - 1) == '/')) {
        if (containsDir(path)) {
          return new DirZipBundleEntry(this, path);
        }
      }
      return null;
    }
    return new ZipBundleEntry(zipEntry, this);
  }
  
  public synchronized Enumeration<String> getEntryPaths(String path)
  {
    if (!checkedOpen()) {
      return null;
    }
    if (path == null) {
      throw new NullPointerException();
    }
    if ((path.length() > 0) && (path.charAt(0) == '/')) {
      path = path.substring(1);
    }
    if ((path.length() > 0) && (path.charAt(path.length() - 1) != '/')) {
      path = path + "/";
    }
    List<String> vEntries = new ArrayList();
    Enumeration<? extends ZipEntry> entries = zipFile.entries();
    while (entries.hasMoreElements())
    {
      ZipEntry zipEntry = (ZipEntry)entries.nextElement();
      String entryPath = zipEntry.getName();
      if ((entryPath.startsWith(path)) && 
        (path.length() < entryPath.length())) {
        if (entryPath.lastIndexOf('/') < path.length())
        {
          vEntries.add(entryPath);
        }
        else
        {
          entryPath = entryPath.substring(path.length());
          int slash = entryPath.indexOf('/');
          entryPath = path + entryPath.substring(0, slash + 1);
          if (!vEntries.contains(entryPath)) {
            vEntries.add(entryPath);
          }
        }
      }
    }
    return vEntries.size() == 0 ? null : Collections.enumeration(vEntries);
  }
  
  public synchronized void close()
    throws IOException
  {
    if (!closed)
    {
      if ((referenceCount > 0) && (isMruListClosing()))
      {
        try
        {
          wait(1000L);
        }
        catch (InterruptedException localInterruptedException) {}
        if ((referenceCount != 0) || (closed)) {
          return;
        }
      }
      closed = true;
      zipFile.close();
      mruListRemove();
    }
  }
  
  private boolean isMruListClosing()
  {
    return (mruList != null) && (mruList.isClosing(this));
  }
  
  boolean isMruEnabled()
  {
    return (mruList != null) && (mruList.isEnabled());
  }
  
  private void mruListRemove()
  {
    if (mruList != null) {
      mruList.remove(this);
    }
  }
  
  private void mruListUse()
  {
    if (mruList != null) {
      mruList.use(this);
    }
  }
  
  private void mruListAdd()
  {
    if (mruList != null) {
      mruList.add(this);
    }
  }
  
  public void open() {}
  
  synchronized void incrementReference()
  {
    referenceCount += 1;
  }
  
  synchronized void decrementReference()
  {
    referenceCount = Math.max(0, referenceCount - 1);
    if (referenceCount == 0) {
      notify();
    }
  }
}

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

import java.io.IOException;
import java.net.URLConnection;
import java.util.Properties;
import org.eclipse.osgi.baseadaptor.BaseAdaptor;
import org.eclipse.osgi.framework.log.FrameworkLog;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;

public abstract interface AdaptorHook
{
  public abstract void initialize(BaseAdaptor paramBaseAdaptor);
  
  public abstract void frameworkStart(BundleContext paramBundleContext)
    throws BundleException;
  
  public abstract void frameworkStop(BundleContext paramBundleContext)
    throws BundleException;
  
  public abstract void frameworkStopping(BundleContext paramBundleContext);
  
  public abstract void addProperties(Properties paramProperties);
  
  public abstract URLConnection mapLocationToURLConnection(String paramString)
    throws IOException;
  
  public abstract void handleRuntimeError(Throwable paramThrowable);
  
  public abstract FrameworkLog createFrameworkLog();
}

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

import java.io.IOException;
import org.eclipse.osgi.baseadaptor.BaseData;
import org.eclipse.osgi.baseadaptor.bundlefile.BundleFile;

public abstract interface BundleFileFactoryHook
{
  public abstract BundleFile createBundleFile(Object paramObject, BaseData paramBaseData, boolean paramBoolean)
    throws IOException;
}

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

import java.io.IOException;
import org.eclipse.osgi.baseadaptor.BaseData;
import org.eclipse.osgi.baseadaptor.bundlefile.BundleFile;

public abstract interface BundleFileWrapperFactoryHook
{
  public abstract BundleFile wrapBundleFile(BundleFile paramBundleFile, Object paramObject, BaseData paramBaseData, boolean paramBoolean)
    throws IOException;
}

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

import java.security.ProtectionDomain;
import java.util.ArrayList;
import org.eclipse.osgi.baseadaptor.BaseData;
import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;
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;

public abstract interface ClassLoadingHook
{
  public abstract byte[] processClass(String paramString, byte[] paramArrayOfByte, ClasspathEntry paramClasspathEntry, BundleEntry paramBundleEntry, ClasspathManager paramClasspathManager);
  
  public abstract boolean addClassPathEntry(ArrayList<ClasspathEntry> paramArrayList, String paramString, ClasspathManager paramClasspathManager, BaseData paramBaseData, ProtectionDomain paramProtectionDomain);
  
  public abstract String findLibrary(BaseData paramBaseData, String paramString);
  
  public abstract ClassLoader getBundleClassLoaderParent();
  
  public abstract BaseClassLoader createClassLoader(ClassLoader paramClassLoader, ClassLoaderDelegate paramClassLoaderDelegate, BundleProtectionDomain paramBundleProtectionDomain, BaseData paramBaseData, String[] paramArrayOfString);
  
  public abstract void initializedClassLoader(BaseClassLoader paramBaseClassLoader, BaseData paramBaseData);
}

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

import java.net.URL;
import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;
import org.eclipse.osgi.baseadaptor.loader.ClasspathEntry;
import org.eclipse.osgi.baseadaptor.loader.ClasspathManager;

public abstract interface ClassLoadingStatsHook
{
  public abstract void preFindLocalClass(String paramString, ClasspathManager paramClasspathManager)
    throws ClassNotFoundException;
  
  public abstract void postFindLocalClass(String paramString, Class<?> paramClass, ClasspathManager paramClasspathManager)
    throws ClassNotFoundException;
  
  public abstract void preFindLocalResource(String paramString, ClasspathManager paramClasspathManager);
  
  public abstract void postFindLocalResource(String paramString, URL paramURL, ClasspathManager paramClasspathManager);
  
  public abstract void recordClassDefine(String paramString, Class<?> paramClass, byte[] paramArrayOfByte, ClasspathEntry paramClasspathEntry, BundleEntry paramBundleEntry, ClasspathManager paramClasspathManager);
}

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

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Dictionary;
import org.eclipse.osgi.baseadaptor.BaseData;
import org.eclipse.osgi.framework.util.KeyedElement;
import org.osgi.framework.BundleException;

public abstract interface StorageHook
  extends KeyedElement
{
  public abstract int getStorageVersion();
  
  public abstract StorageHook create(BaseData paramBaseData)
    throws BundleException;
  
  public abstract void initialize(Dictionary<String, String> paramDictionary)
    throws BundleException;
  
  public abstract StorageHook load(BaseData paramBaseData, DataInputStream paramDataInputStream)
    throws IOException;
  
  public abstract void save(DataOutputStream paramDataOutputStream)
    throws IOException;
  
  public abstract void copy(StorageHook paramStorageHook);
  
  public abstract void validate()
    throws IllegalArgumentException;
  
  public abstract Dictionary<String, String> getManifest(boolean paramBoolean)
    throws BundleException;
  
  public abstract boolean forgetStatusChange(int paramInt);
  
  public abstract boolean forgetStartLevelChange(int paramInt);
}

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

import java.net.URL;
import java.security.ProtectionDomain;
import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;
import org.eclipse.osgi.baseadaptor.bundlefile.BundleFile;
import org.eclipse.osgi.framework.adaptor.BundleClassLoader;

public abstract interface BaseClassLoader
  extends BundleClassLoader
{
  public abstract ProtectionDomain getDomain();
  
  public abstract ClasspathEntry createClassPathEntry(BundleFile paramBundleFile, ProtectionDomain paramProtectionDomain);
  
  public abstract Class<?> defineClass(String paramString, byte[] paramArrayOfByte, ClasspathEntry paramClasspathEntry, BundleEntry paramBundleEntry);
  
  public abstract Class<?> publicFindLoaded(String paramString);
  
  public abstract Object publicGetPackage(String paramString);
  
  public abstract Object publicDefinePackage(String paramString1, String paramString2, String paramString3, String paramString4, String paramString5, String paramString6, String paramString7, URL paramURL);
  
  public abstract ClasspathManager getClasspathManager();
}

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

import java.security.ProtectionDomain;
import org.eclipse.osgi.baseadaptor.BaseData;
import org.eclipse.osgi.baseadaptor.bundlefile.BundleFile;
import org.eclipse.osgi.framework.util.KeyedElement;
import org.eclipse.osgi.framework.util.KeyedHashSet;

public class ClasspathEntry
{
  private final BundleFile bundlefile;
  private final ProtectionDomain domain;
  private KeyedHashSet userObjects = null;
  private volatile BaseData data;
  
  public ClasspathEntry(BundleFile bundlefile, ProtectionDomain domain)
  {
    this.bundlefile = bundlefile;
    this.domain = domain;
  }
  
  public BundleFile getBundleFile()
  {
    return bundlefile;
  }
  
  public BaseData getBaseData()
  {
    return data;
  }
  
  void setBaseData(BaseData data)
  {
    this.data = data;
  }
  
  public ProtectionDomain getDomain()
  {
    return domain;
  }
  
  /* Error */
  public Object getUserObject(Object key)
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 52	org/eclipse/osgi/baseadaptor/loader/ClasspathEntry:userObjects	Lorg/eclipse/osgi/framework/util/KeyedHashSet;
    //   4: ifnonnull +5 -> 9
    //   7: aconst_null
    //   8: areturn
    //   9: aload_0
    //   10: getfield 52	org/eclipse/osgi/baseadaptor/loader/ClasspathEntry:userObjects	Lorg/eclipse/osgi/framework/util/KeyedHashSet;
    //   13: dup
    //   14: astore_2
    //   15: monitorenter
    //   16: aload_0
    //   17: getfield 52	org/eclipse/osgi/baseadaptor/loader/ClasspathEntry:userObjects	Lorg/eclipse/osgi/framework/util/KeyedHashSet;
    //   20: aload_1
    //   21: invokevirtual 56	org/eclipse/osgi/framework/util/KeyedHashSet:getByKey	(Ljava/lang/Object;)Lorg/eclipse/osgi/framework/util/KeyedElement;
    //   24: aload_2
    //   25: monitorexit
    //   26: areturn
    //   27: aload_2
    //   28: monitorexit
    //   29: athrow
    // Line number table:
    //   Java source line #78	-> byte code offset #0
    //   Java source line #79	-> byte code offset #7
    //   Java source line #80	-> byte code offset #9
    //   Java source line #81	-> byte code offset #16
    //   Java source line #80	-> byte code offset #27
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	30	0	this	ClasspathEntry
    //   0	30	1	key	Object
    //   14	14	2	Ljava/lang/Object;	Object
    // Exception table:
    //   from	to	target	type
    //   16	26	27	finally
    //   27	29	27	finally
  }
  
  public synchronized void addUserObject(KeyedElement userObject)
  {
    if (userObjects == null) {
      userObjects = new KeyedHashSet(5, false);
    }
    synchronized (userObjects)
    {
      userObjects.add(userObject);
    }
  }
}

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

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.security.ProtectionDomain;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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.ClassLoadingHook;
import org.eclipse.osgi.baseadaptor.hooks.ClassLoadingStatsHook;
import org.eclipse.osgi.framework.adaptor.BundleData;
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.debug.Debug;
import org.eclipse.osgi.framework.internal.core.FrameworkProperties;
import org.eclipse.osgi.internal.baseadaptor.AdaptorMsg;
import org.eclipse.osgi.internal.baseadaptor.ArrayMap;
import org.eclipse.osgi.util.NLS;
import org.osgi.framework.BundleException;

public class ClasspathManager
{
  private static final FragmentClasspath[] emptyFragments = new FragmentClasspath[0];
  private static final String PROP_CLASSLOADER_LOCK = "osgi.classloader.lock";
  private static final String VALUE_CLASSNAME_LOCK = "classname";
  private static final boolean LOCK_CLASSNAME = "classname".equals(FrameworkProperties.getProperty("osgi.classloader.lock"));
  private static final Class<?>[] NULL_CLASS_RESULT = new Class[2];
  private final BaseData data;
  private final String[] classpath;
  private final BaseClassLoader classloader;
  private final boolean isParallelClassLoader;
  private final Map<String, Thread> classNameLocks = new HashMap(5);
  private ClasspathEntry[] entries;
  private FragmentClasspath[] fragments = emptyFragments;
  private ArrayMap<String, String> loadedLibraries = null;
  private ThreadLocal<Collection<String>> currentlyDefining = new ThreadLocal();
  
  public ClasspathManager(BaseData data, String[] classpath, BaseClassLoader classloader)
  {
    this.data = data;
    this.classpath = classpath;
    this.classloader = classloader;
    isParallelClassLoader = ((classloader instanceof ParallelClassLoader) ? ((ParallelClassLoader)classloader).isParallelCapable() : false);
  }
  
  public void initialize()
  {
    entries = buildClasspath(classpath, this, data, classloader == null ? null : classloader.getDomain());
    ClassLoadingHook[] hooks = data.getAdaptor().getHookRegistry().getClassLoadingHooks();
    if (classloader != null) {
      for (int i = 0; i < hooks.length; i++) {
        hooks[i].initializedClassLoader(classloader, data);
      }
    }
  }
  
  public void close()
  {
    if (entries != null) {
      for (int i = 0; i < entries.length; i++) {
        if (entries[i] != null) {
          try
          {
            entries[i].getBundleFile().close();
          }
          catch (IOException e)
          {
            data.getAdaptor().getEventPublisher().publishFrameworkEvent(2, data.getBundle(), e);
          }
        }
      }
    }
    for (int i = 0; i < fragments.length; i++) {
      fragments[i].close();
    }
  }
  
  public void attachFragment(BundleData sourcedata, ProtectionDomain sourcedomain, String[] sourceclasspath)
  {
    try
    {
      sourcedata.open();
    }
    catch (IOException e)
    {
      ((BaseData)sourcedata).getAdaptor().getEventPublisher().publishFrameworkEvent(2, ((BaseData)sourcedata).getBundle(), e);
    }
    ClasspathEntry[] fragEntries = buildClasspath(sourceclasspath, this, (BaseData)sourcedata, sourcedomain);
    FragmentClasspath fragClasspath = new FragmentClasspath((BaseData)sourcedata, fragEntries, sourcedomain);
    insertFragment(fragClasspath);
  }
  
  private synchronized void insertFragment(FragmentClasspath fragClasspath)
  {
    FragmentClasspath[] newFragments = new FragmentClasspath[fragments.length + 1];
    
    long fragID = fragClasspath.getBundleData().getBundleID();
    int insert = 0;
    for (int i = 0; i < fragments.length; i++)
    {
      long otherID = fragments[i].getBundleData().getBundleID();
      if ((insert == 0) && (fragID < otherID))
      {
        newFragments[i] = fragClasspath;
        insert = 1;
      }
      newFragments[(i + insert)] = fragments[i];
    }
    if (insert == 0) {
      newFragments[fragments.length] = fragClasspath;
    }
    fragments = newFragments;
  }
  
  private static ClasspathEntry[] buildClasspath(String[] cp, ClasspathManager hostloader, BaseData sourcedata, ProtectionDomain sourcedomain)
  {
    ArrayList<ClasspathEntry> result = new ArrayList(cp.length);
    for (int i = 0; i < cp.length; i++) {
      findClassPathEntry(result, cp[i], hostloader, sourcedata, sourcedomain);
    }
    return (ClasspathEntry[])result.toArray(new ClasspathEntry[result.size()]);
  }
  
  public static void findClassPathEntry(ArrayList<ClasspathEntry> result, String cp, ClasspathManager hostloader, BaseData sourcedata, ProtectionDomain sourcedomain)
  {
    ClassLoadingHook[] loaderHooks = sourcedata.getAdaptor().getHookRegistry().getClassLoadingHooks();
    boolean hookAdded = false;
    for (int i = 0; i < loaderHooks.length; i++) {
      hookAdded |= loaderHooks[i].addClassPathEntry(result, cp, hostloader, sourcedata, sourcedomain);
    }
    if ((!addClassPathEntry(result, cp, hostloader, sourcedata, sourcedomain)) && (!hookAdded))
    {
      BundleException be = new BundleException(NLS.bind(AdaptorMsg.BUNDLE_CLASSPATH_ENTRY_NOT_FOUND_EXCEPTION, cp, sourcedata.getLocation()), 3);
      sourcedata.getAdaptor().getEventPublisher().publishFrameworkEvent(32, sourcedata.getBundle(), be);
    }
  }
  
  public static boolean addClassPathEntry(ArrayList<ClasspathEntry> result, String cp, ClasspathManager hostloader, BaseData sourcedata, ProtectionDomain sourcedomain)
  {
    if (cp.equals("."))
    {
      result.add(hostloader.createClassPathEntry(sourcedata.getBundleFile(), sourcedomain, sourcedata));
      return true;
    }
    ClasspathEntry element = hostloader.getClasspath(cp, sourcedata, sourcedomain);
    if (element != null)
    {
      result.add(element);
      return true;
    }
    if (data == sourcedata) {
      for (int i = 0; i < fragments.length; i++)
      {
        FragmentClasspath fragCP = fragments[i];
        element = hostloader.getClasspath(cp, fragCP.getBundleData(), fragCP.getDomain());
        if (element != null)
        {
          result.add(element);
          return true;
        }
      }
    }
    return false;
  }
  
  public ClasspathEntry getClasspath(String cp, BaseData sourcedata, ProtectionDomain sourcedomain)
  {
    BundleFile bundlefile = null;
    
    BundleEntry cpEntry = sourcedata.getBundleFile().getEntry(cp);
    if ((cpEntry != null) && (cpEntry.getName().endsWith("/")))
    {
      bundlefile = createBundleFile(cp, sourcedata);
    }
    else
    {
      File file;
      if ((file = sourcedata.getBundleFile().getFile(cp, false)) != null) {
        bundlefile = createBundleFile(file, sourcedata);
      }
    }
    if (bundlefile != null) {
      return createClassPathEntry(bundlefile, sourcedomain, sourcedata);
    }
    return null;
  }
  
  public ClasspathEntry getExternalClassPath(String cp, BaseData sourcedata, ProtectionDomain sourcedomain)
  {
    File file = new File(cp);
    if (!file.isAbsolute()) {
      return null;
    }
    BundleFile bundlefile = createBundleFile(file, sourcedata);
    if (bundlefile != null) {
      return createClassPathEntry(bundlefile, sourcedomain, sourcedata);
    }
    return null;
  }
  
  private static BundleFile createBundleFile(Object content, BaseData sourcedata)
  {
    if ((content == null) || (((content instanceof File)) && (!((File)content).exists()))) {
      return null;
    }
    try
    {
      return sourcedata.getAdaptor().createBundleFile(content, sourcedata);
    }
    catch (IOException e)
    {
      sourcedata.getAdaptor().getEventPublisher().publishFrameworkEvent(2, sourcedata.getBundle(), e);
    }
    return null;
  }
  
  private ClasspathEntry createClassPathEntry(BundleFile bundlefile, ProtectionDomain cpDomain, BaseData cpData)
  {
    ClasspathEntry entry;
    ClasspathEntry entry;
    if (classloader != null) {
      entry = classloader.createClassPathEntry(bundlefile, cpDomain);
    } else {
      entry = new ClasspathEntry(bundlefile, null);
    }
    entry.setBaseData(cpData);
    Object domain = entry.getDomain();
    if ((domain instanceof BundleProtectionDomain)) {
      ((BundleProtectionDomain)domain).setBundle(cpData.getBundle());
    }
    return entry;
  }
  
  public URL findLocalResource(String resource)
  {
    ClassLoadingStatsHook[] hooks = data.getAdaptor().getHookRegistry().getClassLoadingStatsHooks();
    for (int i = 0; i < hooks.length; i++) {
      hooks[i].preFindLocalResource(resource, this);
    }
    URL result = null;
    try
    {
      result = findLocalResourceImpl(resource, -1);
      int i;
      return result;
    }
    finally
    {
      for (int i = 0; i < hooks.length; i++) {
        hooks[i].postFindLocalResource(resource, result, this);
      }
    }
  }
  
  private URL findLocalResourceImpl(String resource, int classPathIndex)
  {
    URL result = null;
    int curIndex = 0;
    for (int i = 0; i < entries.length; i++)
    {
      if (entries[i] != null)
      {
        result = findResourceImpl(resource, entries[i].getBundleFile(), curIndex);
        if ((result != null) && ((classPathIndex == -1) || (classPathIndex == curIndex))) {
          return result;
        }
      }
      curIndex++;
    }
    for (int i = 0; i < fragments.length; i++)
    {
      ClasspathEntry[] fragEntries = fragments[i].getEntries();
      for (int j = 0; j < fragEntries.length; j++)
      {
        result = findResourceImpl(resource, fragEntries[j].getBundleFile(), curIndex);
        if ((result != null) && ((classPathIndex == -1) || (classPathIndex == curIndex))) {
          return result;
        }
        curIndex++;
      }
    }
    return null;
  }
  
  public Enumeration<URL> findLocalResources(String resource)
  {
    List<URL> resources = new ArrayList(6);
    int classPathIndex = 0;
    for (int i = 0; i < entries.length; i++)
    {
      if (entries[i] != null)
      {
        URL url = findResourceImpl(resource, entries[i].getBundleFile(), classPathIndex);
        if (url != null) {
          resources.add(url);
        }
      }
      classPathIndex++;
    }
    for (int i = 0; i < fragments.length; i++)
    {
      ClasspathEntry[] fragEntries = fragments[i].getEntries();
      for (int j = 0; j < fragEntries.length; j++)
      {
        URL url = findResourceImpl(resource, fragEntries[j].getBundleFile(), classPathIndex);
        if (url != null) {
          resources.add(url);
        }
        classPathIndex++;
      }
    }
    if (resources.size() > 0) {
      return Collections.enumeration(resources);
    }
    return null;
  }
  
  private URL findResourceImpl(String name, BundleFile bundlefile, int index)
  {
    return bundlefile.getResourceURL(name, data, index);
  }
  
  public BundleEntry findLocalEntry(String path)
  {
    return findLocalEntry(path, -1);
  }
  
  public BundleEntry findLocalEntry(String path, int classPathIndex)
  {
    BundleEntry result = null;
    int curIndex = 0;
    for (int i = 0; i < entries.length; i++)
    {
      if (entries[i] != null)
      {
        result = findEntryImpl(path, entries[i].getBundleFile());
        if ((result != null) && ((classPathIndex == -1) || (classPathIndex == curIndex))) {
          return result;
        }
      }
      curIndex++;
    }
    for (int i = 0; i < fragments.length; i++)
    {
      ClasspathEntry[] fragEntries = fragments[i].getEntries();
      for (int j = 0; j < fragEntries.length; j++)
      {
        result = findEntryImpl(path, fragEntries[j].getBundleFile());
        if ((result != null) && ((classPathIndex == -1) || (classPathIndex == curIndex))) {
          return result;
        }
        curIndex++;
      }
    }
    return null;
  }
  
  public Enumeration<BundleEntry> findLocalEntries(String path)
  {
    List<BundleEntry> objects = new ArrayList(6);
    for (int i = 0; i < entries.length; i++) {
      if (entries[i] != null)
      {
        BundleEntry result = findEntryImpl(path, entries[i].getBundleFile());
        if (result != null) {
          objects.add(result);
        }
      }
    }
    for (int i = 0; i < fragments.length; i++)
    {
      ClasspathEntry[] fragEntries = fragments[i].getEntries();
      for (int j = 0; j < fragEntries.length; j++)
      {
        BundleEntry result = findEntryImpl(path, fragEntries[j].getBundleFile());
        if (result != null) {
          objects.add(result);
        }
      }
    }
    if (objects.size() > 0) {
      return Collections.enumeration(objects);
    }
    return null;
  }
  
  private BundleEntry findEntryImpl(String path, BundleFile bundleFile)
  {
    return bundleFile.getEntry(path);
  }
  
  public Class<?> findLocalClass(String classname)
    throws ClassNotFoundException
  {
    Class<?> result = null;
    ClassLoadingStatsHook[] hooks = data.getAdaptor().getHookRegistry().getClassLoadingStatsHooks();
    try
    {
      for (int i = 0; i < hooks.length; i++) {
        hooks[i].preFindLocalClass(classname, this);
      }
      result = findLoadedClass(classname);
      Class<?> localClass1;
      if (result != null)
      {
        int i;
        return result;
      }
      result = findLocalClassImpl(classname, hooks);
      int i;
      return result;
    }
    finally
    {
      for (int i = 0; i < hooks.length; i++) {
        hooks[i].postFindLocalClass(classname, result, this);
      }
    }
  }
  
  /* Error */
  private Class<?> findLoadedClass(String classname)
  {
    // Byte code:
    //   0: getstatic 540	org/eclipse/osgi/baseadaptor/loader/ClasspathManager:LOCK_CLASSNAME	Z
    //   3: ifne +10 -> 13
    //   6: aload_0
    //   7: getfield 541	org/eclipse/osgi/baseadaptor/loader/ClasspathManager:isParallelClassLoader	Z
    //   10: ifeq +45 -> 55
    //   13: aload_0
    //   14: aload_1
    //   15: invokespecial 608	org/eclipse/osgi/baseadaptor/loader/ClasspathManager:lockClassName	(Ljava/lang/String;)Z
    //   18: istore_2
    //   19: aload_0
    //   20: getfield 547	org/eclipse/osgi/baseadaptor/loader/ClasspathManager:classloader	Lorg/eclipse/osgi/baseadaptor/loader/BaseClassLoader;
    //   23: aload_1
    //   24: invokeinterface 661 2 0
    //   29: astore 4
    //   31: iload_2
    //   32: ifeq +8 -> 40
    //   35: aload_0
    //   36: aload_1
    //   37: invokespecial 607	org/eclipse/osgi/baseadaptor/loader/ClasspathManager:unlockClassName	(Ljava/lang/String;)V
    //   40: aload 4
    //   42: areturn
    //   43: astore_3
    //   44: iload_2
    //   45: ifeq +8 -> 53
    //   48: aload_0
    //   49: aload_1
    //   50: invokespecial 607	org/eclipse/osgi/baseadaptor/loader/ClasspathManager:unlockClassName	(Ljava/lang/String;)V
    //   53: aload_3
    //   54: athrow
    //   55: aload_0
    //   56: getfield 547	org/eclipse/osgi/baseadaptor/loader/ClasspathManager:classloader	Lorg/eclipse/osgi/baseadaptor/loader/BaseClassLoader;
    //   59: dup
    //   60: astore_2
    //   61: monitorenter
    //   62: aload_0
    //   63: getfield 547	org/eclipse/osgi/baseadaptor/loader/ClasspathManager:classloader	Lorg/eclipse/osgi/baseadaptor/loader/BaseClassLoader;
    //   66: aload_1
    //   67: invokeinterface 661 2 0
    //   72: aload_2
    //   73: monitorexit
    //   74: areturn
    //   75: aload_2
    //   76: monitorexit
    //   77: athrow
    // Line number table:
    //   Java source line #474	-> byte code offset #0
    //   Java source line #475	-> byte code offset #13
    //   Java source line #477	-> byte code offset #19
    //   Java source line #479	-> byte code offset #31
    //   Java source line #480	-> byte code offset #35
    //   Java source line #477	-> byte code offset #40
    //   Java source line #478	-> byte code offset #43
    //   Java source line #479	-> byte code offset #44
    //   Java source line #480	-> byte code offset #48
    //   Java source line #481	-> byte code offset #53
    //   Java source line #483	-> byte code offset #55
    //   Java source line #484	-> byte code offset #62
    //   Java source line #483	-> byte code offset #75
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	78	0	this	ClasspathManager
    //   0	78	1	classname	String
    //   18	27	2	initialLock	boolean
    //   60	16	2	Ljava/lang/Object;	Object
    //   43	11	3	localObject1	Object
    //   29	12	4	localClass	Class
    // Exception table:
    //   from	to	target	type
    //   19	31	43	finally
    //   62	74	75	finally
    //   75	77	75	finally
  }
  
  private Class<?> findLocalClassImpl(String classname, ClassLoadingStatsHook[] hooks)
    throws ClassNotFoundException
  {
    Class<?> result = null;
    for (int i = 0; i < entries.length; i++) {
      if (entries[i] != null)
      {
        result = findClassImpl(classname, entries[i], hooks);
        if (result != null) {
          return result;
        }
      }
    }
    for (int i = 0; i < fragments.length; i++)
    {
      ClasspathEntry[] fragEntries = fragments[i].getEntries();
      for (int j = 0; j < fragEntries.length; j++)
      {
        result = findClassImpl(classname, fragEntries[j], hooks);
        if (result != null) {
          return result;
        }
      }
    }
    throw new ClassNotFoundException(classname);
  }
  
  private boolean lockClassName(String classname)
  {
    synchronized (classNameLocks)
    {
      Object lockingThread = classNameLocks.get(classname);
      Thread current = Thread.currentThread();
      if (lockingThread == current) {
        return false;
      }
      for (;;)
      {
        if (lockingThread == null)
        {
          classNameLocks.put(classname, current);
          return true;
        }
        try
        {
          classNameLocks.wait();
          lockingThread = classNameLocks.get(classname);
        }
        catch (InterruptedException e)
        {
          current.interrupt();
          throw ((LinkageError)new LinkageError(classname).initCause(e));
        }
      }
    }
  }
  
  private void unlockClassName(String classname)
  {
    synchronized (classNameLocks)
    {
      classNameLocks.remove(classname);
      classNameLocks.notifyAll();
    }
  }
  
  private Class<?> findClassImpl(String name, ClasspathEntry classpathEntry, ClassLoadingStatsHook[] hooks)
  {
    if (Debug.DEBUG_LOADER) {
      Debug.println("BundleClassLoader[" + classpathEntry.getBundleFile() + "].findClassImpl(" + name + ")");
    }
    String filename = name.replace('.', '/').concat(".class");
    BundleEntry entry = classpathEntry.getBundleFile().getEntry(filename);
    if (entry == null) {
      return null;
    }
    try
    {
      classbytes = entry.getBytes();
    }
    catch (IOException e)
    {
      byte[] classbytes;
      if (Debug.DEBUG_LOADER) {
        Debug.println("  IOException reading " + filename + " from " + classpathEntry.getBundleFile());
      }
      throw ((LinkageError)new LinkageError("Error reading class bytes: " + name).initCause(e));
    }
    byte[] classbytes;
    if (Debug.DEBUG_LOADER)
    {
      Debug.println("  read " + classbytes.length + " bytes from " + classpathEntry.getBundleFile() + "/" + filename);
      Debug.println("  defining class " + name);
    }
    Collection<String> current = (Collection)currentlyDefining.get();
    if (current == null)
    {
      current = new ArrayList(5);
      currentlyDefining.set(current);
    }
    if (current.contains(name)) {
      return null;
    }
    try
    {
      current.add(name);
      return defineClass(name, classbytes, classpathEntry, entry, hooks);
    }
    catch (Error e)
    {
      if (Debug.DEBUG_LOADER) {
        Debug.println("  error defining class " + name);
      }
      throw e;
    }
    finally
    {
      current.remove(name);
    }
  }
  
  /* Error */
  private Class<?> defineClass(String name, byte[] classbytes, ClasspathEntry classpathEntry, BundleEntry entry, ClassLoadingStatsHook[] statsHooks)
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 546	org/eclipse/osgi/baseadaptor/loader/ClasspathManager:data	Lorg/eclipse/osgi/baseadaptor/BaseData;
    //   4: invokevirtual 592	org/eclipse/osgi/baseadaptor/BaseData:getAdaptor	()Lorg/eclipse/osgi/baseadaptor/BaseAdaptor;
    //   7: invokevirtual 585	org/eclipse/osgi/baseadaptor/BaseAdaptor:getHookRegistry	()Lorg/eclipse/osgi/baseadaptor/HookRegistry;
    //   10: invokevirtual 595	org/eclipse/osgi/baseadaptor/HookRegistry:getClassLoadingHooks	()[Lorg/eclipse/osgi/baseadaptor/hooks/ClassLoadingHook;
    //   13: astore 6
    //   15: aload_2
    //   16: astore 7
    //   18: getstatic 542	org/eclipse/osgi/baseadaptor/loader/ClasspathManager:NULL_CLASS_RESULT	[Ljava/lang/Class;
    //   21: astore 8
    //   23: iconst_0
    //   24: istore 9
    //   26: goto +32 -> 58
    //   29: aload 6
    //   31: iload 9
    //   33: aaload
    //   34: aload_1
    //   35: aload_2
    //   36: aload_3
    //   37: aload 4
    //   39: aload_0
    //   40: invokeinterface 652 6 0
    //   45: astore 7
    //   47: aload 7
    //   49: ifnull +6 -> 55
    //   52: aload 7
    //   54: astore_2
    //   55: iinc 9 1
    //   58: iload 9
    //   60: aload 6
    //   62: arraylength
    //   63: if_icmplt -34 -> 29
    //   66: getstatic 540	org/eclipse/osgi/baseadaptor/loader/ClasspathManager:LOCK_CLASSNAME	Z
    //   69: ifne +10 -> 79
    //   72: aload_0
    //   73: getfield 541	org/eclipse/osgi/baseadaptor/loader/ClasspathManager:isParallelClassLoader	Z
    //   76: ifeq +52 -> 128
    //   79: aload_0
    //   80: aload_1
    //   81: invokespecial 608	org/eclipse/osgi/baseadaptor/loader/ClasspathManager:lockClassName	(Ljava/lang/String;)Z
    //   84: istore 9
    //   86: aload_0
    //   87: aload_1
    //   88: aload_2
    //   89: aload_3
    //   90: aload 4
    //   92: invokespecial 620	org/eclipse/osgi/baseadaptor/loader/ClasspathManager:defineClassHoldingLock	(Ljava/lang/String;[BLorg/eclipse/osgi/baseadaptor/loader/ClasspathEntry;Lorg/eclipse/osgi/baseadaptor/bundlefile/BundleEntry;)[Ljava/lang/Class;
    //   95: astore 8
    //   97: goto +18 -> 115
    //   100: astore 10
    //   102: iload 9
    //   104: ifeq +8 -> 112
    //   107: aload_0
    //   108: aload_1
    //   109: invokespecial 607	org/eclipse/osgi/baseadaptor/loader/ClasspathManager:unlockClassName	(Ljava/lang/String;)V
    //   112: aload 10
    //   114: athrow
    //   115: iload 9
    //   117: ifeq +82 -> 199
    //   120: aload_0
    //   121: aload_1
    //   122: invokespecial 607	org/eclipse/osgi/baseadaptor/loader/ClasspathManager:unlockClassName	(Ljava/lang/String;)V
    //   125: goto +74 -> 199
    //   128: aload_0
    //   129: getfield 547	org/eclipse/osgi/baseadaptor/loader/ClasspathManager:classloader	Lorg/eclipse/osgi/baseadaptor/loader/BaseClassLoader;
    //   132: dup
    //   133: astore 9
    //   135: monitorenter
    //   136: aload_0
    //   137: aload_1
    //   138: aload_2
    //   139: aload_3
    //   140: aload 4
    //   142: invokespecial 620	org/eclipse/osgi/baseadaptor/loader/ClasspathManager:defineClassHoldingLock	(Ljava/lang/String;[BLorg/eclipse/osgi/baseadaptor/loader/ClasspathEntry;Lorg/eclipse/osgi/baseadaptor/bundlefile/BundleEntry;)[Ljava/lang/Class;
    //   145: astore 8
    //   147: aload 9
    //   149: monitorexit
    //   150: goto +49 -> 199
    //   153: aload 9
    //   155: monitorexit
    //   156: athrow
    //   157: astore 11
    //   159: iconst_0
    //   160: istore 12
    //   162: goto +26 -> 188
    //   165: aload 5
    //   167: iload 12
    //   169: aaload
    //   170: aload_1
    //   171: aload 8
    //   173: iconst_1
    //   174: aaload
    //   175: aload_2
    //   176: aload_3
    //   177: aload 4
    //   179: aload_0
    //   180: invokeinterface 658 7 0
    //   185: iinc 12 1
    //   188: iload 12
    //   190: aload 5
    //   192: arraylength
    //   193: if_icmplt -28 -> 165
    //   196: aload 11
    //   198: athrow
    //   199: iconst_0
    //   200: istore 12
    //   202: goto +26 -> 228
    //   205: aload 5
    //   207: iload 12
    //   209: aaload
    //   210: aload_1
    //   211: aload 8
    //   213: iconst_1
    //   214: aaload
    //   215: aload_2
    //   216: aload_3
    //   217: aload 4
    //   219: aload
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-2017. Infinite Loop Ltd