Search in sources :

Example 11 with BundleLoader

use of org.eclipse.osgi.internal.loader.BundleLoader in project rt.equinox.framework by eclipse.

the class PackageSource method isServiceAssignableTo.

/**
 * Used by ServiceReferenceImpl for isAssignableTo
 * @param registrant Bundle registering service
 * @param client Bundle desiring to use service
 * @param className class name to use
 * @param serviceClass class of original service object
 * @param container the equinox container
 * @return true if assignable given package wiring
 */
public static boolean isServiceAssignableTo(Bundle registrant, Bundle client, String className, Class<?> serviceClass, EquinoxContainer container) {
    // 1) if the registrant == client always return true
    if (registrant == client) {
        return true;
    }
    // 2) get the package name from the specified className
    String pkgName = BundleLoader.getPackageName(className);
    if (// $NON-NLS-1$
    pkgName.startsWith("java."))
        return true;
    BundleLoader producerBL = getBundleLoader(registrant);
    if (producerBL == null)
        return false;
    BundleLoader consumerBL = getBundleLoader(client);
    if (consumerBL == null)
        return false;
    // 3) for the specified bundle, find the wiring for the package.  If no wiring is found return true
    PackageSource consumerSource = consumerBL.getPackageSource(pkgName);
    if (consumerSource == null)
        return true;
    // work around the issue when the package is in the EE and we delegate to boot for that package
    if (container.isBootDelegationPackage(pkgName)) {
        Bundle systemBundle = container.getStorage().getModuleContainer().getModule(0).getBundle();
        SystemBundleLoader systemLoader = (SystemBundleLoader) getBundleLoader(systemBundle);
        if (systemLoader.isExportedPackage(pkgName)) {
            // in this case we have a common source from the EE
            return true;
        }
    }
    // 4) For the registrant bundle, find the wiring for the package.
    PackageSource producerSource = producerBL.getPackageSource(pkgName);
    if (producerSource == null) {
        if (serviceClass != null && ServiceFactory.class.isAssignableFrom(serviceClass)) {
            @SuppressWarnings("deprecation") Bundle bundle = container.getPackageAdmin().getBundle(serviceClass);
            if (bundle != null && bundle != registrant)
                // bug 326918
                return true;
        }
        // 5) If no wiring is found for the registrant bundle then find the wiring for the classloader of the service object.  If no wiring is found return false.
        producerSource = getPackageSource(serviceClass, pkgName, container.getPackageAdmin());
        if (producerSource == null)
            return false;
    }
    // 6) If the two wirings found are equal then return true; otherwise return false.
    return producerSource.hasCommonSource(consumerSource);
}
Also used : ServiceFactory(org.osgi.framework.ServiceFactory) EquinoxBundle(org.eclipse.osgi.internal.framework.EquinoxBundle) Bundle(org.osgi.framework.Bundle) SystemBundleLoader(org.eclipse.osgi.internal.loader.SystemBundleLoader) SystemBundleLoader(org.eclipse.osgi.internal.loader.SystemBundleLoader) BundleLoader(org.eclipse.osgi.internal.loader.BundleLoader)

Example 12 with BundleLoader

use of org.eclipse.osgi.internal.loader.BundleLoader in project rt.equinox.framework by eclipse.

the class DependentPolicy method loadResources.

public Enumeration<URL> loadResources(String name) {
    if (allDependents == null)
        return null;
    Enumeration<URL> results = null;
    // size may change, so we must check it every time
    for (int i = 0; i < allDependents.size(); i++) {
        ModuleWiring searchWiring = allDependents.get(i);
        BundleLoader searchLoader = (BundleLoader) searchWiring.getModuleLoader();
        if (searchLoader != null) {
            try {
                results = BundleLoader.compoundEnumerations(results, searchLoader.findResources(name));
                addDependent(i, searchWiring);
            } catch (IOException e) {
            // Ignore and keep looking
            }
        }
    }
    return results;
}
Also used : ModuleWiring(org.eclipse.osgi.container.ModuleWiring) IOException(java.io.IOException) URL(java.net.URL) BundleLoader(org.eclipse.osgi.internal.loader.BundleLoader)

Aggregations

BundleLoader (org.eclipse.osgi.internal.loader.BundleLoader)12 ModuleWiring (org.eclipse.osgi.container.ModuleWiring)8 URL (java.net.URL)4 SystemBundleLoader (org.eclipse.osgi.internal.loader.SystemBundleLoader)3 IOException (java.io.IOException)2 EquinoxBundle (org.eclipse.osgi.internal.framework.EquinoxBundle)2 ModuleClassLoader (org.eclipse.osgi.internal.loader.ModuleClassLoader)2 Bundle (org.osgi.framework.Bundle)2 ProtectionDomain (java.security.ProtectionDomain)1 Module (org.eclipse.osgi.container.Module)1 ModuleLoader (org.eclipse.osgi.container.ModuleLoader)1 ModuleRevision (org.eclipse.osgi.container.ModuleRevision)1 SystemModule (org.eclipse.osgi.container.SystemModule)1 BundlePermissions (org.eclipse.osgi.internal.permadmin.BundlePermissions)1 ServiceRegistry (org.eclipse.osgi.internal.serviceregistry.ServiceRegistry)1 ResolutionReport (org.eclipse.osgi.report.resolution.ResolutionReport)1 Generation (org.eclipse.osgi.storage.BundleInfo.Generation)1 BundleException (org.osgi.framework.BundleException)1 ServiceFactory (org.osgi.framework.ServiceFactory)1 Capability (org.osgi.resource.Capability)1