org.eclipse.osgi_3.8.2.v20130124-134944

er parentCL = getParentClassLoader();
    if ((checkParent) && (parentCL != null) && (name.startsWith("java."))) {
      return parentCL.loadClass(name);
    }
    return findClassInternal(name, checkParent, parentCL);
  }
  
  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])) && (!context[i].getName().equals("java.lang.J9VMInternals")))
      {
        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 + '/');
    if ((path.length() > 1) && (path.charAt(0) == '/')) {
      path = path.substring(1);
    }
    boolean subPackages = (options & 0x1) != 0;
    List<String> packages = new ArrayList();
    
    KeyedHashSet importSources = getImportedSources(null);
    int j;
    int i;
    if (importSources != null)
    {
      KeyedElement[] imports = importSources.elements();
      j = (localObject1 = imports).length;
      for (i = 0; i < j; i++)
      {
        KeyedElement keyedElement = localObject1[i];
        String id = ((PackageSource)keyedElement).getId();
        if ((id.equals(pkgName)) || ((subPackages) && (isSubPackage(pkgName, id)))) {
          packages.add(id);
        }
      }
    }
    if (requiredBundles != null)
    {
      KeyedHashSet visited = new KeyedHashSet(false);
      visited.add(bundle);
      j = (localObject1 = requiredBundles).length;
      for (i = 0; i < j; i++)
      {
        BundleLoaderProxy requiredProxy = localObject1[i];
        BundleLoader requiredLoader = requiredProxy.getBundleLoader();
        requiredLoader.addProvidedPackageNames(requiredProxy.getSymbolicName(), pkgName, packages, subPackages, visited);
      }
    }
    boolean localSearch = (options & 0x2) != 0;
    List<String> result = new ArrayList();
    Object importedPackages = new HashSet(0);
    Iterator localIterator;
    label444:
    for (Object localObject1 = packages.iterator(); ((Iterator)localObject1).hasNext(); localIterator.hasNext())
    {
      String name = (String)((Iterator)localObject1).next();
      
      externalSource = findImportedSource(name, null);
      if (externalSource != null) {
        ((Set)importedPackages).add(name);
      } else {
        externalSource = findRequiredSource(name, null);
      }
      if ((externalSource == null) || (localSearch)) {
        break label444;
      }
      String packagePath = name.replace('.', '/');
      Collection<String> externalResources = externalSource.listResources(packagePath, filePattern);
      localIterator = externalResources.iterator(); continue;String resource = (String)localIterator.next();
      if (!result.contains(resource)) {
        result.add(resource);
      }
    }
    Object localResources = createClassLoader().listLocalResources(path, filePattern, options);
    for (PackageSource externalSource = ((Collection)localResources).iterator(); externalSource.hasNext();)
    {
      String resource = (String)externalSource.next();
      String resourcePkg = getResourcePackageName(resource);
      if ((!((Set)importedPackages).contains(resourcePkg)) && (!result.contains(resource))) {
        result.add(resource);
      }
    }
    return result;
  }
  
  public Enumeration<URL> getResources(String name)
    throws IOException
  {
    if ((name.length() > 1) && (name.charAt(0) == '/')) {
      name = name.substring(1);
    }
    String pkgName = getResourcePackageName(name);
    
    Enumeration<URL> result = null;
    if ((pkgName.startsWith("java.")) || (bundle.getFramework().isBootDelegationPackage(pkgName)))
    {
      ClassLoader parentCL = getParentClassLoader();
      result = parentCL == null ? null : parentCL.getResources(name);
      if (pkgName.startsWith("java.")) {
        return result;
      }
    }
    return compoundEnumerations(result, findResources(name));
  }
  
  public static <E> Enumeration<E> compoundEnumerations(Enumeration<E> list1, Enumeration<E> list2)
  {
    if ((list2 == null) || (!list2.hasMoreElements())) {
      return list1;
    }
    if ((list1 == null) || (!list1.hasMoreElements())) {
      return list2;
    }
    List<E> compoundResults = new ArrayList();
    while (list1.hasMoreElements()) {
      compoundResults.add(list1.nextElement());
    }
    while (list2.hasMoreElements())
    {
      E item = list2.nextElement();
      if (!compoundResults.contains(item)) {
        compoundResults.add(item);
      }
    }
    return Collections.enumeration(compoundResults);
  }
  
  URL findLocalResource(String name)
  {
    return createClassLoader().findLocalResource(name);
  }
  
  Enumeration<URL> findLocalResources(String name)
  {
    return createClassLoader().findLocalResources(name);
  }
  
  public String findLibrary(final String name)
  {
    if (System.getSecurityManager() == null) {
      return findLocalLibrary(name);
    }
    (String)AccessController.doPrivileged(new PrivilegedAction()
    {
      public String run()
      {
        return findLocalLibrary(name);
      }
    });
  }
  
  final String findLocalLibrary(String name)
  {
    String result = null;
    try
    {
      result = (String)searchHooks(name, 7);
    }
    catch (FileNotFoundException localFileNotFoundException1)
    {
      return null;
    }
    catch (ClassNotFoundException localClassNotFoundException1) {}
    if (result != null) {
      return result;
    }
    result = bundle.getBundleData().findLibrary(name);
    if (result != null) {
      return result;
    }
    BundleFragment[] fragments = bundle.getFragments();
    if (fragments != null) {
      for (int i = 0; i < fragments.length; i++)
      {
        result = fragments[i].getBundleData().findLibrary(name);
        if (result != null) {
          return result;
        }
      }
    }
    try
    {
      return (String)searchHooks(name, 8);
    }
    catch (FileNotFoundException localFileNotFoundException2)
    {
      return null;
    }
    catch (ClassNotFoundException localClassNotFoundException2) {}
    return null;
  }
  
  public final AbstractBundle getBundle()
  {
    return bundle;
  }
  
  private BundleClassLoader createBCLPrevileged(final BundleProtectionDomain pd, final String[] cp)
  {
    if (System.getSecurityManager() == null) {
      return createBCL(pd, cp);
    }
    (BundleClassLoader)AccessController.doPrivileged(new PrivilegedAction()
    {
      public BundleClassLoader run()
      {
        return createBCL(pd, cp);
      }
    });
  }
  
  BundleClassLoader createBCL(BundleProtectionDomain pd, String[] cp)
  {
    BundleClassLoader bcl = bundle.getBundleData().createClassLoader(this, pd, cp);
    
    BundleFragment[] fragments = bundle.getFragments();
    if (fragments != null) {
      for (int i = 0; i < fragments.length; i++) {
        try
        {
          bcl.attachFragment(fragments[i].getBundleData(), fragments[i].getProtectionDomain(), fragments[i].getBundleData().getClassPath());
        }
        catch (BundleException be)
        {
          bundle.getFramework().publishFrameworkEvent(2, bundle, be);
        }
      }
    }
    bcl.initialize();
    return bcl;
  }
  
  public final String toString()
  {
    BundleData result = bundle.getBundleData();
    return result == null ? "BundleLoader.bundledata == null!" : result.toString();
  }
  
  private final synchronized boolean isDynamicallyImported(String pkgname)
  {
    if ((this instanceof SystemBundleLoader)) {
      return false;
    }
    if (pkgname.startsWith("java.")) {
      return true;
    }
    if ((loaderFlags & 0x2) == 0) {
      return false;
    }
    if ((loaderFlags & 0x4) != 0) {
      return true;
    }
    if (dynamicImportPackages != null) {
      for (int i = 0; i < dynamicImportPackages.length; i++) {
        if (pkgname.equals(dynamicImportPackages[i])) {
          return true;
        }
      }
    }
    if (dynamicImportPackageStems != null) {
      for (int i = 0; i < dynamicImportPackageStems.length; i++) {
        if (pkgname.startsWith(dynamicImportPackageStems[i])) {
          return true;
        }
      }
    }
    return false;
  }
  
  final void addExportedProvidersFor(String symbolicName, String packageName, List<PackageSource> result, KeyedHashSet visited)
  {
    if (!visited.add(bundle)) {
      return;
    }
    PackageSource local = null;
    if (isExportedPackage(packageName))
    {
      local = proxy.getPackageSource(packageName);
    }
    else if (isSubstitutedExport(packageName))
    {
      result.add(findImportedSource(packageName, visited));
      return;
    }
    if (requiredBundles != null)
    {
      int size = reexportTable == null ? 0 : reexportTable.length;
      int reexportIndex = 0;
      for (int i = 0; i < requiredBundles.length; i++) {
        if (local != null)
        {
          requiredBundles[i].getBundleLoader().addExportedProvidersFor(symbolicName, packageName, result, visited);
        }
        else if ((reexportIndex < size) && (reexportTable[reexportIndex] == i))
        {
          reexportIndex++;
          requiredBundles[i].getBundleLoader().addExportedProvidersFor(symbolicName, packageName, result, visited);
        }
      }
    }
    if ((local != null) && (local.isFriend(symbolicName))) {
      result.add(local);
    }
  }
  
  final void addProvidedPackageNames(String symbolicName, String packageName, List<String> result, boolean subPackages, KeyedHashSet visitied)
  {
    if (!visitied.add(bundle)) {
      return;
    }
    for (Iterator localIterator = exportedPackages.iterator(); localIterator.hasNext();)
    {
      String exported = (String)localIterator.next();
      if (((exported.equals(packageName)) || ((subPackages) && (isSubPackage(packageName, exported)))) && 
        (!result.contains(exported))) {
        result.add(exported);
      }
    }
    if (substitutedPackages != null) {
      for (localIterator = substitutedPackages.iterator(); localIterator.hasNext();)
      {
        String substituted = (String)localIterator.next();
        if (((substituted.equals(packageName)) || ((subPackages) && (isSubPackage(packageName, substituted)))) && 
          (!result.contains(substituted))) {
          result.add(substituted);
        }
      }
    }
    if (requiredBundles != null)
    {
      int size = reexportTable == null ? 0 : reexportTable.length;
      int reexportIndex = 0;
      for (int i = 0; i < requiredBundles.length; i++) {
        if ((reexportIndex < size) && (reexportTable[reexportIndex] == i))
        {
          reexportIndex++;
          requiredBundles[i].getBundleLoader().addProvidedPackageNames(symbolicName, packageName, result, subPackages, visitied);
        }
      }
    }
  }
  
  final boolean isExportedPackage(String name)
  {
    return exportedPackages.contains(name);
  }
  
  final boolean isSubstitutedExport(String name)
  {
    return substitutedPackages == null ? false : substitutedPackages.contains(name);
  }
  
  private void addDynamicImportPackage(ImportPackageSpecification[] packages)
  {
    if (packages == null) {
      return;
    }
    List<String> dynamicImports = new ArrayList(packages.length);
    for (int i = 0; i < packages.length; i++) {
      if ("dynamic".equals(packages[i].getDirective("resolution"))) {
        dynamicImports.add(packages[i].getName());
      }
    }
    if (dynamicImports.size() > 0) {
      addDynamicImportPackage((String[])dynamicImports.toArray(new String[dynamicImports.size()]));
    }
  }
  
  private void addDynamicImportPackage(String[] packages)
  {
    if (packages == null) {
      return;
    }
    loaderFlags = ((byte)(loaderFlags | 0x2));
    int size = packages.length;
    List<String> stems;
    List<String> stems;
    if (dynamicImportPackageStems == null)
    {
      stems = new ArrayList(size);
    }
    else
    {
      stems = new ArrayList(size + dynamicImportPackageStems.length);
      for (int i = 0; i < dynamicImportPackageStems.length; i++) {
        stems.add(dynamicImportPackageStems[i]);
      }
    }
    List<String> names;
    List<String> names;
    if (dynamicImportPackages == null)
    {
      names = new ArrayList(size);
    }
    else
    {
      names = new ArrayList(size + dynamicImportPackages.length);
      for (int i = 0; i < dynamicImportPackages.length; i++) {
        names.add(dynamicImportPackages[i]);
      }
    }
    for (int i = 0; i < size; i++)
    {
      String name = packages[i];
      if (!isDynamicallyImported(name))
      {
        if (name.equals("*"))
        {
          loaderFlags = ((byte)(loaderFlags | 0x4));
          return;
        }
        if (name.endsWith(".*")) {
          stems.add(name.substring(0, name.length() - 1));
        } else {
          names.add(name);
        }
      }
    }
    size = stems.size();
    if (size > 0) {
      dynamicImportPackageStems = ((String[])stems.toArray(new String[size]));
    }
    size = names.size();
    if (size > 0) {
      dynamicImportPackages = ((String[])names.toArray(new String[size]));
    }
  }
  
  public final synchronized void addDynamicImportPackage(ManifestElement[] packages)
  {
    if (packages == null) {
      return;
    }
    List<String> dynamicImports = new ArrayList(packages.length);
    List<ImportPackageSpecification> dynamicImportSpecs = new ArrayList(packages.length);
    ManifestElement[] arrayOfManifestElement;
    int j = (arrayOfManifestElement = packages).length;
    for (int i = 0; i < j; i++)
    {
      ManifestElement dynamicImportElement = arrayOfManifestElement[i];
      String[] names = dynamicImportElement.getValueComponents();
      String[] arrayOfString1;
      int m = (arrayOfString1 = names).length;
      for (int k = 0; k < m; k++)
      {
        String name = arrayOfString1[k];
        dynamicImports.add(name);
      }
      StateBuilder.addImportPackages(dynamicImportElement, dynamicImportSpecs, 2, true);
    }
    if (dynamicImports.size() > 0)
    {
      addDynamicImportPackage((String[])dynamicImports.toArray(new String[dynamicImports.size()]));
      BundleDescription revision = getLoaderProxy().getBundleDescription();
      State state = revision.getContainingState();
      state.addDynamicImportPackages(revision, (ImportPackageSpecification[])dynamicImportSpecs.toArray(new ImportPackageSpecification[dynamicImportSpecs.size()]));
    }
  }
  
  public synchronized void attachFragment(BundleFragment fragment)
    throws BundleException
  {
    ExportPackageDescription[] exports = proxy.getBundleDescription().getSelectedExports();
    if (classloader == null)
    {
      initializeExports(exports, exportedPackages);
      return;
    }
    String[] classpath = fragment.getBundleData().getClassPath();
    if (classpath != null) {
      classloader.attachFragment(fragment.getBundleData(), fragment.getProtectionDomain(), classpath);
    }
    initializeExports(exports, exportedPackages);
  }
  
  private PackageSource findSource(String pkgName)
  {
    if (pkgName == null) {
      return null;
    }
    PackageSource result = findImportedSource(pkgName, null);
    if (result != null) {
      return result;
    }
    return findRequiredSource(pkgName, null);
  }
  
  /* Error */
  private PackageSource findImportedSource(String pkgName, KeyedHashSet visited)
  {
    // Byte code:
    //   0: aload_0
    //   1: aload_2
    //   2: invokevirtual 930	org/eclipse/osgi/internal/loader/BundleLoader:getImportedSources	(Lorg/eclipse/osgi/framework/util/KeyedHashSet;)Lorg/eclipse/osgi/framework/util/KeyedHashSet;
    //   5: astore_3
    //   6: aload_3
    //   7: ifnonnull +5 -> 12
    //   10: aconst_null
    //   11: areturn
    //   12: aload_3
    //   13: dup
    //   14: astore 4
    //   16: monitorenter
    //   17: aload_3
    //   18: aload_1
    //   19: invokevirtual 904	org/eclipse/osgi/framework/util/KeyedHashSet:getByKey	(Ljava/lang/Object;)Lorg/eclipse/osgi/framework/util/KeyedElement;
    //   22: checkcast 460	org/eclipse/osgi/internal/loader/PackageSource
    //   25: aload 4
    //   27: monitorexit
    //   28: areturn
    //   29: aload 4
    //   31: monitorexit
    //   32: athrow
    // Line number table:
    //   Java source line #1157	-> byte code offset #0
    //   Java source line #1158	-> byte code offset #6
    //   Java source line #1159	-> byte code offset #10
    //   Java source line #1160	-> byte code offset #12
    //   Java source line #1161	-> byte code offset #17
    //   Java source line #1160	-> byte code offset #29
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	33	0	this	BundleLoader
    //   0	33	1	pkgName	String
    //   0	33	2	visited	KeyedHashSet
    //   5	13	3	imports	KeyedHashSet
    //   14	16	4	Ljava/lang/Object;	Object
    // Exception table:
    //   from	to	target	type
    //   17	28	29	finally
    //   29	32	29	finally
  }
  
  private PackageSource findDynamicSource(String pkgName)
  {
    if (isDynamicallyImported(pkgName))
    {
      ExportPackageDescription exportPackage = bundle.getFramework().getAdaptor().getState().linkDynamicImport(proxy.getBundleDescription(), pkgName);
      if (exportPackage != null)
      {
        PackageSource source = createExportPackageSource(exportPackage, null);
        synchronized (this)
        {
          if (importedSources == null) {
            importedSources = new KeyedHashSet(false);
          }
        }
        synchronized (importedSources)
        {
          importedSources.add(source);
        }
        return source;
      }
    }
    return null;
  }
  
  private PackageSource findRequiredSource(String pkgName, KeyedHashSet visited)
  {
    if (requiredBundles == null) {
      return null;
    }
    synchronized (requiredSources)
    {
      PackageSource result = (PackageSource)requiredSources.getByKey(pkgName);
      if (result != null) {
        return result.isNullSource() ? null : result;
      }
    }
    if (visited == null) {
      visited = new KeyedHashSet(false);
    }
    visited.add(bundle);
    List<PackageSource> result = new ArrayList(3);
    for (int i = 0; i < requiredBundles.length; i++)
    {
      BundleLoader requiredLoader = requiredBundles[i].getBundleLoader();
      requiredLoader.addExportedProvidersFor(proxy.getSymbolicName(), pkgName, result, visited);
    }
    PackageSource source;
    PackageSource source;
    if (result.size() == 0)
    {
      source = NullPackageSource.getNullPackageSource(pkgName);
    }
    else
    {
      PackageSource source;
      if (result.size() == 1)
      {
        source = (PackageSource)result.get(0);
      }
      else
      {
        PackageSource[] srcs = (PackageSource[])result.toArray(new PackageSource[result.size()]);
        source = createMultiSource(pkgName, srcs);
      }
    }
    synchronized (requiredSources)
    {
      requiredSources.add(source);
    }
    return source.isNullSource() ? null : source;
  }
  
  public final PackageSource getPackageSource(String pkgName)
  {
    PackageSource result = findSource(pkgName);
    if (!isExportedPackage(pkgName)) {
      return result;
    }
    PackageSource localSource = proxy.getPackageSource(pkgName);
    if (result == null) {
      return localSource;
    }
    if (localSource == null) {
      return result;
    }
    return createMultiSource(pkgName, new PackageSource[] { result, localSource });
  }
  
  private ClassLoader getParentPrivileged(final BundleClassLoader bcl)
  {
    if (System.getSecurityManager() == null) {
      return bcl.getParent();
    }
    (ClassLoader)AccessController.doPrivileged(new PrivilegedAction()
    {
      public ClassLoader run()
      {
        return bcl.getParent();
      }
    });
  }
  
  static final class ClassContext
    extends SecurityManager
  {
    public Class<?>[] getClassContext()
    {
      return super.getClassContext();
    }
  }
  
  public static void closeBundleLoader(BundleLoaderProxy proxy)
  {
    if (proxy == null) {
      return;
    }
    BundleLoader loader = proxy.getBasicBundleLoader();
    if (loader != null) {
      loader.close();
    }
    proxy.setStale();
    
    BundleDescription description = proxy.getBundleDescription();
    
    description.setUserObject(proxy.getBundleData());
  }
}

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

import java.security.PrivilegedAction;

class BundleLoaderProxy$1
  implements PrivilegedAction<BundleLoader>
{
  final BundleLoaderProxy this$0;
  
  BundleLoaderProxy$1(BundleLoaderProxy paramBundleLoaderProxy) {}
  
  public BundleLoader run()
  {
    return this$0.getBundleLoader0();
  }
}

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

import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.osgi.framework.adaptor.BundleData;
import org.eclipse.osgi.framework.internal.core.AbstractBundle;
import org.eclipse.osgi.framework.internal.core.BundleHost;
import org.eclipse.osgi.framework.internal.core.Framework;
import org.eclipse.osgi.framework.util.KeyedHashSet;
import org.eclipse.osgi.framework.util.SecureAction;
import org.eclipse.osgi.internal.composite.CompositeBase;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.ExportPackageDescription;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.framework.BundleReference;
import org.osgi.framework.Version;
import org.osgi.service.packageadmin.RequiredBundle;

public class BundleLoaderProxy
  implements RequiredBundle, BundleReference
{
  static SecureAction secureAction = (SecureAction)AccessController.doPrivileged(SecureAction.createSecureAction());
  private BundleLoader loader;
  private final BundleHost bundle;
  private final BundleDescription description;
  private final BundleData data;
  private boolean stale = false;
  private final KeyedHashSet pkgSources;
  
  public BundleLoaderProxy(BundleHost bundle, BundleDescription description)
  {
    this.bundle = bundle;
    this.description = description;
    pkgSources = new KeyedHashSet(false);
    data = bundle.getBundleData();
  }
  
  public BundleLoader getBundleLoader()
  {
    if (System.getSecurityManager() == null) {
      return getBundleLoader0();
    }
    (BundleLoader)AccessController.doPrivileged(new PrivilegedAction()
    {
      public BundleLoader run()
      {
        return getBundleLoader0();
      }
    });
  }
  
  synchronized BundleLoader getBundleLoader0()
  {
    if (loader != null) {
      return loader;
    }
    if (bundle.isResolved()) {
      try
      {
        if (bundle.getBundleId() == 0L) {
          loader = new SystemBundleLoader(bundle, this);
        } else {
          loader = new BundleLoader(bundle, this);
        }
      }
      catch (BundleException e)
      {
        bundle.getFramework().publishFrameworkEvent(2, bundle, e);
        return null;
      }
    }
    return loader;
  }
  
  public BundleLoader getBasicBundleLoader()
  {
    return loader;
  }
  
  public AbstractBundle getBundleHost()
  {
    return bundle;
  }
  
  void setStale()
  {
    stale = true;
  }
  
  public boolean isStale()
  {
    return stale;
  }
  
  public String toString()
  {
    String symbolicName = bundle.getSymbolicName();
    StringBuffer sb = new StringBuffer(symbolicName == null ? bundle.getBundleData().getLocation() : symbolicName);
    sb.append("; ").append("bundle-version");
    sb.append("=\"").append(description.getVersion().toString()).append("\"");
    return sb.toString();
  }
  
  public Bundle getBundle()
  {
    if (isStale()) {
      return null;
    }
    return bundle;
  }
  
  public BundleData getBundleData()
  {
    return data;
  }
  
  public Bundle[] getRequiringBundles()
  {
    if (isStale()) {
      return null;
    }
    BundleDescription[] dependents = description.getDependents();
    if ((dependents == null) || (dependents.length == 0)) {
      return new Bundle[0];
    }
    List<Bundle> result = new ArrayList(dependents.length);
    for (int i = 0; i < dependents.length; i++) {
      addRequirers(dependents[i], result);
    }
    return (Bundle[])result.toArray(new Bundle[result.size()]);
  }
  
  void addRequirers(BundleDescription dependent, List<Bundle> result)
  {
    if (dependent.getHost() != null) {
      return;
    }
    BundleLoaderProxy dependentProxy = getBundleLoader().getLoaderProxy(dependent);
    if (dependentProxy == null) {
      return;
    }
    if (result.contains(bundle)) {
      return;
    }
    BundleLoader dependentLoader = dependentProxy.getBundleLoader();
    BundleLoaderProxy[] requiredBundles = requiredBundles;
    int[] reexportTable = reexportTable;
    if (requiredBundles == null) {
      return;
    }
    int size = reexportTable == null ? 0 : reexportTable.length;
    int reexportIndex = 0;
    for (int i = 0; i < requiredBundles.length; i++) {
      if (requiredBundles[i] == this)
      {
        result.add(bundle);
        if ((reexportIndex < size) && (reexportTable[reexportIndex] == i))
        {
          reexportIndex++;
          BundleDescription[] dependents = dependent.getDependents();
          if (dependents == null) {
            return;
          }
          for (int j = 0; j < dependents.length; j++) {
            dependentProxy.addRequirers(dependents[j], result);
          }
        }
        return;
      }
    }
  }
  
  public String getSymbolicName()
  {
    return description.getSymbolicName();
  }
  
  public Version getVersion()
  {
    return description.getVersion();
  }
  
  public boolean isRemovalPending()
  {
    return description.isRemovalPending();
  }
  
  public BundleDescription getBundleDescription()
  {
    return description;
  }
  
  PackageSource getPackageSource(String pkgName)
  {
    PackageSource pkgSource = (PackageSource)pkgSources.getByKey(pkgName);
    if (pkgSource == null)
    {
      pkgSource = new SingleSourcePackage(pkgName, this);
      synchronized (pkgSources)
      {
        pkgSources.add(pkgSource);
      }
    }
    return pkgSource;
  }
  
  public boolean inUse()
  {
    return (description.getDependents().length > 0) || (((bundle instanceof CompositeBase)) && (description.getResolvedImports().length > 0));
  }
  
  boolean forceSourceCreation(ExportPackageDescription export)
  {
    boolean strict = "strict".equals(secureAction.getProperty("osgi.resolverMode"));
    return (export.getDirective("include") != null) || (export.getDirective("exclude") != null) || ((strict) && (export.getDirective("x-friends") != null));
  }
  
  public PackageSource createPackageSource(ExportPackageDescription export, boolean storeSource)
  {
    PackageSource pkgSource = null;
    
    String includes = (String)export.getDirective("include");
    String excludes = (String)export.getDirective("exclude");
    String[] friends = (String[])export.getDirective("x-friends");
    if (friends != null)
    {
      boolean strict = "strict".equals(secureAction.getProperty("osgi.resolverMode"));
      if (!strict) {
        friends = null;
      }
    }
    if ((includes != null) || (excludes != null) || (friends != null)) {
      pkgSource = new FilteredSourcePackage(export.getName(), this, includes, excludes, friends);
    }
    if (storeSource)
    {
      if ((pkgSource != null) && (pkgSources.getByKey(export.getName()) == null)) {
        synchronized (pkgSources)
        {
          pkgSources.add(pkgSource);
        }
      }
    }
    else if (pkgSource == null)
    {
      pkgSource = getPackageSource(export.getName());
      if (pkgSource.getClass() != SingleSourcePackage.class) {
        return new SingleSourcePackage(export.getName(), this);
      }
    }
    return pkgSource;
  }
}

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

import java.net.URL;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
import org.eclipse.osgi.util.ManifestElement;

public class FilteredSourcePackage
  extends SingleSourcePackage
{
  private static final char ALL = '*';
  String[] includes;
  String[] excludes;
  String[] friends;
  
  public FilteredSourcePackage(String name, BundleLoaderProxy supplier, String includes, String excludes, String[] friends)
  {
    super(name, supplier);
    if (includes != null) {
      this.includes = ManifestElement.getArrayFromList(includes);
    }
    if (excludes != null) {
      this.excludes = ManifestElement.getArrayFromList(excludes);
    }
    this.friends = friends;
  }
  
  public boolean isFriend(String symbolicName)
  {
    if (friends == null) {
      return true;
    }
    for (int i = 0; i < friends.length; i++) {
      if (friends[i].equals(symbolicName)) {
        return true;
      }
    }
    return false;
  }
  
  public URL getResource(String name)
  {
    if (isFiltered(name, getId())) {
      return null;
    }
    return super.getResource(name);
  }
  
  public Enumeration<URL> getResources(String name)
  {
    if (isFiltered(name, getId())) {
      return null;
    }
    return super.getResources(name);
  }
  
  public Class<?> loadClass(String name)
    throws ClassNotFoundException
  {
    if (isFiltered(name, getId())) {
      return null;
    }
    return super.loadClass(name);
  }
  
  private boolean isFiltered(String name, String pkgName)
  {
    String lastName = getName(name, pkgName);
    return (!isIncluded(lastName)) || (isExcluded(lastName));
  }
  
  private String getName(String name, String pkgName)
  {
    if ((!".".equals(pkgName)) && (pkgName.length() + 1 <= name.length())) {
      return name.substring(pkgName.length() + 1);
    }
    return name;
  }
  
  private boolean isIncluded(String name)
  {
    if (includes == null) {
      return true;
    }
    return isInList(name, includes);
  }
  
  private boolean isExcluded(String name)
  {
    if (excludes == null) {
      return false;
    }
    return isInList(name, excludes);
  }
  
  private boolean isInList(String name, String[] list)
  {
    for (int i = 0; i < list.length; i++)
    {
      int len = list[i].length();
      if (len != 0)
      {
        if ((list[i].charAt(0) == '*') && (len == 1)) {
          return true;
        }
        if ((list[i].charAt(len - 1) == '*') && 
          (name.startsWith(list[i].substring(0, len - 1)))) {
          return true;
        }
        if (name.equals(list[i])) {
          return true;
        }
      }
    }
    return false;
  }
  
  public Collection<String> listResources(String path, String filePattern)
  {
    Collection<String> result = super.listResources(path, filePattern);
    for (Iterator<String> resources = result.iterator(); resources.hasNext();)
    {
      String resource = (String)resources.next();
      int lastSlash = resource.lastIndexOf('/');
      String file
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