org.eclipse.osgi_3.7.2.v20120110-1415

pedSurrogate()
    {
      close(2);
    }
    
    private synchronized void open(int bundleActive)
    {
      bundlesActive |= bundleActive;
      if ((bundlesActive & 0x3) != 3) {
        return;
      }
      shareToChildServices = new CompositeServiceTracker(getBundleContext(), getSurrogateBundle().getBundleContext(), (String)getBundleContext().getBundle().getHeaders("").get("CompositeServiceFilter-Import"));
      shareToChildServices.open();
      
      shareToParentServices = new CompositeServiceTracker(getSurrogateBundle().getBundleContext(), getBundleContext(), (String)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
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.composite;

import java.util.Dictionary;
import java.util.Enumeration;
import java.util.Hashtable;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;

class CompositeServiceTracker$ServiceLink
  implements ServiceFactory
{
  private final ServiceReference reference;
  private volatile ServiceRegistration registration;
  private Object service;
  private int useCount;
  final CompositeServiceTracker this$0;
  
  CompositeServiceTracker$ServiceLink(CompositeServiceTracker paramCompositeServiceTracker, ServiceReference reference)
  {
    this.reference = reference;
  }
  
  Dictionary getRefreshProperties()
  {
    Dictionary result = getServiceProperties();
    if (useCount <= 1) {
      return result;
    }
    String[] originalKeys = registration.getReference().getPropertyKeys();
    for (int i = 0; i < originalKeys.length; i++) {
      if ((!"objectClass".equals(originalKeys[i])) && (!"service.id".equals(originalKeys[i]))) {
        if (registration.getReference().getProperty(originalKeys[i]) != result.get(originalKeys[i])) {
          return result;
        }
      }
    }
    for (Enumeration eKeys = result.keys(); eKeys.hasMoreElements();)
    {
      String key = (String)eKeys.nextElement();
      if ((!"objectClass".equals(key)) && (!"service.id".equals(key))) {
        if (result.get(key) != registration.getReference().getProperty(key)) {
          return result;
        }
      }
    }
    return null;
  }
  
  int decrementUse()
  {
    return --useCount;
  }
  
  int incrementUse()
  {
    return ++useCount;
  }
  
  int getUse()
  {
    return useCount;
  }
  
  void setServiceProperties(Dictionary props)
  {
    ServiceRegistration current = registration;
    if (current != null) {
      current.setProperties(props);
    }
  }
  
  void register()
  {
    Dictionary props = getServiceProperties();
    registration = this$0.targetContext.registerService((String[])props.get("objectClass"), this, props);
  }
  
  void unregister()
  {
    ServiceRegistration current = registration;
    if (current != null) {
      current.unregister();
    }
  }
  
  private Dictionary getServiceProperties()
  {
    String[] keys = reference.getPropertyKeys();
    Hashtable serviceProps = new Hashtable(keys.length);
    for (int i = 0; i < keys.length; i++) {
      serviceProps.put(keys[i], reference.getProperty(keys[i]));
    }
    return serviceProps;
  }
  
  public synchronized Object getService(Bundle bundle, ServiceRegistration reg)
  {
    if (service == null) {
      service = this$0.sourceContext.getService(reference);
    }
    return service;
  }
  
  public void ungetService(Bundle bundle, ServiceRegistration reg, Object serv) {}
}

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

import java.util.Dictionary;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import org.eclipse.osgi.util.ManifestElement;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;

class CompositeServiceTracker
  implements ServiceTrackerCustomizer
{
  final BundleContext sourceContext;
  final BundleContext targetContext;
  final ServiceTracker[] trackers;
  final String[] filters;
  final HashMap serviceComposites = new HashMap();
  
  public CompositeServiceTracker(BundleContext sourceContext, BundleContext targetContext, String serviceFilters)
  {
    this.sourceContext = sourceContext;
    this.targetContext = targetContext;
    filters = ManifestElement.getArrayFromList(serviceFilters, ",");
    trackers = new ServiceTracker[filters.length];
  }
  
  synchronized void open()
  {
    for (int i = 0; i < trackers.length; i++) {
      try
      {
        trackers[i] = new ServiceTracker(sourceContext, sourceContext.createFilter(filters[i]), this);
        trackers[i].open();
      }
      catch (InvalidSyntaxException localInvalidSyntaxException) {}
    }
  }
  
  synchronized void close()
  {
    for (int i = 0; i < trackers.length; i++) {
      if (trackers[i] != null) {
        trackers[i].close();
      }
    }
  }
  
  public Object addingService(ServiceReference reference)
  {
    int useCount;
    synchronized (serviceComposites)
    {
      ServiceLink serviceLink = (ServiceLink)serviceComposites.get(reference);
      if (serviceLink == null)
      {
        serviceLink = new ServiceLink(reference);
        serviceComposites.put(reference, serviceLink);
      }
      useCount = serviceLink.incrementUse();
    }
    int useCount;
    ServiceLink serviceLink;
    if (useCount == 1) {
      serviceLink.register();
    }
    return serviceLink;
  }
  
  public void modifiedService(ServiceReference reference, Object service)
  {
    ServiceLink serviceLink = (ServiceLink)service;
    Dictionary serviceProps = null;
    synchronized (serviceComposites)
    {
      serviceProps = serviceLink.getRefreshProperties();
    }
    if (serviceProps != null) {
      ((ServiceLink)service).setServiceProperties(serviceProps);
    }
  }
  
  public void removedService(ServiceReference reference, Object service)
  {
    synchronized (serviceComposites)
    {
      int useCount = ((ServiceLink)service).decrementUse();
      if (useCount == 0) {
        serviceComposites.remove(reference);
      }
    }
    int useCount;
    if (useCount == 0) {
      ((ServiceLink)service).unregister();
    }
  }
  
  class ServiceLink
    implements ServiceFactory
  {
    private final ServiceReference reference;
    private volatile ServiceRegistration registration;
    private Object service;
    private int useCount;
    
    ServiceLink(ServiceReference reference)
    {
      this.reference = reference;
    }
    
    Dictionary getRefreshProperties()
    {
      Dictionary result = getServiceProperties();
      if (useCount <= 1) {
        return result;
      }
      String[] originalKeys = registration.getReference().getPropertyKeys();
      for (int i = 0; i < originalKeys.length; i++) {
        if ((!"objectClass".equals(originalKeys[i])) && (!"service.id".equals(originalKeys[i]))) {
          if (registration.getReference().getProperty(originalKeys[i]) != result.get(originalKeys[i])) {
            return result;
          }
        }
      }
      for (Enumeration eKeys = result.keys(); eKeys.hasMoreElements();)
      {
        String key = (String)eKeys.nextElement();
        if ((!"objectClass".equals(key)) && (!"service.id".equals(key))) {
          if (result.get(key) != registration.getReference().getProperty(key)) {
            return result;
          }
        }
      }
      return null;
    }
    
    int decrementUse()
    {
      return --useCount;
    }
    
    int incrementUse()
    {
      return ++useCount;
    }
    
    int getUse()
    {
      return useCount;
    }
    
    void setServiceProperties(Dictionary props)
    {
      ServiceRegistration current = registration;
      if (current != null) {
        current.setProperties(props);
      }
    }
    
    void register()
    {
      Dictionary props = getServiceProperties();
      registration = targetContext.registerService((String[])props.get("objectClass"), this, props);
    }
    
    void unregister()
    {
      ServiceRegistration current = registration;
      if (current != null) {
        current.unregister();
      }
    }
    
    private Dictionary getServiceProperties()
    {
      String[] keys = reference.getPropertyKeys();
      Hashtable serviceProps = new Hashtable(keys.length);
      for (int i = 0; i < keys.length; i++) {
        serviceProps.put(keys[i], reference.getProperty(keys[i]));
      }
      return serviceProps;
    }
    
    public synchronized Object getService(Bundle bundle, ServiceRegistration reg)
    {
      if (service == null) {
        service = sourceContext.getService(reference);
      }
      return service;
    }
    
    public void ungetService(Bundle bundle, ServiceRegistration reg, Object serv) {}
  }
}

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

import java.util.Properties;
import org.eclipse.osgi.framework.adaptor.BundleData;
import org.eclipse.osgi.framework.internal.core.FrameworkProperties;
import org.eclipse.osgi.internal.module.ResolverBundle;
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.Version;
import org.osgi.service.framework.CompositeBundle;
import org.osgi.service.framework.SurrogateBundle;

public class SurrogateImpl
  extends CompositeBase
  implements SurrogateBundle
{
  private final CompositeBundle composite;
  
  public SurrogateImpl(BundleData bundledata, org.eclipse.osgi.framework.internal.core.Framework framework)
    throws BundleException
  {
    super(bundledata, framework);
    composite = ((CompositeBundle)FrameworkProperties.getProperties().get(PROP_COMPOSITE));
  }
  
  protected org.osgi.framework.launch.Framework findCompanionFramework(org.eclipse.osgi.framework.internal.core.Framework thisFramework, BundleData thisData)
  {
    return (org.osgi.framework.launch.Framework)FrameworkProperties.getProperties().get(PROP_PARENTFRAMEWORK);
  }
  
  public BundleContext getCompositeBundleContext()
  {
    return composite.getBundleContext();
  }
  
  protected Bundle getCompanionBundle()
  {
    return composite;
  }
  
  protected boolean isSurrogate()
  {
    return true;
  }
  
  public boolean giveExports(ExportPackageDescription[] matchingExports)
  {
    if (resolving.get() == null) {
      return false;
    }
    if (matchingExports == null)
    {
      CompositeHelper.setDisabled(true, getBundleDescription());
      return true;
    }
    return validExports(matchingExports);
  }
  
  private boolean validExports(ExportPackageDescription[] matchingExports)
  {
    CompositeModule composite = (CompositeModule)getCompanionBundle();
    BundleDescription childDesc = composite.getCompositeDescription();
    ExportPackageDescription[] childExports = childDesc.getExportPackages();
    for (int i = 0; i < matchingExports.length; i++) {
      for (int j = 0; j < childExports.length; j++) {
        if ((matchingExports[i].getName().equals(childExports[j].getName())) && 
          (!validateExport(matchingExports[i], childExports[j]))) {
          return false;
        }
      }
    }
    return true;
  }
  
  private boolean validateExport(ExportPackageDescription matchingExport, ExportPackageDescription childExport)
  {
    Version matchingVersion = matchingExport.getVersion();
    Version childVersion = childExport.getVersion();
    if ((!childVersion.equals(Version.emptyVersion)) && (!matchingVersion.equals(childVersion))) {
      return false;
    }
    if (!ResolverBundle.equivalentMaps(childExport.getAttributes(), matchingExport.getAttributes(), false)) {
      return false;
    }
    if (!ResolverBundle.equivalentMaps(childExport.getDirectives(), matchingExport.getDirectives(), false)) {
      return false;
    }
    return true;
  }
  
  protected void startHook()
  {
    ((CompositeModule)getCompanionBundle()).started(this);
  }
  
  protected void stopHook()
  {
    ((CompositeModule)getCompanionBundle()).stopped(this);
  }
  
  public void uninstall()
    throws BundleException
  {
    throw new BundleException("Cannot uninstall surrogate bundles", 2);
  }
}

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

import java.security.PrivilegedAction;

class BundleLoader$1
  implements PrivilegedAction<BundleLoader.ClassContext>
{
  public BundleLoader.ClassContext run()
  {
    return new BundleLoader.ClassContext();
  }
}

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

import java.security.PrivilegedAction;

class BundleLoader$2
  implements PrivilegedAction<ClassLoader>
{
  private final Class val$clazz;
  
  BundleLoader$2(Class paramClass) {}
  
  public ClassLoader run()
  {
    return val$clazz.getClassLoader();
  }
}

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

import java.security.PrivilegedAction;

class BundleLoader$3
  implements PrivilegedAction<String>
{
  final BundleLoader this$0;
  
  BundleLoader$3(BundleLoader paramBundleLoader, String paramString) {}
  
  public String run()
  {
    return this$0.findLocalLibrary(val$name);
  }
}

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

import java.security.PrivilegedAction;
import org.eclipse.osgi.framework.adaptor.BundleClassLoader;
import org.eclipse.osgi.framework.adaptor.BundleProtectionDomain;

class BundleLoader$4
  implements PrivilegedAction<BundleClassLoader>
{
  final BundleLoader this$0;
  
  BundleLoader$4(BundleLoader paramBundleLoader, BundleProtectionDomain paramBundleProtectionDomain, String[] paramArrayOfString) {}
  
  public BundleClassLoader run()
  {
    return this$0.createBCL(val$pd, val$cp);
  }
}

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

import java.security.PrivilegedAction;
import org.eclipse.osgi.framework.adaptor.BundleClassLoader;

class BundleLoader$5
  implements PrivilegedAction<ClassLoader>
{
  final BundleLoader this$0;
  
  BundleLoader$5(BundleLoader paramBundleLoader, BundleClassLoader paramBundleClassLoader) {}
  
  public ClassLoader run()
  {
    return val$bcl.getParent();
  }
}

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

final class BundleLoader$ClassContext
  extends SecurityManager
{
  public Class<?>[] getClassContext()
  {
    return super.getClassContext();
  }
}

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

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.eclipse.osgi.framework.adaptor.BundleClassLoader;
import org.eclipse.osgi.framework.adaptor.BundleData;
import org.eclipse.osgi.framework.adaptor.BundleProtectionDomain;
import org.eclipse.osgi.framework.adaptor.ClassLoaderDelegate;
import org.eclipse.osgi.framework.adaptor.ClassLoaderDelegateHook;
import org.eclipse.osgi.framework.adaptor.FrameworkAdaptor;
import org.eclipse.osgi.framework.adaptor.StatusException;
import org.eclipse.osgi.framework.debug.Debug;
import org.eclipse.osgi.framework.internal.core.AbstractBundle;
import org.eclipse.osgi.framework.internal.core.BundleFragment;
import org.eclipse.osgi.framework.internal.core.BundleHost;
import org.eclipse.osgi.framework.internal.core.Framework;
import org.eclipse.osgi.framework.internal.core.Msg;
import org.eclipse.osgi.framework.util.KeyedElement;
import org.eclipse.osgi.framework.util.KeyedHashSet;
import org.eclipse.osgi.framework.util.SecureAction;
import org.eclipse.osgi.internal.loader.buddy.PolicyHandler;
import org.eclipse.osgi.internal.resolver.StateBuilder;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.BundleSpecification;
import org.eclipse.osgi.service.resolver.ExportPackageDescription;
import org.eclipse.osgi.service.resolver.ImportPackageSpecification;
import org.eclipse.osgi.service.resolver.State;
import org.eclipse.osgi.util.ManifestElement;
import org.osgi.framework.BundleException;

public class BundleLoader
  implements ClassLoaderDelegate
{
  public static final String DEFAULT_PACKAGE = ".";
  public static final String JAVA_PACKAGE = "java.";
  public static final byte FLAG_IMPORTSINIT = 1;
  public static final byte FLAG_HASDYNAMICIMPORTS = 2;
  public static final byte FLAG_HASDYNAMICEIMPORTALL = 4;
  public static final byte FLAG_CLOSED = 8;
  public static final byte FLAG_LAZYTRIGGER = 16;
  public static final ClassContext CLASS_CONTEXT = (ClassContext)AccessController.doPrivileged(new PrivilegedAction()
  {
    public BundleLoader.ClassContext run()
    {
      return new BundleLoader.ClassContext();
    }
  });
  public static final ClassLoader FW_CLASSLOADER = getClassLoader(Framework.class);
  private static final int PRE_CLASS = 1;
  private static final int POST_CLASS = 2;
  private static final int PRE_RESOURCE = 3;
  private static final int POST_RESOURCE = 4;
  private static final int PRE_RESOURCES = 5;
  private static final int POST_RESOURCES = 6;
  private static final int PRE_LIBRARY = 7;
  private static final int POST_LIBRARY = 8;
  private static final boolean USE_GLOBAL_DEADLOCK_AVOIDANCE_LOCK = "true".equals(BundleLoaderProxy.secureAction.getProperty("osgi.classloader.singleThreadLoads"));
  private static final List<Object[]> waitingList = USE_GLOBAL_DEADLOCK_AVOIDANCE_LOCK ? new ArrayList(0) : null;
  private static Object lockThread;
  private static int lockCount = 0;
  private final BundleLoaderProxy proxy;
  final BundleHost bundle;
  private final PolicyHandler policy;
  private final Collection<String> exportedPackages;
  private final Collection<String> substitutedPackages;
  final BundleLoaderProxy[] requiredBundles;
  final int[] reexportTable;
  private final KeyedHashSet requiredSources;
  private KeyedHashSet importedSources;
  private String[] dynamicImportPackageStems;
  private String[] dynamicImportPackages;
  private byte loaderFlags = 0;
  private BundleClassLoader classloader;
  private ClassLoader parent;
  
  public static final String getPackageName(String name)
  {
    if (name != null)
    {
      int index = name.lastIndexOf('.');
      if (index > 0) {
        return name.substring(0, index);
      }
    }
    return ".";
  }
  
  public static final String getResourcePackageName(String name)
  {
    if (name != null)
    {
      int begin = (name.length() > 1) && (name.charAt(0) == '/') ? 1 : 0;
      int end = name.lastIndexOf('/');
      if (end > begin) {
        return name.substring(begin, end).replace('/', '.');
      }
    }
    return ".";
  }
  
  protected BundleLoader(BundleHost bundle, BundleLoaderProxy proxy)
    throws BundleException
  {
    this.bundle = bundle;
    this.proxy = proxy;
    try
    {
      bundle.getBundleData().open();
    }
    catch (IOException e)
    {
      throw new BundleException(Msg.BUNDLE_READ_EXCEPTION, e);
    }
    BundleDescription description = proxy.getBundleDescription();
    
    BundleDescription[] required = description.getResolvedRequires();
    if (required.length > 0)
    {
      Set<String> reExportSet = new HashSet(required.length);
      BundleSpecification[] requiredSpecs = description.getRequiredBundles();
      if ((requiredSpecs != null) && (requiredSpecs.length > 0)) {
        for (int i = 0; i < requiredSpecs.length; i++) {
          if (requiredSpecs[i].isExported()) {
            reExportSet.add(requiredSpecs[i].getName());
          }
        }
      }
      requiredBundles = new BundleLoaderProxy[required.length];
      int[] reexported = new int[required.length];
      int reexportIndex = 0;
      for (int i = 0; i < required.length; i++)
      {
        requiredBundles[i] = getLoaderProxy(required[i]);
        if (reExportSet.contains(required[i].getSymbolicName())) {
          reexported[(reexportIndex++)] = i;
        }
      }
      if (reexportIndex > 0)
      {
        reexportTable = new int[reexportIndex];
        System.arraycopy(reexported, 0, reexportTable, 0, reexportIndex);
      }
      else
      {
        reexportTable = null;
      }
      requiredSources = new KeyedHashSet(10, false);
    }
    else
    {
      requiredBundles = null;
      reexportTable = null;
      requiredSources = null;
    }
    ExportPackageDescription[] exports = description.getSelectedExports();
    if ((exports != null) && (exports.length > 0))
    {
      exportedPackages = Collections.synchronizedCollection(exports.length > 10 ? new HashSet(exports.length) : new ArrayList(exports.length));
      initializeExports(exports, exportedPackages);
    }
    else
    {
      exportedPackages = Collections.synchronizedCollection(new ArrayList(0));
    }
    ExportPackageDescription[] substituted = description.getSubstitutedExports();
    if (substituted.length > 0)
    {
      substitutedPackages = (substituted.length > 10 ? new HashSet(substituted.length) : new ArrayList(substituted.length));
      for (int i = 0; i < substituted.length; i++) {
        substitutedPackages.add(substituted[i].getName());
      }
    }
    else
    {
      substitutedPackages = null;
    }
    BundleFragment[] fragmentObjects = bundle.getFragments();
    BundleDescription[] fragments = new BundleDescription[fragmentObjects == null ? 0 : fragmentObjects.length];
    for (int i = 0; i < fragments.length; i++) {
      fragments[i] = fragmentObjects[i].getBundleDescription();
    }
    if (description.hasDynamicImports()) {
      addDynamicImportPackage(description.getImportPackages());
    }
    for (int i = 0; i < fragments.length; i++) {
      if ((fragments[i].isResolved()) && (fragments[i].hasDynamicImports())) {
        addDynamicImportPackage(fragments[i].getImportPackages());
      }
    }
    String buddyList = null;
    try
    {
      buddyList = (String)bundle.getBundleData().getManifest().get("Eclipse-BuddyPolicy");
    }
    catch (BundleException localBundleException) {}
    policy = (buddyList != null ? new PolicyHandler(this, buddyList, bundle.getFramework().getPackageAdmin()) : null);
    if (policy != null) {
      policy.open(bundle.getFramework().getSystemBundleContext());
    }
  }
  
  private void initializeExports(ExportPackageDescription[] exports, Collection<String> exportNames)
  {
    for (int i = 0; i < exports.length; i++)
    {
      if ((proxy.forceSourceCreation(exports[i])) && 
        (!exportNames.contains(exports[i].getName()))) {
        proxy.createPackageSource(exports[i], true);
      }
      exportNames.add(exports[i].getName());
    }
  }
  
  public synchronized KeyedHashSet getImportedSources(KeyedHashSet visited)
  {
    if ((loaderFlags & 0x1) != 0) {
      return importedSources;
    }
    BundleDescription bundleDesc = proxy.getBundleDescription();
    ExportPackageDescription[] packages = bundleDesc.getResolvedImports();
    if ((packages != null) && (packages.length > 0))
    {
      if (importedSources == null) {
        importedSources = new KeyedHashSet(packages.length, false);
      }
      for (int i = 0; i < packages.length; i++) {
        if (packages[i].getExporter() != bundleDesc)
        {
          PackageSource source = createExportPackageSource(packages[i], visited);
          if (source != null) {
            importedSources.add(source);
          }
        }
      }
    }
    loaderFlags = ((byte)(loaderFlags | 0x1));
    return importedSources;
  }
  
  public synchronized boolean isLazyTriggerSet()
  {
    return (loaderFlags & 0x10) != 0;
  }
  
  public void setLazyTrigger()
    throws BundleException
  {
    synchronized (this)
    {
      loaderFlags = ((byte)(loaderFlags | 0x10));
    }
    BundleLoaderProxy.secureAction.start(bundle, 1073741825);
  }
  
  final PackageSource createExportPackageSource(ExportPackageDescription export, KeyedHashSet visited)
  {
    BundleLoaderProxy exportProxy = getLoaderProxy(export.getExporter());
    if (exportProxy == null) {
      return null;
    }
    PackageSource requiredSource = exportProxy.getBundleLoader().findRequiredSource(export.getName(), visited);
    PackageSource exportSource = exportProxy.createPackageSource(export, false);
    if (requiredSource == null) {
      return exportSource;
    }
    return createMultiSource(export.getName(), new PackageSource[] { requiredSource, exportSource });
  }
  
  private static PackageSource createMultiSource(String packageName, PackageSource[] sources)
  {
    if (sources.length == 1) {
      return sources[0];
    }
    List<SingleSourcePackage> sourceList = new ArrayList(sources.length);
    for (int i = 0; i < sources.length; i++)
    {
      SingleSourcePackage[] innerSources = sources[i].getSuppliers();
      for (int j = 0; j < innerSources.length; j++) {
        if (!sourceList.contains(innerSources[j])) {
          sourceList.add(innerSources[j]);
        }
      }
    }
    return new MultiSourcePackage(packageName, (SingleSourcePackage[])sourceList.toArray(new SingleSourcePackage[sourceList.size()]));
  }
  
  public final BundleLoaderProxy getLoaderProxy(BundleDescription source)
  {
    Object userObject = source.getUserObject();
    if (!(userObject instanceof BundleLoaderProxy))
    {
      long exportingID = source.getBundleId();
      BundleHost exportingBundle = (BundleHost)bundle.getFramework().getBundle(exportingID);
      if (exportingBundle == null) {
        return null;
      }
      userObject = exportingBundle.getLoaderProxy();
    }
    return (BundleLoaderProxy)userObject;
  }
  
  public BundleLoaderProxy getLoaderProxy()
  {
    return proxy;
  }
  
  synchronized void close()
  {
    if ((loaderFlags & 0x8) != 0) {
      return;
    }
    if (classloader != null) {
      classloader.close();
    }
    if (policy != null) {
      policy.close(bundle.getFramework().getSystemBundleContext());
    }
    loaderFlags = ((byte)(loaderFlags | 0x8));
  }
  
  public final Class<?> loadClass(String name)
    throws ClassNotFoundException
  {
    BundleClassLoader bcl = createClassLoader();
    if ((name.length() > 0) && (name.charAt(0) == '[') && ((bcl instanceof ClassLoader))) {
      return Class.forName(name, false, (ClassLoader)bcl);
    }
    return bcl.loadClass(name);
  }
  
  final URL getResource(String name)
  {
    return createClassLoader().getResource(name);
  }
  
  public final synchronized ClassLoader getParentClassLoader()
  {
    if (parent != null) {
      return parent;
    }
    createClassLoader();
    return parent;
  }
  
  public final synchronized BundleClassLoader createClassLoader()
  {
    if (classloader != null) {
      return classloader;
    }
    String[] classpath;
    try
    {
      classpath = bundle.getBundleData().getClassPath();
    }
    catch (BundleException e)
    {
      String[] classpath;
      classpath = new String[0];
      bundle.getFramework().publishFrameworkEvent(2, bundle, e);
    }
    if (classpath == null)
    {
      classpath = new String[0];
      bundle.getFramework().publishFrameworkEvent(2, bundle, new BundleException(Msg.BUNDLE_NO_CLASSPATH_MATCH, 3));
    }
    BundleClassLoader bcl = createBCLPrevileged(bundle.getProtectionDomain(), classpath);
    parent = getParentPrivileged(bcl);
    classloader = bcl;
    return classloader;
  }
  
  Class<?> findLocalClass(String name)
    throws ClassNotFoundException
  {
    if (Debug.DEBUG_LOADER) {
      Debug.println("BundleLoader[" + this + "].findLocalClass(" + name + ")");
    }
    try
    {
      Class<?> clazz = createClassLoader().findLocalClass(name);
      if ((Debug.DEBUG_LOADER) && (clazz != null)) {
        Debug.println("BundleLoader[" + this + "] found local class " + name);
      }
      return clazz;
    }
    catch (ClassNotFoundException e)
    {
      if (((e instanceof StatusException)) && 
        ((((StatusException)e).getStatusCode() & 0x8) != 0)) {
        throw e;
      }
    }
    return null;
  }
  
  public Class<?> findClass(String name)
    throws ClassNotFoundException
  {
    return findClass(name, true);
  }
  
  Class<?> findClass(String name, boolean checkParent)
    throws ClassNotFoundException
  {
    ClassLoader parentCL = getParentClassLoader();
    if ((checkParent) && (parentCL != null) && (name.startsWith("java."))) {
      return parentCL.loadClass(name);
    }
    try
    {
      if (USE_GLOBAL_DEADLOCK_AVOIDANCE_LOCK) {
        lock(createClassLoader());
      }
      return findClassInternal(name, checkParent, parentCL);
    }
    finally
    {
      if (USE_GLOBAL_DEADLOCK_AVOIDANCE_LOCK) {
        unlock();
      }
    }
  }
  
  private Class<?> findClassInternal(String name, boolean checkParent, ClassLoader parentCL)
    throws ClassNotFoundException
  {
    if (Debug.DEBUG_LOADER) {
      Debug.println("BundleLoader[" + this + "].loadBundleClass(" + name + ")");
    }
    String pkgName = getPackageName(name);
    boolean bootDelegation = false;
    if ((checkParent) && (parentCL != null) && (bundle.getFramework().isBootDelegationPackage(pkgName))) {
      try
      {
        return parentCL.loadClass(name);
      }
      catch (ClassNotFoundException localClassNotFoundException1)
      {
        bootDelegation = true;
      }
    }
    Class<?> result = null;
    try
    {
      result = (Class)searchHooks(name, 1);
    }
    catch (ClassNotFoundException e)
    {
      throw e;
    }
    catch (FileNotFoundException localFileNotFoundException1) {}
    if (result != null) {
      return result;
    }
    PackageSource source = findImportedSource(pkgName, null);
    if (source != null)
    {
      result = source.loadClass(name);
      if (result != null) {
        return result;
      }
      throw new ClassNotFoundException(name);
    }
    source = findRequiredSource(pkgName, null);
    if (source != null) {
      result = source.loadClass(name);
    }
    if (result == null) {
      result = findLocalClass(name);
    }
    if (result != null) {
      return result;
    }
    if (source == null)
    {
      source = findDynamicSource(pkgName);
      if (source != null)
      {
        result = source.loadClass(name);
        if (result != null) {
          return result;
        }
        throw new ClassNotFoundException(name);
      }
    }
    if (result == null) {
      try
      {
        result = (Class)searchHooks(name, 2);
      }
      catch (ClassNotFoundException e)
      {
        throw e;
      }
      catch (FileNotFoundException localFileNotFoundException2) {}
    }
    if ((result == null) && (policy != null)) {
      result = policy.doBuddyClassLoading(name);
    }
    if (result != null) {
      return result;
    }
    if ((parentCL != null) && (!bootDelegation) && (((checkParent) && (bundle.getFramework().compatibiltyBootDelegation)) || (isRequestFromVM()))) {
      try
      {
        return parentCL.loadClass(name);
      }
      catch (ClassNotFoundException localClassNotFoundException2) {}
    }
    throw new ClassNotFoundException(name);
  }
  
  private <E> E searchHooks(String name, int type)
    throws ClassNotFoundException, FileNotFoundException
  {
    ClassLoaderDelegateHook[] delegateHooks = bundle.getFramework().getDelegateHooks();
    if (delegateHooks == null) {
      return null;
    }
    E result = null;
    for (int i = 0; (i < delegateHooks.length) && (result == null); i++) {
      switch (type)
      {
      case 1: 
        result = delegateHooks[i].preFindClass(name, createClassLoader(), bundle.getBundleData());
        break;
      case 2: 
        result = delegateHooks[i].postFindClass(name, createClassLoader(), bundle.getBundleData());
        break;
      case 3: 
        result = delegateHooks[i].preFindResource(name, createClassLoader(), bundle.getBundleData());
        break;
      case 4: 
        result = delegateHooks[i].postFindResource(name, createClassLoader(), bundle.getBundleData());
        break;
      case 5: 
        result = delegateHooks[i].preFindResources(name, createClassLoader(), bundle.getBundleData());
        break;
      case 6: 
        result = delegateHooks[i].postFindResources(name, createClassLoader(), bundle.getBundleData());
        break;
      case 7: 
        result = delegateHooks[i].preFindLibrary(name, createClassLoader(), bundle.getBundleData());
        break;
      case 8: 
        result = delegateHooks[i].postFindLibrary(name, createClassLoader(), bundle.getBundleData());
      }
    }
    return result;
  }
  
  private boolean isRequestFromVM()
  {
    if ((bundle.getFramework().isBootDelegationPackage("*")) || (!bundle.getFramework().contextBootDelegation)) {
      return false;
    }
    Class[] context = CLASS_CONTEXT.getClassContext();
    if ((context == null) || (context.length < 2)) {
      return false;
    }
    for (int i = 1; i < context.length; i++) {
      if ((context[i] != BundleLoader.class) && (!ClassLoader.class.isAssignableFrom(context[i])))
      {
        ClassLoader cl = getClassLoader(context[i]);
        if (cl != FW_CLASSLOADER)
        {
          if ((Class.class == context[i]) || ((cl instanceof BundleClassLoader))) {
            break;
          }
          return true;
        }
      }
    }
    return false;
  }
  
  private static ClassLoader getClassLoader(Class<?> clazz)
  {
    if (System.getSecurityManager() == null) {
      return clazz.getClassLoader();
    }
    (ClassLoader)AccessController.doPrivileged(new PrivilegedAction()
    {
      public ClassLoader run()
      {
        return getClassLoader();
      }
    });
  }
  
  public URL findResource(String name)
  {
    return findResource(name, true);
  }
  
  URL findResource(String name, boolean checkParent)
  {
    if ((name.length() > 1) && (name.charAt(0) == '/')) {
      name = name.substring(1);
    }
    String pkgName = getResourcePackageName(name);
    boolean bootDelegation = false;
    ClassLoader parentCL = getParentClassLoader();
    if ((checkParent) && (parentCL != null))
    {
      if (pkgName.startsWith("java.")) {
        return parentCL.getResource(name);
      }
      if (bundle.getFramework().isBootDelegationPackage(pkgName))
      {
        URL result = parentCL.getResource(name);
        if (result != null) {
          return result;
        }
        bootDelegation = true;
      }
    }
    URL result = null;
    try
    {
      result = (URL)searchHooks(name, 3);
    }
    catch (FileNotFoundException localFileNotFoundException1)
    {
      return null;
    }
    catch (ClassNotFoundException localClassNotFoundException1) {}
    if (result != null) {
      return result;
    }
    PackageSource source = findImportedSource(pkgName, null);
    if (source != null) {
      return source.getResource(name);
    }
    source = findRequiredSource(pkgName, null);
    if (source != null) {
      result = source.getResource(name);
    }
    if (result == null) {
      result = findLocalResource(name);
    }
    if (result != null) {
      return result;
    }
    if (source == null)
    {
      source = findDynamicSource(pkgName);
      if (source != null) {
        return source.getResource(name);
      }
    }
    if (result == null) {
      try
      {
        result = (URL)searchHooks(name, 4);
      }
      catch (FileNotFoundException localFileNotFoundException2)
      {
        return null;
      }
      catch (ClassNotFoundException localClassNotFoundException2) {}
    }
    if ((result == null) && (policy != null)) {
      result = policy.doBuddyResourceLoading(name);
    }
    if (result != null) {
      return result;
    }
    if ((parentCL != null) && (!bootDelegation) && (((checkParent) && (bundle.getFramework().compatibiltyBootDelegation)) || (isRequestFromVM()))) {
      return parentCL.getResource(name);
    }
    return result;
  }
  
  public Enumeration<URL> findResources(String name)
    throws IOException
  {
    if ((name.length() > 1) && (name.charAt(0) == '/')) {
      name = name.substring(1);
    }
    String pkgName = getResourcePackageName(name);
    Enumeration<URL> result = null;
    try
    {
      result = (Enumeration)searchHooks(name, 5);
    }
    catch (ClassNotFoundException localClassNotFoundException1) {}catch (FileNotFoundException localFileNotFoundException1)
    {
      return null;
    }
    if (result != null) {
      return result;
    }
    PackageSource source = findImportedSource(pkgName, null);
    if (source != null) {
      return source.getResources(name);
    }
    source = findRequiredSource(pkgName, null);
    if (source != null) {
      result = source.getResources(name);
    }
    Enumeration<URL> localResults = findLocalResources(name);
    result = compoundEnumerations(result, localResults);
    if ((result == null) && (source == null))
    {
      source = findDynamicSource(pkgName);
      if (source != null) {
        return source.getResources(name);
      }
    }
    if (result == null) {
      try
      {
        result = (Enumeration)searchHooks(name, 6);
      }
      catch (ClassNotFoundException localClassNotFoundException2) {}catch (FileNotFoundException localFileNotFoundException2)
      {
        return null;
      }
    }
    if (policy != null)
    {
      Enumeration<URL> buddyResult = policy.doBuddyResourcesLoading(name);
      result = compoundEnumerations(result, buddyResult);
    }
    return result;
  }
  
  private boolean isSubPackage(String parentPackage, String subPackage)
  {
    String prefix = parentPackage + '.';
    return subPackage.startsWith(prefix);
  }
  
  public Collection<String> listResources(String path, String filePattern, int options)
  {
    String pkgName = getResourcePackageName(path + '/');
  
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-2017. Infinite Loop Ltd