org.eclipse.osgi_3.8.2.v20130124-134944

7	-> byte code offset #361
    //   Java source line #358	-> byte code offset #365
    //   Java source line #362	-> byte code offset #374
    //   Java source line #366	-> byte code offset #375
    //   Java source line #367	-> byte code offset #381
    //   Java source line #368	-> byte code offset #392
    //   Java source line #370	-> byte code offset #400
    //   Java source line #372	-> byte code offset #402
    //   Java source line #373	-> byte code offset #416
    //   Java source line #374	-> byte code offset #421
    //   Java source line #375	-> byte code offset #430
    //   Java source line #376	-> byte code offset #436
    //   Java source line #377	-> byte code offset #440
    //   Java source line #381	-> byte code offset #466
    //   Java source line #382	-> byte code offset #473
    //   Java source line #383	-> byte code offset #477
    //   Java source line #384	-> byte code offset #487
    //   Java source line #386	-> byte code offset #493
    //   Java source line #387	-> byte code offset #499
    //   Java source line #390	-> byte code offset #519
    //   Java source line #391	-> byte code offset #523
    //   Java source line #394	-> byte code offset #532
    //   Java source line #396	-> byte code offset #537
    //   Java source line #397	-> byte code offset #543
    //   Java source line #399	-> byte code offset #554
    //   Java source line #400	-> byte code offset #558
    //   Java source line #401	-> byte code offset #565
    //   Java source line #403	-> byte code offset #570
    //   Java source line #406	-> byte code offset #575
    //   Java source line #407	-> byte code offset #584
    //   Java source line #408	-> byte code offset #587
    //   Java source line #409	-> byte code offset #589
    //   Java source line #410	-> byte code offset #594
    //   Java source line #411	-> byte code offset #604
    //   Java source line #412	-> byte code offset #610
    //   Java source line #414	-> byte code offset #650
    //   Java source line #409	-> byte code offset #653
    //   Java source line #410	-> byte code offset #658
    //   Java source line #411	-> byte code offset #668
    //   Java source line #412	-> byte code offset #674
    //   Java source line #416	-> byte code offset #714
    //   Java source line #417	-> byte code offset #722
    //   Java source line #418	-> byte code offset #729
    //   Java source line #419	-> byte code offset #734
    //   Java source line #421	-> byte code offset #759
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	760	0	this	BundleHost
    //   0	760	1	options	int
    //   122	13	2	msg	String
    //   180	10	2	e	IllegalStateException
    //   194	11	2	e	org.eclipse.osgi.service.resolver.ResolverHookException
    //   401	303	2	start	long
    //   414	245	4	bundleStats	org.eclipse.osgi.framework.adaptor.BundleWatcher
    //   535	50	5	e	BundleException
    //   587	64	6	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   153	180	180	java/lang/IllegalStateException
    //   153	180	194	org/eclipse/osgi/service/resolver/ResolverHookException
    //   466	532	535	org/osgi/framework/BundleException
    //   466	587	587	finally
  }
  
  protected void startHook()
    throws BundleException
  {}
  
  protected boolean readyToResume()
  {
    if (getInternalStartLevel() > framework.startLevelManager.getStartLevel()) {
      return false;
    }
    int status = bundledata.getStatus();
    if ((status & 0x1) == 0) {
      return false;
    }
    if (((status & 0x4) == 0) || ((status & 0x2) == 0) || (isLazyTriggerSet())) {
      return true;
    }
    if (!isResolved()) {
      if (!framework.getAdaptor().getState().isResolved())
      {
        if (framework.packageAdmin.resolveBundles(new Bundle[] { this })) {}
      }
      else {
        return false;
      }
    }
    state = 8;
    
    completeStateChange();
    framework.publishBundleEvent(512, this);
    return false;
  }
  
  private synchronized boolean isLazyTriggerSet()
  {
    if (proxy == null) {
      return false;
    }
    BundleLoader loader = proxy.getBasicBundleLoader();
    return loader != null ? loader.isLazyTriggerSet() : false;
  }
  
  protected BundleContextImpl createContext()
  {
    return new BundleContextImpl(this);
  }
  
  protected synchronized BundleContextImpl getContext()
  {
    if (context == null) {
      if ((state & 0x38) != 0) {
        context = createContext();
      }
    }
    return context;
  }
  
  /* Error */
  protected void stopWorker(int options)
    throws BundleException
  {
    // Byte code:
    //   0: iload_1
    //   1: iconst_1
    //   2: iand
    //   3: ifne +51 -> 54
    //   6: aload_0
    //   7: iconst_1
    //   8: iconst_0
    //   9: invokevirtual 509	org/eclipse/osgi/framework/internal/core/BundleHost:setStatus	(IZ)V
    //   12: aload_0
    //   13: iconst_4
    //   14: iconst_0
    //   15: invokevirtual 509	org/eclipse/osgi/framework/internal/core/BundleHost:setStatus	(IZ)V
    //   18: getstatic 451	org/eclipse/osgi/framework/debug/Debug:MONITOR_ACTIVATION	Z
    //   21: ifeq +33 -> 54
    //   24: new 219	java/lang/Exception
    //   27: dup
    //   28: new 224	java/lang/StringBuffer
    //   31: dup
    //   32: ldc_w 207
    //   35: invokespecial 480	java/lang/StringBuffer:<init>	(Ljava/lang/String;)V
    //   38: aload_0
    //   39: invokevirtual 512	org/eclipse/osgi/framework/internal/core/BundleHost:getBundleData	()Lorg/eclipse/osgi/framework/adaptor/BundleData;
    //   42: invokevirtual 483	java/lang/StringBuffer:append	(Ljava/lang/Object;)Ljava/lang/StringBuffer;
    //   45: invokevirtual 479	java/lang/StringBuffer:toString	()Ljava/lang/String;
    //   48: invokespecial 476	java/lang/Exception:<init>	(Ljava/lang/String;)V
    //   51: invokevirtual 475	java/lang/Exception:printStackTrace	()V
    //   54: aload_0
    //   55: getfield 459	org/eclipse/osgi/framework/internal/core/BundleHost:framework	Lorg/eclipse/osgi/framework/internal/core/Framework;
    //   58: getfield 462	org/eclipse/osgi/framework/internal/core/Framework:active	Z
    //   61: ifeq +237 -> 298
    //   64: aload_0
    //   65: getfield 454	org/eclipse/osgi/framework/internal/core/BundleHost:state	I
    //   68: bipush 22
    //   70: iand
    //   71: ifeq +4 -> 75
    //   74: return
    //   75: aload_0
    //   76: getfield 459	org/eclipse/osgi/framework/internal/core/BundleHost:framework	Lorg/eclipse/osgi/framework/internal/core/Framework;
    //   79: getfield 463	org/eclipse/osgi/framework/internal/core/Framework:adaptor	Lorg/eclipse/osgi/framework/adaptor/FrameworkAdaptor;
    //   82: invokeinterface 558 1 0
    //   87: astore_2
    //   88: aload_2
    //   89: ifnull +12 -> 101
    //   92: aload_2
    //   93: aload_0
    //   94: bipush 16
    //   96: invokeinterface 557 3 0
    //   101: aload_0
    //   102: bipush 16
    //   104: putfield 454	org/eclipse/osgi/framework/internal/core/BundleHost:state	I
    //   107: aload_0
    //   108: getfield 459	org/eclipse/osgi/framework/internal/core/BundleHost:framework	Lorg/eclipse/osgi/framework/internal/core/Framework;
    //   111: sipush 256
    //   114: aload_0
    //   115: invokevirtual 523	org/eclipse/osgi/framework/internal/core/Framework:publishBundleEvent	(ILorg/osgi/framework/Bundle;)V
    //   118: aload_0
    //   119: getfield 457	org/eclipse/osgi/framework/internal/core/BundleHost:context	Lorg/eclipse/osgi/framework/internal/core/BundleContextImpl;
    //   122: ifnull +96 -> 218
    //   125: aload_0
    //   126: getfield 457	org/eclipse/osgi/framework/internal/core/BundleHost:context	Lorg/eclipse/osgi/framework/internal/core/BundleContextImpl;
    //   129: invokevirtual 495	org/eclipse/osgi/framework/internal/core/BundleContextImpl:stop	()V
    //   132: goto +86 -> 218
    //   135: astore_3
    //   136: aload_0
    //   137: invokevirtual 506	org/eclipse/osgi/framework/internal/core/BundleHost:stopHook	()V
    //   140: aload_0
    //   141: getfield 457	org/eclipse/osgi/framework/internal/core/BundleHost:context	Lorg/eclipse/osgi/framework/internal/core/BundleContextImpl;
    //   144: ifnull +15 -> 159
    //   147: aload_0
    //   148: getfield 457	org/eclipse/osgi/framework/internal/core/BundleHost:context	Lorg/eclipse/osgi/framework/internal/core/BundleContextImpl;
    //   151: invokevirtual 493	org/eclipse/osgi/framework/internal/core/BundleContextImpl:close	()V
    //   154: aload_0
    //   155: aconst_null
    //   156: putfield 457	org/eclipse/osgi/framework/internal/core/BundleHost:context	Lorg/eclipse/osgi/framework/internal/core/BundleContextImpl;
    //   159: aload_0
    //   160: invokevirtual 503	org/eclipse/osgi/framework/internal/core/BundleHost:checkValid	()V
    //   163: aload_0
    //   164: iconst_4
    //   165: putfield 454	org/eclipse/osgi/framework/internal/core/BundleHost:state	I
    //   168: getstatic 450	org/eclipse/osgi/framework/debug/Debug:DEBUG_GENERAL	Z
    //   171: ifeq +23 -> 194
    //   174: new 224	java/lang/StringBuffer
    //   177: dup
    //   178: ldc_w 205
    //   181: invokespecial 480	java/lang/StringBuffer:<init>	(Ljava/lang/String;)V
    //   184: aload_0
    //   185: invokevirtual 483	java/lang/StringBuffer:append	(Ljava/lang/Object;)Ljava/lang/StringBuffer;
    //   188: invokevirtual 479	java/lang/StringBuffer:toString	()Ljava/lang/String;
    //   191: invokestatic 489	org/eclipse/osgi/framework/debug/Debug:println	(Ljava/lang/String;)V
    //   194: aload_0
    //   195: getfield 459	org/eclipse/osgi/framework/internal/core/BundleHost:framework	Lorg/eclipse/osgi/framework/internal/core/Framework;
    //   198: iconst_4
    //   199: aload_0
    //   200: invokevirtual 523	org/eclipse/osgi/framework/internal/core/Framework:publishBundleEvent	(ILorg/osgi/framework/Bundle;)V
    //   203: aload_2
    //   204: ifnull +12 -> 216
    //   207: aload_2
    //   208: aload_0
    //   209: bipush 32
    //   211: invokeinterface 557 3 0
    //   216: aload_3
    //   217: athrow
    //   218: aload_0
    //   219: invokevirtual 506	org/eclipse/osgi/framework/internal/core/BundleHost:stopHook	()V
    //   222: aload_0
    //   223: getfield 457	org/eclipse/osgi/framework/internal/core/BundleHost:context	Lorg/eclipse/osgi/framework/internal/core/BundleContextImpl;
    //   226: ifnull +15 -> 241
    //   229: aload_0
    //   230: getfield 457	org/eclipse/osgi/framework/internal/core/BundleHost:context	Lorg/eclipse/osgi/framework/internal/core/BundleContextImpl;
    //   233: invokevirtual 493	org/eclipse/osgi/framework/internal/core/BundleContextImpl:close	()V
    //   236: aload_0
    //   237: aconst_null
    //   238: putfield 457	org/eclipse/osgi/framework/internal/core/BundleHost:context	Lorg/eclipse/osgi/framework/internal/core/BundleContextImpl;
    //   241: aload_0
    //   242: invokevirtual 503	org/eclipse/osgi/framework/internal/core/BundleHost:checkValid	()V
    //   245: aload_0
    //   246: iconst_4
    //   247: putfield 454	org/eclipse/osgi/framework/internal/core/BundleHost:state	I
    //   250: getstatic 450	org/eclipse/osgi/framework/debug/Debug:DEBUG_GENERAL	Z
    //   253: ifeq +23 -> 276
    //   256: new 224	java/lang/StringBuffer
    //   259: dup
    //   260: ldc_w 205
    //   263: invokespecial 480	java/lang/StringBuffer:<init>	(Ljava/lang/String;)V
    //   266: aload_0
    //   267: invokevirtual 483	java/lang/StringBuffer:append	(Ljava/lang/Object;)Ljava/lang/StringBuffer;
    //   270: invokevirtual 479	java/lang/StringBuffer:toString	()Ljava/lang/String;
    //   273: invokestatic 489	org/eclipse/osgi/framework/debug/Debug:println	(Ljava/lang/String;)V
    //   276: aload_0
    //   277: getfield 459	org/eclipse/osgi/framework/internal/core/BundleHost:framework	Lorg/eclipse/osgi/framework/internal/core/Framework;
    //   280: iconst_4
    //   281: aload_0
    //   282: invokevirtual 523	org/eclipse/osgi/framework/internal/core/Framework:publishBundleEvent	(ILorg/osgi/framework/Bundle;)V
    //   285: aload_2
    //   286: ifnull +12 -> 298
    //   289: aload_2
    //   290: aload_0
    //   291: bipush 32
    //   293: invokeinterface 557 3 0
    //   298: return
    // Line number table:
    //   Java source line #490	-> byte code offset #0
    //   Java source line #491	-> byte code offset #6
    //   Java source line #492	-> byte code offset #12
    //   Java source line #493	-> byte code offset #18
    //   Java source line #494	-> byte code offset #24
    //   Java source line #496	-> byte code offset #54
    //   Java source line #497	-> byte code offset #64
    //   Java source line #498	-> byte code offset #74
    //   Java source line #501	-> byte code offset #75
    //   Java source line #502	-> byte code offset #88
    //   Java source line #503	-> byte code offset #92
    //   Java source line #505	-> byte code offset #101
    //   Java source line #506	-> byte code offset #107
    //   Java source line #509	-> byte code offset #118
    //   Java source line #510	-> byte code offset #125
    //   Java source line #511	-> byte code offset #132
    //   Java source line #512	-> byte code offset #136
    //   Java source line #513	-> byte code offset #140
    //   Java source line #514	-> byte code offset #147
    //   Java source line #515	-> byte code offset #154
    //   Java source line #518	-> byte code offset #159
    //   Java source line #520	-> byte code offset #163
    //   Java source line #522	-> byte code offset #168
    //   Java source line #523	-> byte code offset #174
    //   Java source line #526	-> byte code offset #194
    //   Java source line #527	-> byte code offset #203
    //   Java source line #528	-> byte code offset #207
    //   Java source line #530	-> byte code offset #216
    //   Java source line #512	-> byte code offset #218
    //   Java source line #513	-> byte code offset #222
    //   Java source line #514	-> byte code offset #229
    //   Java source line #515	-> byte code offset #236
    //   Java source line #518	-> byte code offset #241
    //   Java source line #520	-> byte code offset #245
    //   Java source line #522	-> byte code offset #250
    //   Java source line #523	-> byte code offset #256
    //   Java source line #526	-> byte code offset #276
    //   Java source line #527	-> byte code offset #285
    //   Java source line #528	-> byte code offset #289
    //   Java source line #532	-> byte code offset #298
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	299	0	this	BundleHost
    //   0	299	1	options	int
    //   87	203	2	bundleStats	org.eclipse.osgi.framework.adaptor.BundleWatcher
    //   135	82	3	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   118	135	135	finally
  }
  
  protected void stopHook()
    throws BundleException
  {}
  
  public ServiceReference<?>[] getRegisteredServices()
  {
    checkValid();
    if (context == null) {
      return null;
    }
    return context.getFramework().getServiceRegistry().getRegisteredServices(context);
  }
  
  public ServiceReference<?>[] getServicesInUse()
  {
    checkValid();
    if (context == null) {
      return null;
    }
    return context.getFramework().getServiceRegistry().getServicesInUse(context);
  }
  
  public BundleFragment[] getFragments()
  {
    synchronized (framework.bundles)
    {
      if (fragments == null) {
        return null;
      }
      BundleFragment[] result = new BundleFragment[fragments.length];
      System.arraycopy(fragments, 0, result, 0, result.length);
      return result;
    }
  }
  
  protected void attachFragment(BundleFragment fragment)
    throws BundleException
  {
    BundleLoader loader = getLoaderProxy().getBasicBundleLoader();
    if (loader != null) {
      loader.attachFragment(fragment);
    }
    if (fragments == null)
    {
      fragments = new BundleFragment[] { fragment };
    }
    else
    {
      boolean inserted = false;
      
      BundleFragment[] newFragments = new BundleFragment[fragments.length + 1];
      for (int i = 0; i < fragments.length; i++)
      {
        if (fragment == fragments[i]) {
          return;
        }
        fragments[i].manifestLocalization = null;
        if ((!inserted) && (fragment.getBundleId() < fragments[i].getBundleId()))
        {
          if (loader != null) {
            throw new BundleException(NLS.bind(Msg.BUNDLE_LOADER_ATTACHMENT_ERROR, fragments[i].getSymbolicName(), getSymbolicName()), 2);
          }
          newFragments[i] = fragment;
          inserted = true;
        }
        newFragments[(inserted ? i + 1 : i)] = fragments[i];
      }
      if (!inserted) {
        newFragments[(newFragments.length - 1)] = fragment;
      }
      fragments = newFragments;
    }
    manifestLocalization = null;
  }
  
  protected BundleLoader getBundleLoader()
  {
    BundleLoaderProxy curProxy = getLoaderProxy();
    return curProxy == null ? null : curProxy.getBundleLoader();
  }
  
  public synchronized BundleLoaderProxy getLoaderProxy()
  {
    if (proxy != null) {
      return proxy;
    }
    BundleDescription bundleDescription = getBundleDescription();
    if (bundleDescription == null) {
      return null;
    }
    proxy = new BundleLoaderProxy(this, bundleDescription);
    
    bundleDescription.setUserObject(proxy);
    return proxy;
  }
  
  public ClassLoader getClassLoader()
  {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
      sm.checkPermission(new RuntimePermission("getClassLoader"));
    }
    BundleLoaderProxy curProxy = getLoaderProxy();
    BundleLoader loader = curProxy == null ? null : curProxy.getBundleLoader();
    BundleClassLoader bcl = loader == null ? null : loader.createClassLoader();
    return (bcl instanceof ClassLoader) ? (ClassLoader)bcl : null;
  }
}

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

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.osgi.framework.util.KeyedHashSet;
import org.osgi.framework.Version;

public final class BundleRepository
{
  private List<AbstractBundle> bundlesByInstallOrder;
  private KeyedHashSet bundlesById;
  private Map<String, AbstractBundle[]> bundlesBySymbolicName;
  
  public BundleRepository(int initialCapacity)
  {
    synchronized (this)
    {
      bundlesByInstallOrder = new ArrayList(initialCapacity);
      bundlesById = new KeyedHashSet(initialCapacity, true);
      bundlesBySymbolicName = new HashMap(initialCapacity);
    }
  }
  
  public synchronized List<AbstractBundle> getBundles()
  {
    return bundlesByInstallOrder;
  }
  
  public synchronized AbstractBundle getBundle(long bundleId)
  {
    Long key = new Long(bundleId);
    return (AbstractBundle)bundlesById.getByKey(key);
  }
  
  public synchronized AbstractBundle[] getBundles(String symbolicName)
  {
    if ("system.bundle".equals(symbolicName)) {
      symbolicName = Constants.getInternalSymbolicName();
    }
    return (AbstractBundle[])bundlesBySymbolicName.get(symbolicName);
  }
  
  public synchronized List<AbstractBundle> getBundles(String symbolicName, Version version)
  {
    AbstractBundle[] bundles = getBundles(symbolicName);
    List<AbstractBundle> result = null;
    if ((bundles != null) && 
      (bundles.length > 0)) {
      for (int i = 0; i < bundles.length; i++) {
        if (bundles[i].getVersion().equals(version))
        {
          if (result == null) {
            result = new ArrayList();
          }
          result.add(bundles[i]);
        }
      }
    }
    return result == null ? Collections.EMPTY_LIST : result;
  }
  
  public synchronized void add(AbstractBundle bundle)
  {
    bundlesByInstallOrder.add(bundle);
    bundlesById.add(bundle);
    addSymbolicName(bundle);
  }
  
  private void addSymbolicName(AbstractBundle bundle)
  {
    String symbolicName = bundle.getSymbolicName();
    if (symbolicName == null) {
      return;
    }
    AbstractBundle[] bundles = (AbstractBundle[])bundlesBySymbolicName.get(symbolicName);
    if (bundles == null)
    {
      bundles = new AbstractBundle[1];
      bundles[0] = bundle;
      bundlesBySymbolicName.put(symbolicName, bundles);
      return;
    }
    List<AbstractBundle> list = new ArrayList(bundles.length + 1);
    
    Version newVersion = bundle.getVersion();
    boolean added = false;
    for (int i = 0; i < bundles.length; i++)
    {
      AbstractBundle oldBundle = bundles[i];
      Version oldVersion = oldBundle.getVersion();
      if ((!added) && (newVersion.compareTo(oldVersion) >= 0))
      {
        added = true;
        list.add(bundle);
      }
      list.add(oldBundle);
    }
    if (!added) {
      list.add(bundle);
    }
    bundles = new AbstractBundle[list.size()];
    list.toArray(bundles);
    bundlesBySymbolicName.put(symbolicName, bundles);
  }
  
  public synchronized boolean remove(AbstractBundle bundle)
  {
    boolean found = bundlesById.remove(bundle);
    if (!found) {
      return false;
    }
    bundlesByInstallOrder.remove(bundle);
    
    String symbolicName = bundle.getSymbolicName();
    if (symbolicName == null) {
      return true;
    }
    removeSymbolicName(symbolicName, bundle);
    return true;
  }
  
  private void removeSymbolicName(String symbolicName, AbstractBundle bundle)
  {
    AbstractBundle[] bundles = (AbstractBundle[])bundlesBySymbolicName.get(symbolicName);
    if (bundles == null) {
      return;
    }
    int numRemoved = 0;
    for (int i = 0; i < bundles.length; i++) {
      if (bundle == bundles[i])
      {
        numRemoved++;
        bundles[i] = null;
      }
    }
    if (numRemoved > 0) {
      if (bundles.length - numRemoved <= 0)
      {
        bundlesBySymbolicName.remove(symbolicName);
      }
      else
      {
        AbstractBundle[] newBundles = new AbstractBundle[bundles.length - numRemoved];
        int indexCnt = 0;
        for (int i = 0; i < bundles.length; i++) {
          if (bundles[i] != null)
          {
            newBundles[indexCnt] = bundles[i];
            indexCnt++;
          }
        }
        bundlesBySymbolicName.put(symbolicName, newBundles);
      }
    }
  }
  
  public synchronized void update(String oldSymbolicName, AbstractBundle bundle)
  {
    if (oldSymbolicName != null)
    {
      if (!oldSymbolicName.equals(bundle.getSymbolicName()))
      {
        removeSymbolicName(oldSymbolicName, bundle);
        addSymbolicName(bundle);
      }
    }
    else {
      addSymbolicName(bundle);
    }
  }
  
  public synchronized void removeAllBundles()
  {
    bundlesByInstallOrder.clear();
    bundlesById = new KeyedHashSet();
    bundlesBySymbolicName.clear();
  }
}

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

import java.io.IOException;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
import org.eclipse.osgi.baseadaptor.BaseAdaptor;
import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;
import org.eclipse.osgi.baseadaptor.loader.BaseClassLoader;
import org.eclipse.osgi.framework.adaptor.FrameworkAdaptor;
import org.eclipse.osgi.framework.internal.protocol.ProtocolActivator;
import org.eclipse.osgi.internal.baseadaptor.AdaptorMsg;
import org.eclipse.osgi.internal.loader.BundleLoader;
import org.eclipse.osgi.util.NLS;
import org.osgi.framework.AdminPermission;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;

public abstract class BundleResourceHandler
  extends URLStreamHandler
  implements ProtocolActivator
{
  public static final String SECURITY_CHECKED = "SECURITY_CHECKED";
  public static final String SECURITY_UNCHECKED = "SECURITY_UNCHECKED";
  public static final String BID_FWKID_SEPARATOR = ".fwk";
  private BaseAdaptor adaptor;
  protected BundleEntry bundleEntry;
  
  public BundleResourceHandler()
  {
    this(null, null);
  }
  
  public BundleResourceHandler(BundleEntry bundleEntry, BaseAdaptor adaptor)
  {
    this.bundleEntry = bundleEntry;
    this.adaptor = adaptor;
  }
  
  public void start(BundleContext context, FrameworkAdaptor baseAdaptor)
  {
    adaptor = ((BaseAdaptor)baseAdaptor);
  }
  
  protected void parseURL(URL url, String str, int start, int end)
  {
    if (end < start) {
      return;
    }
    if (url.getPath() != null) {
      bundleEntry = null;
    }
    String spec = "";
    if (start < end) {
      spec = str.substring(start, end);
    }
    end -= start;
    
    String path = url.getPath();
    String host = url.getHost();
    int resIndex = url.getPort();
    if (resIndex < 0) {
      resIndex = 0;
    }
    int pathIdx = 0;
    if (spec.startsWith("//"))
    {
      int bundleIdIdx = 2;
      pathIdx = spec.indexOf('/', bundleIdIdx);
      if (pathIdx == -1)
      {
        pathIdx = end;
        
        path = "";
      }
      int bundleIdEnd = spec.indexOf(':', bundleIdIdx);
      if ((bundleIdEnd > pathIdx) || (bundleIdEnd == -1)) {
        bundleIdEnd = pathIdx;
      }
      if (bundleIdEnd < pathIdx - 1) {
        try
        {
          resIndex = Integer.parseInt(spec.substring(bundleIdEnd + 1, pathIdx));
        }
        catch (NumberFormatException localNumberFormatException) {}
      }
      host = spec.substring(bundleIdIdx, bundleIdEnd);
    }
    if ((pathIdx < end) && (spec.charAt(pathIdx) == '/'))
    {
      path = spec.substring(pathIdx, end);
    }
    else if (end > pathIdx)
    {
      if ((path == null) || (path.equals(""))) {
        path = "/";
      }
      int last = path.lastIndexOf('/') + 1;
      if (last == 0) {
        path = spec.substring(pathIdx, end);
      } else {
        path = path.substring(0, last) + spec.substring(pathIdx, end);
      }
    }
    if (path == null) {
      path = "";
    }
    if ((path.endsWith("/.")) || (path.endsWith("/.."))) {
      path = path + '/';
    }
    int dotIndex;
    while ((dotIndex = path.indexOf("/./")) >= 0)
    {
      int dotIndex;
      path = path.substring(0, dotIndex + 1) + path.substring(dotIndex + 3);
    }
    while ((dotIndex = path.indexOf("/../")) >= 0) {
      if (dotIndex != 0) {
        path = path.substring(0, path.lastIndexOf('/', dotIndex - 1)) + path.substring(dotIndex + 3);
      } else {
        path = path.substring(dotIndex + 3);
      }
    }
    while ((dotIndex = path.indexOf("//")) >= 0) {
      path = path.substring(0, dotIndex + 1) + path.substring(dotIndex + 2);
    }
    String authorized = "SECURITY_UNCHECKED";
    long bundleId = getBundleID(host);
    Bundle bundle = adaptor == null ? null : adaptor.getBundle(bundleId);
    if (checkAuthorization(bundle)) {
      authorized = "SECURITY_CHECKED";
    }
    if (adaptor != null) {
      host = Long.toString(bundleId) + ".fwk" + Integer.toString(adaptor.hashCode());
    }
    setURL(url, url.getProtocol(), host, resIndex, authorized, null, path, null, url.getRef());
  }
  
  protected URLConnection openConnection(URL url)
    throws IOException
  {
    if (bundleEntry != null) {
      return new BundleURLConnection(url, bundleEntry);
    }
    String host = url.getHost();
    if (host == null) {
      throw new IOException(NLS.bind(AdaptorMsg.URL_NO_BUNDLE_ID, url.toExternalForm()));
    }
    AbstractBundle bundle = null;
    try
    {
      bundleID = getBundleID(host);
    }
    catch (NumberFormatException nfe)
    {
      long bundleID;
      throw ((MalformedURLException)new MalformedURLException(NLS.bind(AdaptorMsg.URL_INVALID_BUNDLE_ID, host)).initCause(nfe));
    }
    long bundleID;
    bundle = adaptor == null ? null : (AbstractBundle)adaptor.getBundle(bundleID);
    if (bundle == null) {
      throw new IOException(NLS.bind(AdaptorMsg.URL_NO_BUNDLE_FOUND, url.toExternalForm()));
    }
    if (!url.getAuthority().equals("SECURITY_CHECKED")) {
      checkAuthorization(bundle);
    }
    return new BundleURLConnection(url, findBundleEntry(url, bundle));
  }
  
  protected abstract BundleEntry findBundleEntry(URL paramURL, AbstractBundle paramAbstractBundle)
    throws IOException;
  
  protected String toExternalForm(URL url)
  {
    StringBuffer result = new StringBuffer(url.getProtocol());
    result.append("://");
    
    String host = url.getHost();
    if ((host != null) && (host.length() > 0)) {
      result.append(host);
    }
    int index = url.getPort();
    if (index > 0) {
      result.append(':').append(index);
    }
    String path = url.getPath();
    if (path != null)
    {
      if ((path.length() > 0) && (path.charAt(0) != '/')) {
        result.append("/");
      }
      result.append(path);
    }
    String ref = url.getRef();
    if ((ref != null) && (ref.length() > 0)) {
      result.append('#').append(ref);
    }
    return result.toString();
  }
  
  protected int hashCode(URL url)
  {
    int hash = 0;
    String protocol = url.getProtocol();
    if (protocol != null) {
      hash += protocol.hashCode();
    }
    String host = url.getHost();
    if (host != null) {
      hash += host.hashCode();
    }
    hash += url.getPort();
    
    String path = url.getPath();
    if (path != null) {
      hash += path.hashCode();
    }
    if (adaptor != null) {
      hash += adaptor.hashCode();
    }
    return hash;
  }
  
  protected boolean equals(URL url1, URL url2)
  {
    return sameFile(url1, url2);
  }
  
  protected synchronized InetAddress getHostAddress(URL url)
  {
    return null;
  }
  
  protected boolean hostsEqual(URL url1, URL url2)
  {
    String host1 = url1.getHost();
    String host2 = url2.getHost();
    if ((host1 != null) && (host2 != null)) {
      return host1.equalsIgnoreCase(host2);
    }
    return (host1 == null) && (host2 == null);
  }
  
  protected boolean sameFile(URL url1, URL url2)
  {
    if (url1.hashCode() != url2.hashCode()) {
      return false;
    }
    String p1 = url1.getProtocol();
    String p2 = url2.getProtocol();
    if ((p1 != p2) && ((p1 == null) || (!p1.equalsIgnoreCase(p2)))) {
      return false;
    }
    if (!hostsEqual(url1, url2)) {
      return false;
    }
    if (url1.getPort() != url2.getPort()) {
      return false;
    }
    String path1 = url1.getPath();
    String path2 = url2.getPath();
    if ((path1 != path2) && ((path1 == null) || (!path1.equals(path2)))) {
      return false;
    }
    return true;
  }
  
  protected boolean checkAuthorization(Bundle bundle)
  {
    SecurityManager sm = System.getSecurityManager();
    if (sm == null) {
      return true;
    }
    if (bundle == null) {
      return false;
    }
    sm.checkPermission(new AdminPermission(bundle, "resource"));
    return true;
  }
  
  protected static BaseClassLoader getBundleClassLoader(AbstractBundle bundle)
  {
    BundleLoader loader = bundle.getBundleLoader();
    if (loader == null) {
      return null;
    }
    return (BaseClassLoader)loader.createClassLoader();
  }
  
  private long getBundleID(String host)
  {
    int dotIndex = host.indexOf('.');
    return (dotIndex >= 0) && (dotIndex < host.length() - 1) ? Long.parseLong(host.substring(0, dotIndex)) : Long.parseLong(host);
  }
}

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

import java.io.IOException;
import java.io.InputStream;
import java.net.URLConnection;

public class BundleSource
  extends URLConnection
{
  private InputStream in;
  
  protected BundleSource(InputStream in)
  {
    super(null);
    this.in = in;
  }
  
  public void connect()
    throws IOException
  {
    connected = true;
  }
  
  public InputStream getInputStream()
    throws IOException
  {
    return in;
  }
}

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

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;
import org.eclipse.osgi.internal.baseadaptor.AdaptorMsg;
import org.eclipse.osgi.util.NLS;

public class BundleURLConnection
  extends URLConnection
{
  protected final BundleEntry bundleEntry;
  protected InputStream in;
  protected String contentType;
  
  public BundleURLConnection(URL url, BundleEntry bundleEntry)
  {
    super(url);
    
    this.bundleEntry = bundleEntry;
    in = null;
    contentType = null;
  }
  
  public synchronized void connect()
    throws IOException
  {
    if (!connected) {
      if (bundleEntry != null)
      {
        in = bundleEntry.getInputStream();
        connected = true;
      }
      else
      {
        throw new IOException(NLS.bind(AdaptorMsg.RESOURCE_NOT_FOUND_EXCEPTION, url));
      }
    }
  }
  
  public int getContentLength()
  {
    return (int)bundleEntry.getSize();
  }
  
  public String getContentType()
  {
    if (contentType == null)
    {
      contentType = guessContentTypeFromName(bundleEntry.getName());
      if (contentType == null)
      {
        if (!connected) {
          try
          {
            connect();
          }
          catch (IOException localIOException1)
          {
            return null;
          }
        }
        try
        {
          if (in.markSupported()) {
            contentType = guessContentTypeFromStream(in);
          }
        }
        catch (IOException localIOException2) {}
      }
    }
    return contentType;
  }
  
  public boolean getDoInput()
  {
    return true;
  }
  
  public boolean getDoOutput()
  {
    return false;
  }
  
  public InputStream getInputStream()
    throws IOException
  {
    if (!connected) {
      connect();
    }
    return in;
  }
  
  public long getLastModified()
  {
    long lastModified = bundleEntry.getTime();
    if (lastModified == -1L) {
      return 0L;
    }
    return lastModified;
  }
  
  public URL getLocalURL()
  {
    return bundleEntry.getLocalURL();
  }
  
  public URL getFileURL()
  {
    return bundleEntry.getFileURL();
  }
}

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

import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;

class ConsoleManager$1
  extends FilterInputStream
{
  final ConsoleManager this$0;
  
  ConsoleManager$1(ConsoleManager paramConsoleManager, InputStream $anonymous0)
  {
    super($anonymous0);
  }
  
  public void close()
    throws IOException
  {}
}

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

import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;

class ConsoleManager$2
  extends FilterOutputStream
{
  final ConsoleManager this$0;
  
  ConsoleManager$2(ConsoleManager paramConsoleManager, OutputStream $anonymous0)
  {
    super($anonymous0);
  }
  
  public void close()
    throws IOException
  {}
  
  public void write(byte[] var0, int var1, int var2)
    throws IOException
  {
    out.write(var0, var1, var2);
  }
}

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

import java.io.IOException;
import java.io.PrintStream;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import org.eclipse.osgi.util.NLS;

class ConsoleManager$ConsoleSocketGetter
  implements Runnable
{
  private final ServerSocket server;
  private volatile boolean shutdown = false;
  final ConsoleManager this$0;
  
  ConsoleManager$ConsoleSocketGetter(ConsoleManager arg1, ServerSocket server)
  {
    this.server = server;
    try
    {
      Method reuseAddress = server.getClass().getMethod("setReuseAddress", new Class[] { Boolean.TYPE });
      reuseAddress.invoke(server, new Object[] { Boolean.TRUE });
    }
    catch (Exception localException) {}
    Thread t = new Thread(this, "ConsoleSocketGetter");
    t.setDaemon(false);
    t.start();
  }
  
  public void run()
  {
    System.out.println(NLS.bind(ConsoleMsg.CONSOLE_LISTENING_ON_PORT, server.getInetAddress().toString() + ':' + Integer.toString(server.getLocalPort())));
    while (!shutdown) {
      try
      {
        Socket socket = server.accept();
        if (socket == null) {
          throw new IOException("No socket available.  Probably caused by a shutdown.");
        }
        FrameworkConsoleSession session = new FrameworkConsoleSession(socket.getInputStream(), socket.getOutputStream(), socket); Class 
          tmp108_105 = ConsoleManager.class$0;
        if (tmp108_105 == null)
        {
          tmp108_105;
          try
          {
            tmpTernaryOp = (ConsoleManager.class$0 = Class.forName("org.eclipse.osgi.framework.console.ConsoleSession"));
          }
          catch (ClassNotFoundException localClassNotFoundException)
          {
            throw new NoClassDefFoundError(localClassNotFoundException.getMessage());
          }
        }
        this$0.framework.getSystemBundleContext().registerService(tmp108_105.getName(), session, null);
      }
      catch (Exception e)
      {
        if (!shutdown) {
          e.printStackTrace();
        }
      }
    }
  }
  
  public void shutdown()
  {
    if (shutdown) {
      return;
    }
    shutdown = true;
    try
    {
      server.close();
    }
    catch (IOException e)
    {
      e.printStackTrace();
    }
  }
}

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

import java.io.FilterInputStream;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Dictionary;
import java.util.Hashtable;
import org.eclipse.osgi.framework.console.CommandProvider;
import org.eclipse.osgi.framework.console.ConsoleSession;
import org.eclipse.osgi.util.NLS;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;

public class ConsoleManager
  implements ServiceTrackerCustomizer<ConsoleSession, FrameworkConsole>
{
  public static final String PROP_CONSOLE = "osgi.console";
  private static final String PROP_SYSTEM_IN_OUT = "console.systemInOut";
  private static final String CONSOLE_NAME = "OSGi Console";
  public static final String CONSOLE_BUNDLE = "org.eclipse.equinox.console";
  public static final String PROP_CONSOLE_ENABLED = "osgi.console.enable.builtin";
  final Framework framework;
  private final ServiceTracker<CommandProvider, CommandProvider> cpTracker;
  private final ServiceTracker<ConsoleSession, FrameworkConsole> sessions;
  private final String consolePort;
  private final String consoleHost;
  private FrameworkCommandProvider fwkCommands;
  private ServiceRegistration<?>
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