org.eclipse.osgi_3.7.2.v20120110-1415

f (value != orig) {
      dirty = true;
    }
    return value;
  }
  
  public void save()
    throws IOException
  {
    adaptor.getStorage().save(this);
  }
  
  public boolean isDirty()
  {
    return dirty;
  }
  
  public void setDirty(boolean dirty)
  {
    this.dirty = dirty;
  }
  
  public final String getSymbolicName()
  {
    return symbolicName;
  }
  
  public final void setSymbolicName(String symbolicName)
  {
    this.symbolicName = symbolicName;
  }
  
  public final Version getVersion()
  {
    return version;
  }
  
  public final void setVersion(Version version)
  {
    this.version = version;
  }
  
  public final int getType()
  {
    return type;
  }
  
  public final void setType(int type)
  {
    this.type = type;
  }
  
  public final String[] getClassPath()
    throws BundleException
  {
    ManifestElement[] classpathElements = ManifestElement.parseHeader("Bundle-ClassPath", classpath);
    return getClassPath(classpathElements);
  }
  
  public String getClassPathString()
  {
    return classpath;
  }
  
  public void setClassPathString(String classpath)
  {
    this.classpath = classpath;
  }
  
  public final String getActivator()
  {
    return activator;
  }
  
  public final void setActivator(String activator)
  {
    this.activator = activator;
  }
  
  public final String getExecutionEnvironment()
  {
    return executionEnvironment;
  }
  
  public void setExecutionEnvironment(String executionEnvironment)
  {
    this.executionEnvironment = executionEnvironment;
  }
  
  public final String getDynamicImports()
  {
    return dynamicImports;
  }
  
  public void setDynamicImports(String dynamicImports)
  {
    this.dynamicImports = dynamicImports;
  }
  
  public final BaseAdaptor getAdaptor()
  {
    return adaptor;
  }
  
  public synchronized BundleFile getBundleFile()
    throws IllegalArgumentException
  {
    if (bundleFile == null) {
      try
      {
        bundleFile = adaptor.createBundleFile(null, this);
      }
      catch (IOException e)
      {
        throw ((IllegalArgumentException)new IllegalArgumentException(e.getMessage()).initCause(e));
      }
    }
    return bundleFile;
  }
  
  public synchronized BundleFile getBundleFile(Object content, boolean base)
  {
    return bundleFiles == null ? null : base ? bundleFile : (BundleFile)bundleFiles.get(content);
  }
  
  public synchronized void setBundleFile(Object content, BundleFile bundleFile)
  {
    if (bundleFiles == null) {
      bundleFiles = new ArrayMap(1);
    }
    bundleFiles.put(content, bundleFile);
  }
  
  private static String[] getClassPath(ManifestElement[] classpath)
  {
    if (classpath == null)
    {
      if (Debug.DEBUG_LOADER) {
        Debug.println("  no classpath");
      }
      return new String[] { "." };
    }
    List<String> result = new ArrayList(classpath.length);
    for (int i = 0; i < classpath.length; i++)
    {
      if (Debug.DEBUG_LOADER) {
        Debug.println("  found classpath entry " + classpath[i].getValueComponents());
      }
      String[] paths = classpath[i].getValueComponents();
      for (int j = 0; j < paths.length; j++) {
        result.add(paths[j]);
      }
    }
    return (String[])result.toArray(new String[result.size()]);
  }
  
  public StorageHook getStorageHook(String key)
  {
    if (storageHooks == null) {
      return null;
    }
    for (int i = 0; i < storageHooks.length; i++) {
      if (storageHooks[i].getKey().equals(key)) {
        return storageHooks[i];
      }
    }
    return null;
  }
  
  public void setStorageHooks(StorageHook[] storageHooks)
  {
    if (this.storageHooks != null) {
      return;
    }
    this.storageHooks = storageHooks;
  }
  
  public StorageHook[] getStorageHooks()
  {
    return storageHooks == null ? new StorageHook[0] : storageHooks;
  }
  
  public File getExtractFile(String path)
  {
    return adaptor.getStorage().getExtractFile(this, path);
  }
  
  public void setFileName(String fileName)
  {
    this.fileName = fileName;
  }
  
  public String toString()
  {
    String name = getSymbolicName();
    if (name == null) {
      return getLocation();
    }
    Version ver = getVersion();
    if (ver == null) {
      return name;
    }
    return name + "_" + ver;
  }
  
  public Enumeration<URL> findLocalResources(String path)
  {
    String[] cp;
    try
    {
      cp = getClassPath();
    }
    catch (BundleException localBundleException)
    {
      String[] cp;
      cp = new String[0];
    }
    if (cp == null) {
      cp = new String[0];
    }
    ClasspathManager cm = new ClasspathManager(this, cp, null);
    cm.initialize();
    Enumeration<URL> result = cm.findLocalResources(path);
    
    return result;
  }
}

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

public abstract interface HookConfigurator
{
  public abstract void addHooks(HookRegistry paramHookRegistry);
}

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

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.osgi.baseadaptor.hooks.AdaptorHook;
import org.eclipse.osgi.baseadaptor.hooks.BundleFileFactoryHook;
import org.eclipse.osgi.baseadaptor.hooks.BundleFileWrapperFactoryHook;
import org.eclipse.osgi.baseadaptor.hooks.ClassLoadingHook;
import org.eclipse.osgi.baseadaptor.hooks.ClassLoadingStatsHook;
import org.eclipse.osgi.baseadaptor.hooks.StorageHook;
import org.eclipse.osgi.framework.adaptor.BundleWatcher;
import org.eclipse.osgi.framework.adaptor.ClassLoaderDelegateHook;
import org.eclipse.osgi.framework.internal.core.FrameworkProperties;
import org.eclipse.osgi.framework.log.FrameworkLogEntry;
import org.eclipse.osgi.util.ManifestElement;

public final class HookRegistry
{
  public static final String HOOK_CONFIGURATORS_FILE = "hookconfigurators.properties";
  public static final String HOOK_CONFIGURATORS = "hook.configurators";
  public static final String PROP_HOOK_CONFIGURATORS_INCLUDE = "osgi.hook.configurators.include";
  public static final String PROP_HOOK_CONFIGURATORS_EXCLUDE = "osgi.hook.configurators.exclude";
  public static final String PROP_HOOK_CONFIGURATORS = "osgi.hook.configurators";
  private static final String BUILTIN_HOOKS = "builtin.hooks";
  private BaseAdaptor adaptor;
  private boolean readonly = false;
  private AdaptorHook[] adaptorHooks = new AdaptorHook[0];
  private BundleWatcher[] watchers = new BundleWatcher[0];
  private ClassLoadingHook[] classLoadingHooks = new ClassLoadingHook[0];
  private ClassLoadingStatsHook[] classLoadingStatsHooks = new ClassLoadingStatsHook[0];
  private ClassLoaderDelegateHook[] classLoaderDelegateHooks = new ClassLoaderDelegateHook[0];
  private StorageHook[] storageHooks = new StorageHook[0];
  private BundleFileFactoryHook[] bundleFileFactoryHooks = new BundleFileFactoryHook[0];
  private BundleFileWrapperFactoryHook[] bundleFileWrapperFactoryHooks = new BundleFileWrapperFactoryHook[0];
  
  public HookRegistry(BaseAdaptor adaptor)
  {
    this.adaptor = adaptor;
  }
  
  public FrameworkLogEntry[] initialize()
  {
    List<String> configurators = new ArrayList(5);
    List<FrameworkLogEntry> errors = new ArrayList(0);
    mergeFileHookConfigurators(configurators, errors);
    mergePropertyHookConfigurators(configurators);
    loadConfigurators(configurators, errors);
    
    readonly = true;
    return (FrameworkLogEntry[])errors.toArray(new FrameworkLogEntry[errors.size()]);
  }
  
  /* Error */
  private void mergeFileHookConfigurators(List<String> configuratorList, List<FrameworkLogEntry> errors)
  {
    // Byte code:
    //   0: aload_0
    //   1: invokevirtual 349	java/lang/Object:getClass	()Ljava/lang/Class;
    //   4: invokevirtual 342	java/lang/Class:getClassLoader	()Ljava/lang/ClassLoader;
    //   7: astore_3
    //   8: aload_3
    //   9: ifnull +12 -> 21
    //   12: aload_3
    //   13: ldc 6
    //   15: invokevirtual 345	java/lang/ClassLoader:getResources	(Ljava/lang/String;)Ljava/util/Enumeration;
    //   18: goto +8 -> 26
    //   21: ldc 6
    //   23: invokestatic 346	java/lang/ClassLoader:getSystemResources	(Ljava/lang/String;)Ljava/util/Enumeration;
    //   26: astore 4
    //   28: goto +30 -> 58
    //   31: astore 5
    //   33: aload_2
    //   34: new 207	org/eclipse/osgi/framework/log/FrameworkLogEntry
    //   37: dup
    //   38: ldc 7
    //   40: iconst_4
    //   41: iconst_0
    //   42: ldc 4
    //   44: iconst_0
    //   45: aload 5
    //   47: aconst_null
    //   48: invokespecial 365	org/eclipse/osgi/framework/log/FrameworkLogEntry:<init>	(Ljava/lang/String;IILjava/lang/String;ILjava/lang/Throwable;[Lorg/eclipse/osgi/framework/log/FrameworkLogEntry;)V
    //   51: invokeinterface 374 2 0
    //   56: pop
    //   57: return
    //   58: iconst_0
    //   59: istore 5
    //   61: goto +260 -> 321
    //   64: aload 4
    //   66: invokeinterface 368 1 0
    //   71: checkcast 190	java/net/URL
    //   74: astore 6
    //   76: aconst_null
    //   77: astore 7
    //   79: new 195	java/util/Properties
    //   82: dup
    //   83: invokespecial 357	java/util/Properties:<init>	()V
    //   86: astore 8
    //   88: aload 6
    //   90: invokevirtual 354	java/net/URL:openStream	()Ljava/io/InputStream;
    //   93: astore 7
    //   95: aload 8
    //   97: aload 7
    //   99: invokevirtual 358	java/util/Properties:load	(Ljava/io/InputStream;)V
    //   102: aload 8
    //   104: ldc 5
    //   106: invokevirtual 359	java/util/Properties:getProperty	(Ljava/lang/String;)Ljava/lang/String;
    //   109: astore 9
    //   111: aload 9
    //   113: ifnonnull +20 -> 133
    //   116: aload 7
    //   118: ifnull +203 -> 321
    //   121: aload 7
    //   123: invokevirtual 339	java/io/InputStream:close	()V
    //   126: goto +195 -> 321
    //   129: pop
    //   130: goto +191 -> 321
    //   133: aload 8
    //   135: ldc 2
    //   137: invokevirtual 359	java/util/Properties:getProperty	(Ljava/lang/String;)Ljava/lang/String;
    //   140: invokestatic 341	java/lang/Boolean:valueOf	(Ljava/lang/String;)Ljava/lang/Boolean;
    //   143: invokevirtual 340	java/lang/Boolean:booleanValue	()Z
    //   146: istore 10
    //   148: aload 9
    //   150: ldc 1
    //   152: invokestatic 366	org/eclipse/osgi/util/ManifestElement:getArrayFromList	(Ljava/lang/String;Ljava/lang/String;)[Ljava/lang/String;
    //   155: astore 11
    //   157: iconst_0
    //   158: istore 12
    //   160: goto +56 -> 216
    //   163: aload_1
    //   164: aload 11
    //   166: iload 12
    //   168: aaload
    //   169: invokeinterface 375 2 0
    //   174: ifne +39 -> 213
    //   177: iload 10
    //   179: ifeq +22 -> 201
    //   182: aload_1
    //   183: iload 5
    //   185: iinc 5 1
    //   188: aload 11
    //   190: iload 12
    //   192: aaload
    //   193: invokeinterface 373 3 0
    //   198: goto +15 -> 213
    //   201: aload_1
    //   202: aload 11
    //   204: iload 12
    //   206: aaload
    //   207: invokeinterface 374 2 0
    //   212: pop
    //   213: iinc 12 1
    //   216: iload 12
    //   218: aload 11
    //   220: arraylength
    //   221: if_icmplt -58 -> 163
    //   224: goto +83 -> 307
    //   227: astore 8
    //   229: aload_2
    //   230: new 207	org/eclipse/osgi/framework/log/FrameworkLogEntry
    //   233: dup
    //   234: ldc 7
    //   236: iconst_4
    //   237: iconst_0
    //   238: new 187	java/lang/StringBuffer
    //   241: dup
    //   242: ldc 3
    //   244: invokespecial 351	java/lang/StringBuffer:<init>	(Ljava/lang/String;)V
    //   247: aload 6
    //   249: invokevirtual 355	java/net/URL:toExternalForm	()Ljava/lang/String;
    //   252: invokevirtual 352	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
    //   255: invokevirtual 350	java/lang/StringBuffer:toString	()Ljava/lang/String;
    //   258: iconst_0
    //   259: aload 8
    //   261: aconst_null
    //   262: invokespecial 365	org/eclipse/osgi/framework/log/FrameworkLogEntry:<init>	(Ljava/lang/String;IILjava/lang/String;ILjava/lang/Throwable;[Lorg/eclipse/osgi/framework/log/FrameworkLogEntry;)V
    //   265: invokeinterface 374 2 0
    //   270: pop
    //   271: aload 7
    //   273: ifnull +48 -> 321
    //   276: aload 7
    //   278: invokevirtual 339	java/io/InputStream:close	()V
    //   281: goto +40 -> 321
    //   284: pop
    //   285: goto +36 -> 321
    //   288: astore 13
    //   290: aload 7
    //   292: ifnull +12 -> 304
    //   295: aload 7
    //   297: invokevirtual 339	java/io/InputStream:close	()V
    //   300: goto +4 -> 304
    //   303: pop
    //   304: aload 13
    //   306: athrow
    //   307: aload 7
    //   309: ifnull +12 -> 321
    //   312: aload 7
    //   314: invokevirtual 339	java/io/InputStream:close	()V
    //   317: goto +4 -> 321
    //   320: pop
    //   321: aload 4
    //   323: invokeinterface 367 1 0
    //   328: ifne -264 -> 64
    //   331: return
    // Line number table:
    //   Java source line #107	-> byte code offset #0
    //   Java source line #111	-> byte code offset #8
    //   Java source line #112	-> byte code offset #31
    //   Java source line #113	-> byte code offset #33
    //   Java source line #114	-> byte code offset #57
    //   Java source line #116	-> byte code offset #58
    //   Java source line #117	-> byte code offset #61
    //   Java source line #118	-> byte code offset #64
    //   Java source line #119	-> byte code offset #76
    //   Java source line #122	-> byte code offset #79
    //   Java source line #123	-> byte code offset #88
    //   Java source line #124	-> byte code offset #95
    //   Java source line #125	-> byte code offset #102
    //   Java source line #126	-> byte code offset #111
    //   Java source line #141	-> byte code offset #116
    //   Java source line #143	-> byte code offset #121
    //   Java source line #144	-> byte code offset #129
    //   Java source line #127	-> byte code offset #130
    //   Java source line #128	-> byte code offset #133
    //   Java source line #129	-> byte code offset #148
    //   Java source line #130	-> byte code offset #157
    //   Java source line #131	-> byte code offset #163
    //   Java source line #132	-> byte code offset #177
    //   Java source line #133	-> byte code offset #182
    //   Java source line #135	-> byte code offset #201
    //   Java source line #130	-> byte code offset #213
    //   Java source line #137	-> byte code offset #227
    //   Java source line #138	-> byte code offset #229
    //   Java source line #141	-> byte code offset #271
    //   Java source line #143	-> byte code offset #276
    //   Java source line #144	-> byte code offset #284
    //   Java source line #140	-> byte code offset #288
    //   Java source line #141	-> byte code offset #290
    //   Java source line #143	-> byte code offset #295
    //   Java source line #144	-> byte code offset #303
    //   Java source line #147	-> byte code offset #304
    //   Java source line #141	-> byte code offset #307
    //   Java source line #143	-> byte code offset #312
    //   Java source line #144	-> byte code offset #320
    //   Java source line #117	-> byte code offset #321
    //   Java source line #149	-> byte code offset #331
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	332	0	this	HookRegistry
    //   0	332	1	configuratorList	List<String>
    //   0	332	2	errors	List<FrameworkLogEntry>
    //   7	6	3	cl	ClassLoader
    //   26	3	4	hookConfigurators	java.util.Enumeration<java.net.URL>
    //   58	264	4	hookConfigurators	java.util.Enumeration<java.net.URL>
    //   31	15	5	e	java.io.IOException
    //   59	125	5	curBuiltin	int
    //   74	174	6	url	java.net.URL
    //   77	236	7	input	java.io.InputStream
    //   86	17	8	configuratorProps	java.util.Properties
    //   133	1	8	configuratorProps	java.util.Properties
    //   227	33	8	e	java.io.IOException
    //   109	3	9	hooksValue	String
    //   133	16	9	hooksValue	String
    //   146	32	10	builtin	boolean
    //   155	64	11	configurators	String[]
    //   158	59	12	i	int
    //   288	17	13	localObject	Object
    //   129	1	19	localIOException1	java.io.IOException
    //   284	1	20	localIOException2	java.io.IOException
    //   303	1	21	localIOException3	java.io.IOException
    //   320	1	22	localIOException4	java.io.IOException
    // Exception table:
    //   from	to	target	type
    //   8	28	31	java/io/IOException
    //   121	126	129	java/io/IOException
    //   79	116	227	java/io/IOException
    //   133	224	227	java/io/IOException
    //   276	281	284	java/io/IOException
    //   79	116	288	finally
    //   133	271	288	finally
    //   295	300	303	java/io/IOException
    //   312	317	320	java/io/IOException
  }
  
  private void mergePropertyHookConfigurators(List<String> configuratorList)
  {
    String[] configurators = ManifestElement.getArrayFromList(FrameworkProperties.getProperty("osgi.hook.configurators"), ",");
    if (configurators.length > 0)
    {
      configuratorList.clear();
      for (int i = 0; i < configurators.length; i++) {
        if (!configuratorList.contains(configurators[i])) {
          configuratorList.add(configurators[i]);
        }
      }
      return;
    }
    String[] includeConfigurators = ManifestElement.getArrayFromList(FrameworkProperties.getProperty("osgi.hook.configurators.include"), ",");
    for (int i = 0; i < includeConfigurators.length; i++) {
      if (!configuratorList.contains(includeConfigurators[i])) {
        configuratorList.add(includeConfigurators[i]);
      }
    }
    String[] excludeHooks = ManifestElement.getArrayFromList(FrameworkProperties.getProperty("osgi.hook.configurators.exclude"), ",");
    for (int i = 0; i < excludeHooks.length; i++) {
      configuratorList.remove(excludeHooks[i]);
    }
  }
  
  private void loadConfigurators(List<String> configurators, List<FrameworkLogEntry> errors)
  {
    for (Iterator<String> iHooks = configurators.iterator(); iHooks.hasNext();)
    {
      String hookName = (String)iHooks.next();
      try
      {
        Class<?> clazz = Class.forName(hookName);
        HookConfigurator configurator = (HookConfigurator)clazz.newInstance();
        configurator.addHooks(this);
      }
      catch (Throwable t)
      {
        errors.add(new FrameworkLogEntry("org.eclipse.osgi", 4, 0, "error loading hook: " + hookName, 0, t, null));
      }
    }
  }
  
  public AdaptorHook[] getAdaptorHooks()
  {
    return adaptorHooks;
  }
  
  public BundleWatcher[] getWatchers()
  {
    return watchers;
  }
  
  public ClassLoadingHook[] getClassLoadingHooks()
  {
    return classLoadingHooks;
  }
  
  public ClassLoadingStatsHook[] getClassLoadingStatsHooks()
  {
    return classLoadingStatsHooks;
  }
  
  public ClassLoaderDelegateHook[] getClassLoaderDelegateHooks()
  {
    return classLoaderDelegateHooks;
  }
  
  public StorageHook[] getStorageHooks()
  {
    return storageHooks;
  }
  
  public BundleFileFactoryHook[] getBundleFileFactoryHooks()
  {
    return bundleFileFactoryHooks;
  }
  
  public BundleFileWrapperFactoryHook[] getBundleFileWrapperFactoryHooks()
  {
    return bundleFileWrapperFactoryHooks;
  }
  
  public void addAdaptorHook(AdaptorHook adaptorHook)
  {
    adaptorHooks = ((AdaptorHook[])add(adaptorHook, adaptorHooks, new AdaptorHook[adaptorHooks.length + 1]));
  }
  
  public void addWatcher(BundleWatcher watcher)
  {
    watchers = ((BundleWatcher[])add(watcher, watchers, new BundleWatcher[watchers.length + 1]));
  }
  
  public void addClassLoadingHook(ClassLoadingHook classLoadingHook)
  {
    classLoadingHooks = ((ClassLoadingHook[])add(classLoadingHook, classLoadingHooks, new ClassLoadingHook[classLoadingHooks.length + 1]));
  }
  
  public void addClassLoadingStatsHook(ClassLoadingStatsHook classLoadingStatsHook)
  {
    classLoadingStatsHooks = ((ClassLoadingStatsHook[])add(classLoadingStatsHook, classLoadingStatsHooks, new ClassLoadingStatsHook[classLoadingStatsHooks.length + 1]));
  }
  
  public void addClassLoaderDelegateHook(ClassLoaderDelegateHook classLoaderDelegateHook)
  {
    classLoaderDelegateHooks = ((ClassLoaderDelegateHook[])add(classLoaderDelegateHook, classLoaderDelegateHooks, new ClassLoaderDelegateHook[classLoaderDelegateHooks.length + 1]));
  }
  
  public void addStorageHook(StorageHook storageHook)
  {
    storageHooks = ((StorageHook[])add(storageHook, storageHooks, new StorageHook[storageHooks.length + 1]));
  }
  
  public void addBundleFileFactoryHook(BundleFileFactoryHook factory)
  {
    bundleFileFactoryHooks = ((BundleFileFactoryHook[])add(factory, bundleFileFactoryHooks, new BundleFileFactoryHook[bundleFileFactoryHooks.length + 1]));
  }
  
  public void addBundleFileWrapperFactoryHook(BundleFileWrapperFactoryHook factory)
  {
    bundleFileWrapperFactoryHooks = ((BundleFileWrapperFactoryHook[])add(factory, bundleFileWrapperFactoryHooks, new BundleFileWrapperFactoryHook[bundleFileWrapperFactoryHooks.length + 1]));
  }
  
  private Object[] add(Object newValue, Object[] oldValues, Object[] newValues)
  {
    if (readonly) {
      throw new IllegalStateException("Cannot add hooks dynamically.");
    }
    if (oldValues.length > 0) {
      System.arraycopy(oldValues, 0, newValues, 0, oldValues.length);
    }
    newValues[oldValues.length] = newValue;
    return newValues;
  }
  
  public BaseAdaptor getAdaptor()
  {
    return adaptor;
  }
}

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

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import org.eclipse.osgi.framework.debug.Debug;
import org.eclipse.osgi.internal.baseadaptor.AdaptorUtil;

public abstract class BundleEntry
{
  protected static final int BUF_SIZE = 8192;
  
  public abstract InputStream getInputStream()
    throws IOException;
  
  public abstract long getSize();
  
  public abstract String getName();
  
  public abstract long getTime();
  
  public abstract URL getLocalURL();
  
  public abstract URL getFileURL();
  
  public String toString()
  {
    return getName();
  }
  
  public byte[] getBytes()
    throws IOException
  {
    InputStream in = getInputStream();
    int length = (int)getSize();
    if (Debug.DEBUG_LOADER) {
      Debug.println("  about to read " + length + " bytes from " + getName());
    }
    return AdaptorUtil.getBytes(in, length, 8192);
  }
}

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

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.AccessController;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import org.eclipse.osgi.baseadaptor.BaseData;
import org.eclipse.osgi.framework.internal.core.FrameworkProperties;
import org.eclipse.osgi.framework.internal.protocol.bundleresource.Handler;
import org.eclipse.osgi.framework.util.SecureAction;
import org.eclipse.osgi.util.ManifestElement;

public abstract class BundleFile
{
  protected static final String PROP_SETPERMS_CMD = "osgi.filepermissions.command";
  static final SecureAction secureAction = (SecureAction)AccessController.doPrivileged(SecureAction.createSecureAction());
  protected File basefile;
  private int mruIndex = -1;
  
  public BundleFile() {}
  
  public BundleFile(File basefile)
  {
    this.basefile = basefile;
  }
  
  public abstract File getFile(String paramString, boolean paramBoolean);
  
  public abstract BundleEntry getEntry(String paramString);
  
  public abstract Enumeration<String> getEntryPaths(String paramString);
  
  public abstract void close()
    throws IOException;
  
  public abstract void open()
    throws IOException;
  
  public abstract boolean containsDir(String paramString);
  
  /**
   * @deprecated
   */
  public URL getResourceURL(String path, long hostBundleID)
  {
    return getResourceURL(path, hostBundleID, 0);
  }
  
  /**
   * @deprecated
   */
  public URL getResourceURL(String path, long hostBundleID, int index)
  {
    return internalGetResourceURL(path, null, hostBundleID, index);
  }
  
  public URL getResourceURL(String path, BaseData hostData, int index)
  {
    return internalGetResourceURL(path, hostData, 0L, index);
  }
  
  private URL internalGetResourceURL(String path, BaseData hostData, long hostBundleID, int index)
  {
    BundleEntry bundleEntry = getEntry(path);
    if (bundleEntry == null) {
      return null;
    }
    if (hostData != null) {
      hostBundleID = hostData.getBundleID();
    }
    path = fixTrailingSlash(path, bundleEntry);
    try
    {
      return secureAction.getURL("bundleresource", Long.toString(hostBundleID) + ".fwk" + Integer.toString(hostData.getAdaptor().hashCode()), index, path, new Handler(bundleEntry, hostData == null ? null : hostData.getAdaptor()));
    }
    catch (MalformedURLException localMalformedURLException) {}
    return null;
  }
  
  public File getBaseFile()
  {
    return basefile;
  }
  
  void setMruIndex(int index)
  {
    mruIndex = index;
  }
  
  int getMruIndex()
  {
    return mruIndex;
  }
  
  public static void setPermissions(File file)
  {
    String commandProp = FrameworkProperties.getProperty("osgi.filepermissions.command");
    if (commandProp == null) {
      commandProp = FrameworkProperties.getProperty("org.osgi.framework.command.execpermission");
    }
    if (commandProp == null) {
      return;
    }
    String[] temp = ManifestElement.getArrayFromList(commandProp, " ");
    List<String> command = new ArrayList(temp.length + 1);
    boolean foundFullPath = false;
    for (int i = 0; i < temp.length; i++) {
      if (("[fullpath]".equals(temp[i])) || ("${abspath}".equals(temp[i])))
      {
        command.add(file.getAbsolutePath());
        foundFullPath = true;
      }
      else
      {
        command.add(temp[i]);
      }
    }
    if (!foundFullPath) {
      command.add(file.getAbsolutePath());
    }
    try
    {
      Runtime.getRuntime().exec((String[])command.toArray(new String[command.size()])).waitFor();
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }
  
  public String toString()
  {
    return String.valueOf(basefile);
  }
  
  public static String fixTrailingSlash(String path, BundleEntry entry)
  {
    if (path.length() == 0) {
      return "/";
    }
    if (path.charAt(0) != '/') {
      path = '/' + path;
    }
    String name = entry.getName();
    if (name.length() == 0) {
      return path;
    }
    boolean pathSlash = path.charAt(path.length() - 1) == '/';
    boolean entrySlash = (name.length() > 0) && (name.charAt(name.length() - 1) == '/');
    if (entrySlash != pathSlash) {
      if (entrySlash) {
        path = path + '/';
      } else {
        path = path.substring(0, path.length() - 1);
      }
    }
    return path;
  }
}

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

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
import org.eclipse.osgi.baseadaptor.BaseData;

public class BundleFileWrapperChain
  extends BundleFile
{
  private final BundleFile wrapped;
  private final BundleFileWrapperChain next;
  
  public BundleFileWrapperChain(BundleFile wrapped, BundleFileWrapperChain next)
  {
    this.wrapped = wrapped;
    this.next = next;
  }
  
  public void close()
    throws IOException
  {
    wrapped.close();
  }
  
  public boolean containsDir(String dir)
  {
    return wrapped.containsDir(dir);
  }
  
  public BundleEntry getEntry(String path)
  {
    return wrapped.getEntry(path);
  }
  
  public Enumeration<String> getEntryPaths(String path)
  {
    return wrapped.getEntryPaths(path);
  }
  
  public File getFile(String path, boolean nativeCode)
  {
    return wrapped.getFile(path, nativeCode);
  }
  
  public void open()
    throws IOException
  {
    wrapped.open();
  }
  
  public File getBaseFile()
  {
    return wrapped.getBaseFile();
  }
  
  public URL getResourceURL(String path, BaseData hostData, int index)
  {
    return wrapped.getResourceURL(path, hostData, index);
  }
  
  public String toString()
  {
    return wrapped.toString();
  }
  
  public BundleFile getWrapped()
  {
    return wrapped;
  }
  
  public BundleFileWrapperChain getNext()
  {
    return next;
  }
}

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

import java.io.File;
import java.util.Enumeration;
import java.util.NoSuchElementException;
import org.eclipse.osgi.framework.util.SecureAction;

class DirBundleFile$1
  implements Enumeration<String>
{
  int cur = 0;
  final DirBundleFile this$0;
  
  DirBundleFile$1(DirBundleFile paramDirBundleFile, String[] paramArrayOfString, File paramFile, String paramString) {}
  
  public boolean hasMoreElements()
  {
    return (val$fileList != null) && (cur < val$fileList.length);
  }
  
  public String nextElement()
  {
    if (!hasMoreElements()) {
      throw new NoSuchElementException();
    }
    File childFile = new File(val$pathFile, val$fileList[cur]);
    StringBuffer sb = new StringBuffer(val$dirPath).append(val$fileList[(cur++)]);
    if (BundleFile.secureAction.isDirectory(childFile)) {
      sb.append("/");
    }
    return sb.toString();
  }
}

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

import java.io.File;
import java.io.IOException;
import java.util.Enumeration;
import java.util.NoSuchElementException;
import org.eclipse.osgi.framework.util.SecureAction;
import org.eclipse.osgi.internal.baseadaptor.AdaptorMsg;
import org.eclipse.osgi.util.NLS;

public class DirBundleFile
  extends BundleFile
{
  public DirBundleFile(File basefile)
    throws IOException
  {
    super(basefile);
    if ((!BundleFile.secureAction.exists(basefile)) || (!BundleFile.secureAction.isDirectory(basefile))) {
      throw new IOException(NLS.bind(AdaptorMsg.ADAPTOR_DIRECTORY_EXCEPTION, basefile));
    }
  }
  
  public File getFile(String path, boolean nativeCode)
  {
    boolean checkInBundle = (path != null) && (path.indexOf("..") >= 0);
    File file = new File(basefile, path);
    if (!BundleFile.secureAction.exists(file)) {
      return null;
    }
    if (checkInBundle) {
      try
      {
        if (!BundleFile.secureAction.getCanonicalPath(file).startsWith(BundleFile.secureAction.getCanonicalPath(basefile))) {
          return null;
        }
      }
      catch (IOException localIOException)
      {
        return null;
      }
    }
    return file;
  }
  
  public BundleEntry getEntry(String path)
  {
    File filePath = getFile(path, false);
    if (filePath == null) {
      return null;
    }
    return new FileBundleEntry(filePath, path);
  }
  
  public boolean containsDir(String dir)
  {
    File dirPath = getFile(dir, false);
    return (dirPath != null) && (BundleFile.secureAction.isDirectory(dirPath));
  }
  
  public Enumeration<String> getEntryPaths(String path)
  {
    if ((path.length() > 0) && (path.charAt(0) == '/')) {
      path = path.substring(1);
    }
    final File pathFile = getFile(path, false);
    if ((pathFile == null) || (!BundleFile.secureAction.isDirectory(pathFile))) {
      return null;
    }
    final String[] fileList = BundleFile.secureAction.list(pathFile);
    if ((fileList == null) || (fileList.length == 0)) {
      return null;
    }
    final String dirPath = path + '/';
    new Enumeration()
    {
      int cur = 0;
      
      public boolean hasMoreElements()
      {
        return (fileList != null) && (cur < fileList.length);
      }
      
      public String nextElement()
      {
        if (!hasMoreElements()) {
          throw new NoSuchElementException();
        }
        File childFile = new File(pathFile, fileList[cur]);
        StringBuffer sb = new StringBuffer(dirPath).append(fileList[(cur++)]);
        if (BundleFile.secureAction.isDirectory(childFile)) {
          sb.append("/");
        }
        return sb.toString();
      }
    };
  }
  
  public void close() {}
  
  public void open() {}
}

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

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

public class DirZipBundleEntry
  extends BundleEntry
{
  private ZipBundleFile bundleFile;
  String name;
  
  public DirZipBundleEntry(ZipBundleFile bundleFile, String name)
  {
    this.name = ((name.length() > 0) && (name.charAt(0) == '/') ? name.substring(1) : name);
    this.bundleFile = bundleFile;
  }
  
  public InputStream getInputStream()
    throws IOException
  {
    return new ByteArrayInputStream(new byte[0]);
  }
  
  public long getSize()
  {
    return 0L;
  }
  
  public String getName()
  {
    return name;
  }
  
  public long getTime()
  {
    return 0L;
  }
  
  public URL getLocalURL()
  {
    try
    {
      return new URL("jar:" + bundleFile.basefile.toURL() + "!/" + name);
    }
    catch (MalformedURLException localMalformedURLException) {}
    return null;
  }
  
  public URL getFileURL()
  {
    try
    {
      return bundleFile.extractDirectory(name).toURL();
    }
    catch (MalformedURLException localMalformedURLException) {}
    return null;
  }
}

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

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import org.eclipse.osgi.framework.util.SecureAction;

public class FileBundleEntry
  extends BundleEntry
{
  private final File file;
  private final String name;
  
  FileBundleEntry(File file, String name)
  {
    this.file = file;
    boolean endsInSlash = (name.length() > 0) && (name.charAt(name.length() - 1) == '/');
    if (BundleFile.secureAction.isDirectory(file))
    {
      if (!endsInSlash) {
        name = name + '/';
      }
    }
    else if (endsInSlash) {
      name = name.substring(0, name.length() - 1);
    }
    this.name = name;
  }
  
  public InputStream getInputStream()
    throws IOException
  {
    return BundleFile.secureAction.getFileInputStream(file);
  }
  
  public long getSize()
  {
    return BundleFile.secureAction.length(file);
  }
  
  public String getName()
  {
    return name;
  }
  
  public long getTime()
  {
    return BundleFile.secureAction.lastModified(file);
  }
  
  public URL getLocalURL()
  {
    return getFileURL();
  }
  
  public URL getFileURL()
  {
    try
    {
      return file.toURL();
    }
    catch (MalformedURLException localMalformedURLException) {}
    return null;
  }
}

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

import java.util.Map;
import org.eclipse.osgi.framework.eventmgr.CopyOnWriteIdentityMap;
import org.eclipse.osgi.framework.eventmgr.EventDispatcher;
import org.eclipse.osgi.framework.eventmgr.EventManager;
import org.eclipse.osgi.framework.eventmgr.ListenerQueue;
import org.eclipse.osgi.framework.util.SecureAction;

public class MRUBundleFileList
  implements EventDispatcher<Object, Object, BundleFile>
{
  private static final String PROP_FILE_LIMIT = "osgi.bundlefile.limit";
  private static final int MIN = 10;
  private static final int PROP_FILE_LIMIT_VALUE;
  private static final ThreadLocal<BundleFile> closingBundleFile = new ThreadLocal();
  private final BundleFile[] bundleFileList;
  private final long[] useStampList;
  private final int fileLimit;
  private final EventManager bundleFileCloserManager;
  private final Map<Object, Object> bundleFileCloser;
  
  static
  {
    int propValue = 100;
    try
    {
      String prop = BundleFile.secureAction.getProperty("osgi.bundlefile.limit");
      if (prop != null) {
        propValue = Integer.parseInt(prop);
      }
    }
    catch (NumberFormatException localNumberFormatException) {}
    PROP_FILE_LIMIT_VALUE = propValue;
  }
  
  private int numOpen = 0;
  private long curUseStamp = 0L;
  private boolean firstDispatch = true;
  
  public MRUBundleFileList()
  {
    this(PROP_FILE_LIMIT_VALUE);
  }
  
  public MRUBundleFileList(int fileLimit)
  {
    this.fileLimit = fileLimit;
    if (fileLimit >= 10)
    {
      bundleFileList = new BundleFile[fileLimit];
      useStampList = new long[fileLimit];
      bundleFileCloserManager = new EventManager("Bundle File Closer");
      bundleFileCloser = new CopyOnWriteIdentityMap();
      bundleFileCloser.put(this, this);
    }
    else
    {
      bundleFileList = null;
      useStampList = null;
      bundleFileCloserManager = null;
      bundleFileCloser = null;
    }
  }
  
  public void add(BundleFile bundleFile)
  {
    if (fileLimit < 10) {
      return;
    }
    BundleFile toRemove = null;
    synchronized (this)
    {
      if (bundleFile.getMruIndex() >= 0) {
        return;
      }
      int index = 0;
      if (numOpen < fileLimit)
      {
        for (int i = 0; i < fileLimit; i++) {
          if (bundleFileList[i] == null)
          {
            index = i;
            break;
          }
        }
      }
      else
      {
        index = 0;
        for (int i = 1; i < fileLimit; i++) {
          if (useStampList[i] < useStampList[index]) {
            index = i;
          }
        }
        toRemove = bundleFileList[index];
        if (toRemove.getMruIndex() != index) {
          throw new IllegalStateException("The BundleFile has the incorrect mru index: " + index + " != " + toRemove.getMruIndex());
        }
        removeInternal(toRemove);
      }
      bundleFileList[index] = bundleFile;
      bundleFile.setMruIndex(index);
      incUseStamp(index);
      numOpen += 1;
    }
    closeBundleFile(toRemove);
  }
  
  public boolean remove(BundleFile bundleFile)
  {
    if (fileLimit < 10) {
      return false;
    }
    synchronized (this)
    {
      int index = bundleFile.getMruIndex();
      if ((index >= 0) && (index < fileLimit) && (bundleFileList[index] == bundleFile))
      {
        removeInternal(bundleFile);
        return true;
      }
    }
    return false;
  }
  
  private void removeInternal(BundleFile bundleFile)
  {
    int index = bundleFile.getMruIndex();
    bundleFile.setMruIndex(-1);
    bundleFileList[index] = null;
    useStampList[index] = -1L;
    numOpen -= 1;
  }
  
  public void use(BundleFile bundleFile)
  {
    if (fileLimit < 10) {
      return;
    }
    synchronized (this)
    {
      int index = bundleFile.getMruIndex();
      if ((index >= 0) && (index < fileLimit) && (bundleFileList[index] == bundleFile)) {
        incUseStamp(index);
      }
    }
  }
  
  private void incUseStamp(int index)
  {
    if (curUseStamp == Long.MAX_VALUE)
    {
      for (int i = 0; i < fil
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84

Further reading...

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

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd