org.eclipse.osgi_3.7.2.v20120110-1415

eclipse.osgi.internal.composite.CompositeClassLoader
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.composite;

import java.io.IOException;
import java.io.InputStream;
import java.net.URLConnection;
import java.security.AllPermission;
import java.security.ProtectionDomain;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import org.eclipse.osgi.baseadaptor.BaseAdaptor;
import org.eclipse.osgi.baseadaptor.BaseData;
import org.eclipse.osgi.baseadaptor.HookConfigurator;
import org.eclipse.osgi.baseadaptor.HookRegistry;
import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;
import org.eclipse.osgi.baseadaptor.hooks.AdaptorHook;
import org.eclipse.osgi.baseadaptor.hooks.ClassLoadingHook;
import org.eclipse.osgi.baseadaptor.loader.BaseClassLoader;
import org.eclipse.osgi.baseadaptor.loader.ClasspathEntry;
import org.eclipse.osgi.baseadaptor.loader.ClasspathManager;
import org.eclipse.osgi.framework.adaptor.BundleProtectionDomain;
import org.eclipse.osgi.framework.adaptor.ClassLoaderDelegate;
import org.eclipse.osgi.framework.log.FrameworkLog;
import org.eclipse.osgi.internal.module.CompositeResolveHelper;
import org.eclipse.osgi.internal.module.CompositeResolveHelperRegistry;
import org.eclipse.osgi.internal.module.ResolverImpl;
import org.eclipse.osgi.service.internal.composite.CompositeModule;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.State;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleException;
import org.osgi.framework.ServiceRegistration;
import org.osgi.framework.SynchronousBundleListener;
import org.osgi.framework.launch.Framework;
import org.osgi.service.framework.CompositeBundle;
import org.osgi.service.framework.CompositeBundleFactory;

public class CompositeConfigurator
  implements SynchronousBundleListener, HookConfigurator, AdaptorHook, ClassLoadingHook, CompositeBundleFactory, CompositeResolveHelperRegistry
{
  private BaseAdaptor adaptor;
  private ServiceRegistration factoryService;
  private BundleContext systemContext;
  private final Collection helpers = new ArrayList(0);
  
  public void addHooks(HookRegistry hookRegistry)
  {
    hookRegistry.addAdaptorHook(this);
    
    hookRegistry.addClassLoadingHook(this);
  }
  
  public void addProperties(Properties properties) {}
  
  public FrameworkLog createFrameworkLog()
  {
    return null;
  }
  
  public void frameworkStart(BundleContext context)
    throws BundleException
  {
    systemContext = context;
    context.addBundleListener(this);
    addHelpers(context.getBundles());
    
    ((ResolverImpl)adaptor.getState().getResolver()).setCompositeResolveHelperRegistry(this);
    
    factoryService = context.registerService(new String[] { CompositeBundleFactory.class.getName() }, this, null);
  }
  
  public void frameworkStop(BundleContext context)
  {
    if (factoryService != null) {
      factoryService.unregister();
    }
    factoryService = null;
    
    stopFrameworks();
    context.removeBundleListener(this);
    removeAllHelpers();
  }
  
  public void frameworkStopping(BundleContext context) {}
  
  public void handleRuntimeError(Throwable error) {}
  
  public void initialize(BaseAdaptor initAdaptor)
  {
    adaptor = initAdaptor;
  }
  
  public URLConnection mapLocationToURLConnection(String location)
  {
    return null;
  }
  
  public boolean matchDNChain(String pattern, String[] dnChain)
  {
    return false;
  }
  
  public CompositeBundle installCompositeBundle(Map frameworkConfig, String location, Map compositeManifest)
    throws BundleException
  {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
      sm.checkPermission(new AllPermission());
    }
    compositeManifest = new HashMap(compositeManifest);
    
    CompositeHelper.validateCompositeManifest(compositeManifest);
    try
    {
      InputStream content = CompositeHelper.getCompositeInput(frameworkConfig, compositeManifest);
      CompositeBundle result = (CompositeBundle)systemContext.installBundle(location, content);
      
      CompositeHelper.setCompositePermissions(location, systemContext);
      return result;
    }
    catch (IOException e)
    {
      throw new BundleException("Error creating composite bundle", e);
    }
  }
  
  private void stopFrameworks()
  {
    Bundle[] allBundles = systemContext.getBundles();
    for (int i = 0; i < allBundles.length; i++) {
      if ((allBundles[i] instanceof CompositeBundle))
      {
        CompositeBundle composite = (CompositeBundle)allBundles[i];
        try
        {
          Framework child = composite.getCompositeFramework();
          child.stop();
          
          child.waitForStop(30000L);
        }
        catch (Throwable t)
        {
          t.printStackTrace();
        }
      }
    }
  }
  
  public CompositeResolveHelper getCompositeResolveHelper(BundleDescription bundle)
  {
    synchronized (helpers)
    {
      if (helpers.size() == 0) {
        return null;
      }
      for (Iterator iHelpers = helpers.iterator(); iHelpers.hasNext();)
      {
        CompositeBase composite = (CompositeBase)iHelpers.next();
        if (composite.getBundleId() == bundle.getBundleId()) {
          return composite;
        }
      }
      return null;
    }
  }
  
  public boolean addClassPathEntry(ArrayList cpEntries, String cp, ClasspathManager hostmanager, BaseData sourcedata, ProtectionDomain sourcedomain)
  {
    return false;
  }
  
  public BaseClassLoader createClassLoader(ClassLoader parent, ClassLoaderDelegate delegate, BundleProtectionDomain domain, BaseData data, String[] bundleclasspath)
  {
    if ((data.getType() & 0x60) == 0) {
      return null;
    }
    ClassLoaderDelegate companionDelegate = ((CompositeModule)((CompositeBase)data.getBundle()).getCompanionBundle()).getDelegate();
    return new CompositeClassLoader(parent, delegate, companionDelegate, data);
  }
  
  public String findLibrary(BaseData data, String libName)
  {
    return null;
  }
  
  public ClassLoader getBundleClassLoaderParent()
  {
    return null;
  }
  
  public void initializedClassLoader(BaseClassLoader baseClassLoader, BaseData data) {}
  
  public byte[] processClass(String name, byte[] classbytes, ClasspathEntry classpathEntry, BundleEntry entry, ClasspathManager manager)
  {
    return null;
  }
  
  private void addHelpers(Bundle[] bundles)
  {
    synchronized (helpers)
    {
      for (int i = 0; i < bundles.length; i++) {
        addHelper(bundles[i]);
      }
    }
  }
  
  private void addHelper(Bundle bundle)
  {
    if (!(bundle instanceof CompositeBase)) {
      return;
    }
    synchronized (helpers)
    {
      if (!helpers.contains(bundle)) {
        helpers.add(bundle);
      }
    }
  }
  
  private void removeHelper(Bundle bundle)
  {
    if (!(bundle instanceof CompositeBase)) {
      return;
    }
    synchronized (helpers)
    {
      helpers.remove(bundle);
    }
  }
  
  private void removeAllHelpers()
  {
    synchronized (helpers)
    {
      helpers.clear();
    }
  }
  
  public void bundleChanged(BundleEvent event)
  {
    switch (event.getType())
    {
    case 1: 
      addHelper(event.getBundle());
      break;
    case 16: 
      removeHelper(event.getBundle());
      break;
    }
  }
}

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

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.jar.Attributes;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
import org.eclipse.osgi.internal.baseadaptor.BaseStorageHook;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.DisabledInfo;
import org.eclipse.osgi.service.resolver.ExportPackageDescription;
import org.eclipse.osgi.service.resolver.State;
import org.osgi.framework.BundleException;
import org.osgi.framework.PackagePermission;
import org.osgi.framework.ServicePermission;
import org.osgi.framework.Version;
import org.osgi.service.permissionadmin.PermissionInfo;

public class CompositeHelper
{
  private static final PermissionInfo[] COMPOSITE_PERMISSIONS = { new PermissionInfo(PackagePermission.class.getName(), "*", "export"), new PermissionInfo(ServicePermission.class.getName(), "*", "register,get") };
  private static final String COMPOSITE_POLICY = "org.eclipse.osgi.composite";
  private static String ELEMENT_SEPARATOR = "; ";
  private static final Object EQUALS_QUOTE = "=\"";
  private static final String[] INVALID_COMPOSITE_HEADERS = { "DynamicImport-Package", "Fragment-Host", "Require-Bundle", "Bundle-NativeCode", "Bundle-ClassPath", "Bundle-Activator", "Bundle-Localization", "Bundle-ActivationPolicy" };
  static Class class$2;
  static Class class$3;
  
  private static Manifest getCompositeManifest(Map compositeManifest)
  {
    Manifest manifest = new Manifest();
    Attributes attributes = manifest.getMainAttributes();
    attributes.putValue("Manifest-Version", "1.0");
    
    String manifestVersion = (String)compositeManifest.remove("Bundle-ManifestVersion");
    
    attributes.putValue("Bundle-ManifestVersion", manifestVersion);
    
    compositeManifest.remove(BaseStorageHook.COMPOSITE_HEADER);
    attributes.putValue(BaseStorageHook.COMPOSITE_HEADER, BaseStorageHook.COMPOSITE_BUNDLE);
    for (Iterator entries = compositeManifest.entrySet().iterator(); entries.hasNext();)
    {
      Map.Entry entry = (Map.Entry)entries.next();
      if (((entry.getKey() instanceof String)) && ((entry.getValue() instanceof String))) {
        attributes.putValue((String)entry.getKey(), (String)entry.getValue());
      }
    }
    return manifest;
  }
  
  private static Manifest getSurrogateManifest(Dictionary compositeManifest, BundleDescription compositeDesc, ExportPackageDescription[] matchingExports)
  {
    Manifest manifest = new Manifest();
    Attributes attributes = manifest.getMainAttributes();
    attributes.putValue("Manifest-Version", "1.0");
    
    attributes.putValue("Bundle-ManifestVersion", "2");
    
    attributes.putValue(BaseStorageHook.COMPOSITE_HEADER, BaseStorageHook.SURROGATE_BUNDLE);
    if ((compositeDesc != null) && (matchingExports != null))
    {
      addImports(attributes, compositeDesc, matchingExports);
      
      addExports(attributes, compositeDesc, matchingExports);
    }
    for (Enumeration keys = compositeManifest.keys(); keys.hasMoreElements();)
    {
      Object header = keys.nextElement();
      if ((!"Bundle-ManifestVersion".equals(header)) && (!BaseStorageHook.COMPOSITE_HEADER.equals(header)) && (!"Import-Package".equals(header)) && (!"Export-Package".equals(header))) {
        if (((header instanceof String)) && ((compositeManifest.get(header) instanceof String))) {
          attributes.putValue((String)header, (String)compositeManifest.get(header));
        }
      }
    }
    return manifest;
  }
  
  /* Error */
  static InputStream getCompositeInput(Map frameworkConfig, Map compositeManifest)
    throws IOException
  {
    // Byte code:
    //   0: new 254	java/io/ByteArrayOutputStream
    //   3: dup
    //   4: invokespecial 471	java/io/ByteArrayOutputStream:<init>	()V
    //   7: astore_2
    //   8: aload_1
    //   9: invokestatic 510	org/eclipse/osgi/internal/composite/CompositeHelper:getCompositeManifest	(Ljava/util/Map;)Ljava/util/jar/Manifest;
    //   12: astore_3
    //   13: new 279	java/util/jar/JarOutputStream
    //   16: dup
    //   17: aload_2
    //   18: aload_3
    //   19: invokespecial 503	java/util/jar/JarOutputStream:<init>	(Ljava/io/OutputStream;Ljava/util/jar/Manifest;)V
    //   22: astore 4
    //   24: new 275	java/util/Properties
    //   27: dup
    //   28: invokespecial 494	java/util/Properties:<init>	()V
    //   31: astore 5
    //   33: aload_0
    //   34: ifnull +9 -> 43
    //   37: aload 5
    //   39: aload_0
    //   40: invokevirtual 495	java/util/Properties:putAll	(Ljava/util/Map;)V
    //   43: new 278	java/util/jar/JarEntry
    //   46: dup
    //   47: getstatic 469	org/eclipse/osgi/internal/composite/CompositeImpl:COMPOSITE_CONFIGURATION	Ljava/lang/String;
    //   50: invokespecial 498	java/util/jar/JarEntry:<init>	(Ljava/lang/String;)V
    //   53: astore 6
    //   55: aload 4
    //   57: aload 6
    //   59: invokevirtual 502	java/util/jar/JarOutputStream:putNextEntry	(Ljava/util/zip/ZipEntry;)V
    //   62: aload 5
    //   64: aload 4
    //   66: aconst_null
    //   67: invokevirtual 496	java/util/Properties:store	(Ljava/io/OutputStream;Ljava/lang/String;)V
    //   70: aload 4
    //   72: invokevirtual 500	java/util/jar/JarOutputStream:closeEntry	()V
    //   75: aload 4
    //   77: invokevirtual 501	java/util/jar/JarOutputStream:flush	()V
    //   80: goto +17 -> 97
    //   83: astore 7
    //   85: aload 4
    //   87: invokevirtual 499	java/util/jar/JarOutputStream:close	()V
    //   90: goto +4 -> 94
    //   93: pop
    //   94: aload 7
    //   96: athrow
    //   97: aload 4
    //   99: invokevirtual 499	java/util/jar/JarOutputStream:close	()V
    //   102: goto +4 -> 106
    //   105: pop
    //   106: new 253	java/io/ByteArrayInputStream
    //   109: dup
    //   110: aload_2
    //   111: invokevirtual 472	java/io/ByteArrayOutputStream:toByteArray	()[B
    //   114: invokespecial 470	java/io/ByteArrayInputStream:<init>	([B)V
    //   117: areturn
    // Line number table:
    //   Java source line #81	-> byte code offset #0
    //   Java source line #84	-> byte code offset #8
    //   Java source line #85	-> byte code offset #13
    //   Java source line #88	-> byte code offset #24
    //   Java source line #89	-> byte code offset #33
    //   Java source line #90	-> byte code offset #37
    //   Java source line #91	-> byte code offset #43
    //   Java source line #92	-> byte code offset #55
    //   Java source line #93	-> byte code offset #62
    //   Java source line #94	-> byte code offset #70
    //   Java source line #95	-> byte code offset #75
    //   Java source line #96	-> byte code offset #83
    //   Java source line #98	-> byte code offset #85
    //   Java source line #99	-> byte code offset #93
    //   Java source line #102	-> byte code offset #94
    //   Java source line #98	-> byte code offset #97
    //   Java source line #99	-> byte code offset #105
    //   Java source line #103	-> byte code offset #106
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	118	0	frameworkConfig	Map
    //   0	118	1	compositeManifest	Map
    //   7	104	2	bytesOut	ByteArrayOutputStream
    //   12	7	3	manifest	Manifest
    //   22	76	4	jarOut	JarOutputStream
    //   31	32	5	fwProps	java.util.Properties
    //   53	5	6	entry	java.util.jar.JarEntry
    //   83	12	7	localObject	Object
    //   93	1	8	localIOException1	IOException
    //   105	1	9	localIOException2	IOException
    // Exception table:
    //   from	to	target	type
    //   24	83	83	finally
    //   85	90	93	java/io/IOException
    //   97	102	105	java/io/IOException
  }
  
  static InputStream getSurrogateInput(Dictionary compositeManifest, BundleDescription compositeDesc, ExportPackageDescription[] matchingExports)
    throws IOException
  {
    ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
    Manifest manifest = getSurrogateManifest(compositeManifest, compositeDesc, matchingExports);
    JarOutputStream jarOut = new JarOutputStream(bytesOut, manifest);
    jarOut.flush();
    jarOut.close();
    return new ByteArrayInputStream(bytesOut.toByteArray());
  }
  
  private static void addImports(Attributes attrigutes, BundleDescription compositeDesc, ExportPackageDescription[] matchingExports)
  {
    ExportPackageDescription[] exports = compositeDesc.getExportPackages();
    List systemExports = getSystemExports(matchingExports);
    if ((exports.length == 0) && (systemExports.size() == 0)) {
      return;
    }
    StringBuffer importStatement = new StringBuffer();
    Collection importedNames = new ArrayList(exports.length);
    for (int i = 0; i < exports.length; i++)
    {
      if (i != 0) {
        importStatement.append(',');
      }
      importedNames.add(exports[i].getName());
      getImportFrom(exports[i], importStatement);
    }
    for (Iterator iSystemExports = systemExports.iterator(); iSystemExports.hasNext();)
    {
      ExportPackageDescription systemExport = (ExportPackageDescription)iSystemExports.next();
      if (!importedNames.contains(systemExport.getName()))
      {
        if (i != 0) {
          importStatement.append(',');
        }
        i++;
        importStatement.append(systemExport.getName()).append(ELEMENT_SEPARATOR).append("bundle-symbolic-name").append('=').append("system.bundle");
      }
    }
    attrigutes.putValue("Import-Package", importStatement.toString());
  }
  
  private static List getSystemExports(ExportPackageDescription[] matchingExports)
  {
    ArrayList list = null;
    for (int i = 0; i < matchingExports.length; i++) {
      if (matchingExports[i].getExporter().getBundleId() == 0L)
      {
        if (list == null) {
          list = new ArrayList();
        }
        list.add(matchingExports[i]);
      }
    }
    return list == null ? Collections.EMPTY_LIST : list;
  }
  
  private static void getImportFrom(ExportPackageDescription export, StringBuffer importStatement)
  {
    importStatement.append(export.getName()).append(ELEMENT_SEPARATOR);
    Version version = export.getVersion();
    importStatement.append("version").append(EQUALS_QUOTE).append('[').append(version).append(',').append(new Version(version.getMajor(), version.getMinor(), version.getMicro() + 1)).append(')').append('"');
    addMap(importStatement, export.getAttributes(), "=");
  }
  
  private static void addExports(Attributes attributes, BundleDescription compositeDesc, ExportPackageDescription[] matchingExports)
  {
    if (matchingExports.length == 0) {
      return;
    }
    StringBuffer exportStatement = new StringBuffer();
    for (int i = 0; i < matchingExports.length; i++) {
      if (matchingExports[i].getExporter() != compositeDesc)
      {
        if (exportStatement.length() > 0) {
          exportStatement.append(',');
        }
        getExportFrom(matchingExports[i], exportStatement);
      }
    }
    if (exportStatement.length() > 0) {
      attributes.putValue("Export-Package", exportStatement.toString());
    }
  }
  
  private static void getExportFrom(ExportPackageDescription export, StringBuffer exportStatement)
  {
    exportStatement.append(export.getName()).append(ELEMENT_SEPARATOR);
    exportStatement.append("version").append(EQUALS_QUOTE).append(export.getVersion()).append('"');
    addMap(exportStatement, export.getDirectives(), ":=");
    addMap(exportStatement, export.getAttributes(), "=");
  }
  
  private static void addMap(StringBuffer manifest, Map values, String assignment)
  {
    if (values == null) {
      return;
    }
    for (Iterator iEntries = values.entrySet().iterator(); iEntries.hasNext();)
    {
      manifest.append(ELEMENT_SEPARATOR);
      Map.Entry entry = (Map.Entry)iEntries.next();
      manifest.append(entry.getKey()).append(assignment).append('"');
      Object value = entry.getValue();
      if ((value instanceof String[]))
      {
        String[] strings = (String[])value;
        for (int i = 0; i < strings.length; i++)
        {
          if (i != 0) {
            manifest.append(',');
          }
          manifest.append(strings[i]);
        }
      }
      else
      {
        manifest.append(value);
      }
      manifest.append('"');
    }
  }
  
  /* Error */
  static void setCompositePermissions(String bundleLocation, org.osgi.framework.BundleContext systemContext)
  {
    // Byte code:
    //   0: aload_1
    //   1: getstatic 463	org/eclipse/osgi/internal/composite/CompositeHelper:class$2	Ljava/lang/Class;
    //   4: dup
    //   5: ifnonnull +29 -> 34
    //   8: pop
    //   9: ldc_w 249
    //   12: invokestatic 474	java/lang/Class:forName	(Ljava/lang/String;)Ljava/lang/Class;
    //   15: dup
    //   16: putstatic 463	org/eclipse/osgi/internal/composite/CompositeHelper:class$2	Ljava/lang/Class;
    //   19: goto +15 -> 34
    //   22: new 259	java/lang/NoClassDefFoundError
    //   25: dup_x1
    //   26: swap
    //   27: invokevirtual 488	java/lang/Throwable:getMessage	()Ljava/lang/String;
    //   30: invokespecial 477	java/lang/NoClassDefFoundError:<init>	(Ljava/lang/String;)V
    //   33: athrow
    //   34: invokevirtual 473	java/lang/Class:getName	()Ljava/lang/String;
    //   37: invokeinterface 554 2 0
    //   42: astore_2
    //   43: aload_2
    //   44: ifnonnull +7 -> 51
    //   47: aconst_null
    //   48: goto +10 -> 58
    //   51: aload_1
    //   52: aload_2
    //   53: invokeinterface 553 2 0
    //   58: checkcast 293	org/osgi/service/permissionadmin/PermissionAdmin
    //   61: astore_3
    //   62: aload_3
    //   63: ifnonnull +14 -> 77
    //   66: new 262	java/lang/RuntimeException
    //   69: dup
    //   70: ldc_w 242
    //   73: invokespecial 479	java/lang/RuntimeException:<init>	(Ljava/lang/String;)V
    //   76: athrow
    //   77: aload_3
    //   78: aload_0
    //   79: getstatic 468	org/eclipse/osgi/internal/composite/CompositeHelper:COMPOSITE_PERMISSIONS	[Lorg/osgi/service/permissionadmin/PermissionInfo;
    //   82: invokeinterface 555 3 0
    //   87: goto +16 -> 103
    //   90: astore 4
    //   92: aload_1
    //   93: aload_2
    //   94: invokeinterface 552 2 0
    //   99: pop
    //   100: aload 4
    //   102: athrow
    //   103: aload_1
    //   104: aload_2
    //   105: invokeinterface 552 2 0
    //   110: pop
    //   111: return
    // Line number table:
    //   Java source line #209	-> byte code offset #0
    //   Java source line #210	-> byte code offset #43
    //   Java source line #211	-> byte code offset #62
    //   Java source line #212	-> byte code offset #66
    //   Java source line #214	-> byte code offset #77
    //   Java source line #215	-> byte code offset #90
    //   Java source line #216	-> byte code offset #92
    //   Java source line #217	-> byte code offset #100
    //   Java source line #216	-> byte code offset #103
    //   Java source line #218	-> byte code offset #111
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	112	0	bundleLocation	String
    //   0	112	1	systemContext	org.osgi.framework.BundleContext
    //   42	63	2	ref	org.osgi.framework.ServiceReference
    //   61	17	3	permAdmin	org.osgi.service.permissionadmin.PermissionAdmin
    //   90	11	4	localObject	Object
    //   22	1	5	localClassNotFoundException	ClassNotFoundException
    // Exception table:
    //   from	to	target	type
    //   9	15	22	java/lang/ClassNotFoundException
    //   77	90	90	finally
  }
  
  /* Error */
  static void setDisabled(boolean disable, org.osgi.framework.Bundle bundle, org.osgi.framework.BundleContext systemContext)
  {
    // Byte code:
    //   0: aload_2
    //   1: getstatic 464	org/eclipse/osgi/internal/composite/CompositeHelper:class$3	Ljava/lang/Class;
    //   4: dup
    //   5: ifnonnull +29 -> 34
    //   8: pop
    //   9: ldc_w 248
    //   12: invokestatic 474	java/lang/Class:forName	(Ljava/lang/String;)Ljava/lang/Class;
    //   15: dup
    //   16: putstatic 464	org/eclipse/osgi/internal/composite/CompositeHelper:class$3	Ljava/lang/Class;
    //   19: goto +15 -> 34
    //   22: new 259	java/lang/NoClassDefFoundError
    //   25: dup_x1
    //   26: swap
    //   27: invokevirtual 488	java/lang/Throwable:getMessage	()Ljava/lang/String;
    //   30: invokespecial 477	java/lang/NoClassDefFoundError:<init>	(Ljava/lang/String;)V
    //   33: athrow
    //   34: invokevirtual 473	java/lang/Class:getName	()Ljava/lang/String;
    //   37: invokeinterface 554 2 0
    //   42: astore_3
    //   43: aload_3
    //   44: ifnonnull +7 -> 51
    //   47: aconst_null
    //   48: goto +10 -> 58
    //   51: aload_2
    //   52: aload_3
    //   53: invokeinterface 553 2 0
    //   58: checkcast 287	org/eclipse/osgi/service/resolver/PlatformAdmin
    //   61: astore 4
    //   63: aload 4
    //   65: ifnonnull +14 -> 79
    //   68: new 262	java/lang/RuntimeException
    //   71: dup
    //   72: ldc_w 243
    //   75: invokespecial 479	java/lang/RuntimeException:<init>	(Ljava/lang/String;)V
    //   78: athrow
    //   79: aload 4
    //   81: iconst_0
    //   82: invokeinterface 546 2 0
    //   87: astore 5
    //   89: aload 5
    //   91: aload_1
    //   92: invokeinterface 551 1 0
    //   97: invokeinterface 547 3 0
    //   102: astore 6
    //   104: iload_0
    //   105: aload 6
    //   107: invokestatic 506	org/eclipse/osgi/internal/composite/CompositeHelper:setDisabled	(ZLorg/eclipse/osgi/service/resolver/BundleDescription;)V
    //   110: goto +16 -> 126
    //   113: astore 7
    //   115: aload_2
    //   116: aload_3
    //   117: invokeinterface 552 2 0
    //   122: pop
    //   123: aload 7
    //   125: athrow
    //   126: aload_2
    //   127: aload_3
    //   128: invokeinterface 552 2 0
    //   133: pop
    //   134: return
    // Line number table:
    //   Java source line #221	-> byte code offset #0
    //   Java source line #222	-> byte code offset #43
    //   Java source line #223	-> byte code offset #63
    //   Java source line #224	-> byte code offset #68
    //   Java source line #226	-> byte code offset #79
    //   Java source line #227	-> byte code offset #89
    //   Java source line #228	-> byte code offset #104
    //   Java source line #229	-> byte code offset #113
    //   Java source line #230	-> byte code offset #115
    //   Java source line #231	-> byte code offset #123
    //   Java source line #230	-> byte code offset #126
    //   Java source line #232	-> byte code offset #134
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	135	0	disable	boolean
    //   0	135	1	bundle	org.osgi.framework.Bundle
    //   0	135	2	systemContext	org.osgi.framework.BundleContext
    //   42	86	3	ref	org.osgi.framework.ServiceReference
    //   61	19	4	pa	org.eclipse.osgi.service.resolver.PlatformAdmin
    //   87	3	5	state	State
    //   102	4	6	desc	BundleDescription
    //   113	11	7	localObject	Object
    //   22	1	8	localClassNotFoundException	ClassNotFoundException
    // Exception table:
    //   from	to	target	type
    //   9	15	22	java/lang/ClassNotFoundException
    //   79	113	113	finally
  }
  
  static void setDisabled(boolean disable, BundleDescription bundle)
  {
    State state = bundle.getContainingState();
    if (disable)
    {
      state.addDisabledInfo(new DisabledInfo("org.eclipse.osgi.composite", "Composite companion bundle is not resolved.", bundle));
    }
    else
    {
      DisabledInfo toRemove = state.getDisabledInfo(bundle, "org.eclipse.osgi.composite");
      if (toRemove != null) {
        state.removeDisabledInfo(toRemove);
      }
    }
  }
  
  static void validateCompositeManifest(Map compositeManifest)
    throws BundleException
  {
    if (compositeManifest == null) {
      throw new BundleException("The composite manifest cannot be null.", 3);
    }
    if (compositeManifest.get("Bundle-SymbolicName") == null) {
      throw new BundleException("The composite manifest must contain a Bundle-SymbolicName header.", 3);
    }
    for (int i = 0; i < INVALID_COMPOSITE_HEADERS.length; i++) {
      if (compositeManifest.get(INVALID_COMPOSITE_HEADERS[i]) != null) {
        throw new BundleException("The composite manifest must not contain the header " + INVALID_COMPOSITE_HEADERS[i], 3);
      }
    }
    String manifestVersion = (String)compositeManifest.get("Bundle-ManifestVersion");
    if (manifestVersion == null) {
      compositeManifest.put("Bundle-ManifestVersion", "2");
    } else {
      try
      {
        Integer parsed = Integer.valueOf(manifestVersion);
        if ((parsed.intValue() > 2) || (parsed.intValue() < 2)) {
          throw new BundleException("Invalid Bundle-ManifestVersion: " + manifestVersion);
        }
      }
      catch (NumberFormatException localNumberFormatException)
      {
        throw new BundleException("Invalid Bundle-ManifestVersion: " + manifestVersion);
      }
    }
  }
}

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

import java.util.Dictionary;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.service.framework.SurrogateBundle;

class CompositeImpl$ServiceTrackerManager
{
  static final int COMPOSITE_ACTIVE = 1;
  static final int SURROGATE_ACTIVE = 2;
  private int bundlesActive = 0;
  private CompositeServiceTracker shareToChildServices;
  private CompositeServiceTracker shareToParentServices;
  final CompositeImpl this$0;
  
  CompositeImpl$ServiceTrackerManager(CompositeImpl paramCompositeImpl) {}
  
  void startedComposite()
    throws BundleException
  {
    open(1);
    this$0.getSurrogateBundle().start(1);
  }
  
  void startedSurrogate()
  {
    open(2);
  }
  
  void stoppedComposite()
  {
    try
    {
      this$0.getSurrogateBundle().stop(1);
    }
    catch (BundleException localBundleException) {}catch (IllegalStateException localIllegalStateException) {}
    close(1);
  }
  
  void stoppedSurrogate()
  {
    close(2);
  }
  
  private synchronized void open(int bundleActive)
  {
    bundlesActive |= bundleActive;
    if ((bundlesActive & 0x3) != 3) {
      return;
    }
    shareToChildServices = new CompositeServiceTracker(this$0.getBundleContext(), this$0.getSurrogateBundle().getBundleContext(), (String)this$0.getBundleContext().getBundle().getHeaders("").get("CompositeServiceFilter-Import"));
    shareToChildServices.open();
    
    shareToParentServices = new CompositeServiceTracker(this$0.getSurrogateBundle().getBundleContext(), this$0.getBundleContext(), (String)this$0.getBundleContext().getBundle().getHeaders("").get("CompositeServiceFilter-Export"));
    shareToParentServices.open();
  }
  
  private synchronized void close(int bundleStopped)
  {
    bundlesActive ^= bundleStopped;
    if (shareToChildServices != null) {
      shareToChildServices.close();
    }
    if (shareToParentServices != null) {
      shareToParentServices.close();
    }
  }
}

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

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Dictionary;
import java.util.Map;
import java.util.Properties;
import org.eclipse.osgi.framework.adaptor.BundleClassLoader;
import org.eclipse.osgi.framework.adaptor.BundleData;
import org.eclipse.osgi.framework.internal.core.BundleContextImpl;
import org.eclipse.osgi.internal.loader.BundleLoader;
import org.eclipse.osgi.internal.loader.BundleLoaderProxy;
import org.eclipse.osgi.launch.Equinox;
import org.eclipse.osgi.service.internal.composite.CompositeModule;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.ExportPackageDescription;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.FrameworkEvent;
import org.osgi.service.framework.CompositeBundle;
import org.osgi.service.framework.SurrogateBundle;

public class CompositeImpl
  extends CompositeBase
  implements CompositeBundle
{
  private static String COMPOSITE_STORAGE = "store";
  public static String COMPOSITE_CONFIGURATION = "compositeConfig.properties";
  private final ServiceTrackerManager trackerManager = new ServiceTrackerManager();
  
  public CompositeImpl(BundleData bundledata, org.eclipse.osgi.framework.internal.core.Framework framework)
    throws BundleException
  {
    super(bundledata, framework);
  }
  
  protected org.osgi.framework.launch.Framework findCompanionFramework(org.eclipse.osgi.framework.internal.core.Framework thisFramework, BundleData thisData)
    throws BundleException
  {
    File compositeStorage = thisData.getDataFile(COMPOSITE_STORAGE);
    boolean firstTime = false;
    if (!compositeStorage.exists()) {
      firstTime = true;
    }
    URL childConfig = bundledata.getEntry(COMPOSITE_CONFIGURATION);
    Properties props = new Properties();
    try
    {
      props.load(childConfig.openStream());
    }
    catch (IOException e)
    {
      throw new BundleException("Could not load child configuration", e);
    }
    props.put("org.osgi.framework.storage", compositeStorage.getAbsolutePath());
    
    props.put(PROP_PARENTFRAMEWORK, thisFramework.getSystemBundleContext().getBundle());
    
    props.put(PROP_COMPOSITE, this);
    Equinox equinox = new Equinox(props);
    if (!firstTime) {
      return equinox;
    }
    equinox.init();
    installSurrogate(equinox.getBundleContext(), thisData);
    return equinox;
  }
  
  private void installSurrogate(BundleContext companionContext, BundleData thisData)
    throws BundleException
  {
    try
    {
      InputStream surrogateContent = CompositeHelper.getSurrogateInput(thisData.getManifest(), null, null);
      surrogate = companionContext.installBundle(thisData.getLocation(), surrogateContent);
    }
    catch (IOException e)
    {
      Bundle surrogate;
      throw new BundleException("Error installing parent companion composite bundle", e);
    }
    Bundle surrogate;
    CompositeHelper.setDisabled(true, surrogate, companionContext);
    
    CompositeHelper.setCompositePermissions(thisData.getLocation(), companionContext);
  }
  
  private boolean updateSurrogate(BundleData thisData, BundleDescription child, ExportPackageDescription[] matchingExports)
    throws BundleException
  {
    try
    {
      surrogateContent = CompositeHelper.getSurrogateInput(thisData.getManifest(), child, matchingExports);
    }
    catch (IOException e)
    {
      InputStream surrogateContent;
      throw new BundleException("Error updating surrogate bundle.", e);
    }
    InputStream surrogateContent;
    CompositeModule surrogateComposite = (CompositeModule)getSurrogateBundle();
    surrogateComposite.updateContent(surrogateContent);
    
    boolean disable = matchingExports == null;
    CompositeHelper.setDisabled(disable, getSurrogateBundle(), getCompositeFramework().getBundleContext());
    
    return disable ? false : surrogateComposite.resolveContent();
  }
  
  public org.osgi.framework.launch.Framework getCompositeFramework()
  {
    if (((getState() & 0x1) == 0) && 
      ((companionFramework.getState() & 0x6) != 0)) {
      try
      {
        companionFramework.init();
      }
      catch (BundleException e)
      {
        throw new RuntimeException("Cannot initialize child framework.", e);
      }
    }
    return companionFramework;
  }
  
  public SurrogateBundle getSurrogateBundle()
  {
    return (SurrogateBundle)getCompanionBundle();
  }
  
  protected Bundle getCompanionBundle()
  {
    return getCompositeFramework().getBundleContext().getBundle(1L);
  }
  
  public void update(Map compositeManifest)
    throws BundleException
  {
    CompositeHelper.validateCompositeManifest(compositeManifest);
    if (isResolved())
    {
      BundleLoader loader = getBundleLoader();
      if (loader != null) {
        loader.createClassLoader();
      }
    }
    try
    {
      Map frameworkConfig = getFrameworkConfig();
      
      updateSurrogate(getBundleData(), null, null);
      
      updateContent(CompositeHelper.getCompositeInput(frameworkConfig, compositeManifest));
    }
    catch (IOException e)
    {
      throw new BundleException("Error updating composite.", e);
    }
  }
  
  private Map getFrameworkConfig()
    throws IOException
  {
    Properties result = new Properties();
    URL config = getEntry(COMPOSITE_CONFIGURATION);
    result.load(config.openStream());
    return result;
  }
  
  public void uninstall()
    throws BundleException
  {
    checkClassLoader();
    
    stop(1);
    stopChildFramework();
    super.uninstall();
  }
  
  private void checkClassLoader()
  {
    BundleLoaderProxy proxy = getLoaderProxy();
    if ((proxy != null) && (proxy.inUse()) && (proxy.getBundleLoader() != null))
    {
      BundleClassLoader loader = proxy.getBundleLoader().createClassLoader();
      loader.getResource("dummy");
    }
  }
  
  protected void startHook()
    throws BundleException
  {
    companionFramework.start();
    trackerManager.startedComposite();
  }
  
  protected void stopHook()
    throws BundleException
  {
    checkClassLoader();
    trackerManager.stoppedComposite();
    if ((bundledata.getStatus() & 0x1) == 0) {
      stopChildFramework();
    }
  }
  
  public void started(CompositeModule surrogate)
  {
    if (surrogate == getSurrogateBundle()) {
      trackerManager.startedSurrogate();
    }
  }
  
  public void stopped(CompositeModule surrogate)
  {
    if (surrogate == getSurrogateBundle()) {
      trackerManager.stoppedSurrogate();
    }
  }
  
  private void stopChildFramework()
    throws BundleException
  {
    companionFramework.stop();
    try
    {
      FrameworkEvent stopped = companionFramework.waitForStop(30000L);
      switch (stopped.getType())
      {
      case 2: 
        throw new BundleException("Error stopping the child framework.", stopped.getThrowable());
      case 512: 
        throw new BundleException("Timed out waiting for the child framework to stop.");
      case 64: 
        return;
      }
      throw new BundleException("Unexpected code returned when stopping the child framework:" + stopped.getType());
    }
    catch (InterruptedException e)
    {
      throw new BundleException("Error stopping child framework", e);
    }
  }
  
  public boolean giveExports(ExportPackageDescription[] matchingExports)
  {
    if (matchingExports == null)
    {
      SurrogateBundle surrogate = getSurrogateBundle();
      
      CompositeHelper.setDisabled(true, getSurrogateBundle(), getCompositeFramework().getBundleContext());
      
      ((CompositeModule)surrogate).refreshContent();
      return true;
    }
    try
    {
      return updateSurrogate(getBundleData(), getBundleDescription(), matchingExports);
    }
    catch (BundleException e)
    {
      e.printStackTrace();
    }
    return false;
  }
  
  class ServiceTrackerManager
  {
    static final int COMPOSITE_ACTIVE = 1;
    static final int SURROGATE_ACTIVE = 2;
    private int bundlesActive = 0;
    private CompositeServiceTracker shareToChildServices;
    private CompositeServiceTracker shareToParentServices;
    
    ServiceTrackerManager() {}
    
    void startedComposite()
      throws BundleException
    {
      open(1);
      getSurrogateBundle().start(1);
    }
    
    void startedSurrogate()
    {
      open(2);
    }
    
    void stoppedComposite()
    {
      try
      {
        getSurrogateBundle().stop(1);
      }
      catch (BundleException localBundleException) {}catch (IllegalStateException localIllegalStateException) {}
      close(1);
    }
    
    void stop
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