protected boolean canSee()

in core/camel-core-osgi/src/main/java/org/apache/camel/karaf/core/Activator.java [299:325]


    protected boolean canSee(Bundle bundle, Class<?> clazz) {
        if (bundle.getBundleId() == bundleId) {
            // Need extra handling of camel core as it does not import the api
            return true;
        }
        BundleCapability packageCap = packageCapabilities.get(clazz.getPackage().getName());
        if (packageCap != null) {
            BundleWiring wiring = bundle.adapt(BundleWiring.class);
            List<BundleWire> imports = wiring.getRequiredWires(PACKAGE_NAMESPACE);
            for (BundleWire importWire : imports) {
                if (packageCap.equals(importWire.getCapability())) {
                    return true;
                }
            }
        }

        // it may be running outside real OSGi container such as when unit testing with camel-test-blueprint
        // then we need to use a different canSee algorithm that works outside real OSGi
        if (bundle.getBundleId() >= 0) {
            Bundle root = bundle.getBundleContext().getBundle(0);
            if (root != null && "org.apache.felix.connect".equals(root.getSymbolicName())) {
                return checkCompat(bundle, clazz);
            }
        }

        return false;
    }