Search in sources :

Example 1 with CompoundEnumeration

use of org.apache.felix.framework.util.CompoundEnumeration in project felix by apache.

the class BundleWiringImpl method findResourcesByDelegation.

private Enumeration findResourcesByDelegation(String name) {
    Enumeration urls = null;
    List completeUrlList = new ArrayList();
    // Get the package of the target class/resource.
    String pkgName = Util.getResourcePackage(name);
    // property to the parent class loader.
    if (shouldBootDelegate(pkgName)) {
        try {
            // Get the appropriate class loader for delegation.
            ClassLoader bdcl = getBootDelegationClassLoader();
            urls = bdcl.getResources(name);
        } catch (IOException ex) {
        // This shouldn't happen and even if it does, there
        // is nothing we can do, so just ignore it.
        }
        // search; otherwise, continue to look locally.
        if (pkgName.startsWith("java.")) {
            return urls;
        }
        completeUrlList.add(urls);
    }
    // Look in the revisions's imported packages. If the package is
    // imported, then we stop searching no matter the result since
    // imported packages cannot be split.
    BundleRevision provider = m_importedPkgs.get(pkgName);
    if (provider != null) {
        // Delegate to the provider revision.
        urls = ((BundleWiringImpl) provider.getWiring()).getResourcesByDelegation(name);
        // If we find any resources, then add them.
        if ((urls != null) && (urls.hasMoreElements())) {
            completeUrlList.add(urls);
        }
        // across required bundles or the revision's content.
        return new CompoundEnumeration((Enumeration[]) completeUrlList.toArray(new Enumeration[completeUrlList.size()]));
    }
    // See whether we can get the resource from the required bundles and
    // regardless of whether or not this is the case continue to the next
    // step potentially passing on the result of this search (if any).
    List<BundleRevision> providers = m_requiredPkgs.get(pkgName);
    if (providers != null) {
        for (BundleRevision p : providers) {
            // Delegate to the provider revision.
            urls = ((BundleWiringImpl) p.getWiring()).getResourcesByDelegation(name);
            // If we find any resources, then add them.
            if ((urls != null) && (urls.hasMoreElements())) {
                completeUrlList.add(urls);
            }
        // Do not return here, since required packages can be split
        // across the revision's content.
        }
    }
    // Try the module's own class path. If we can find the resource then
    // return it together with the results from the other searches else
    // try to look into the dynamic imports.
    urls = m_revision.getResourcesLocal(name);
    if ((urls != null) && (urls.hasMoreElements())) {
        completeUrlList.add(urls);
    } else {
        // class/resource via a dynamic import, if possible.
        try {
            provider = m_resolver.resolve(m_revision, pkgName);
        } catch (ResolutionException ex) {
        // Ignore this since it is likely normal.
        } catch (BundleException ex) {
        // Ignore this since it is likely the result of a resolver hook.
        }
        if (provider != null) {
            // Delegate to the provider revision.
            urls = ((BundleWiringImpl) provider.getWiring()).getResourcesByDelegation(name);
            // If we find any resources, then add them.
            if ((urls != null) && (urls.hasMoreElements())) {
                completeUrlList.add(urls);
            }
        }
    }
    return new CompoundEnumeration((Enumeration[]) completeUrlList.toArray(new Enumeration[completeUrlList.size()]));
}
Also used : ResolutionException(org.osgi.service.resolver.ResolutionException) Enumeration(java.util.Enumeration) CompoundEnumeration(org.apache.felix.framework.util.CompoundEnumeration) ArrayList(java.util.ArrayList) BundleRevision(org.osgi.framework.wiring.BundleRevision) SecureClassLoader(java.security.SecureClassLoader) List(java.util.List) ImmutableList(org.apache.felix.framework.util.ImmutableList) ArrayList(java.util.ArrayList) IOException(java.io.IOException) BundleException(org.osgi.framework.BundleException) CompoundEnumeration(org.apache.felix.framework.util.CompoundEnumeration)

Aggregations

IOException (java.io.IOException)1 SecureClassLoader (java.security.SecureClassLoader)1 ArrayList (java.util.ArrayList)1 Enumeration (java.util.Enumeration)1 List (java.util.List)1 CompoundEnumeration (org.apache.felix.framework.util.CompoundEnumeration)1 ImmutableList (org.apache.felix.framework.util.ImmutableList)1 BundleException (org.osgi.framework.BundleException)1 BundleRevision (org.osgi.framework.wiring.BundleRevision)1 ResolutionException (org.osgi.service.resolver.ResolutionException)1